1. Go to this page and download the library: Download diogodg/neoorm library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
diogodg / neoorm example snippets
use Diogodg\Neoorm\Query\Database;
use App\Models\Generated\Tables;
use function Diogodg\Neoorm\Query\{eq, gt, desc};
$db = Database::fromConfig();
$u = Tables::users();
$maiores = $db->select()->from($u)
->where(gt($u->age, 18))
->orderBy(desc($u->created_at))
->limit(10)
->all(); // list<UsersRow> — tipado de verdade
namespace App\Models;
use App\Models\Generated\StateTable;
use Diogodg\Neoorm\Abstract\Model;
use Diogodg\Neoorm\Migrations\Col;
use Diogodg\Neoorm\Migrations\Table;
/**
* @extends Model<StateTable>
*/
class State extends Model
{
public const table = 'state';
public static function table(): Table
{
return Table::make(self::table, comment: 'States table')
->columns([
'id' => Col::id(),
'name' => Col::varchar(120)->notNull(),
'abbreviation' => Col::char(2)->notNull(),
'country' => Col::int()->notNull()->references(Country::class),
'ibge' => Col::int()->unique(),
]);
}
}
$dinheiro = Col::decimal(19, 4)->notNull()->default(0);
'saldo' => $dinheiro,
'limite' => $dinheiro->comment('Limite de crédito'), // não mexe em $dinheiro
namespace App\Seeders;
use App\Models\Generated\Inserts\StateInsert;
use App\Models\Generated\Tables;
use App\Models\State;
use Diogodg\Neoorm\Migrations\Seed\Seeder;
use Diogodg\Neoorm\Query\Executor;
final class StateSeeder extends Seeder
{
public static function table(): string
{
return State::table;
}
public function run(Executor $db): void
{
if ($db->select()->from(Tables::state())->count() > 0) {
return;
}
$db->insert(Tables::state())
->values(new StateInsert(name: 'Acre', abbreviation: 'AC', country: 1, ibge: 12))
->execute();
}
}
$s = State::ref(); // StateTable, colunas tipadas
$db->select()->from($s)->where(eq($s->ibge, 12))->one();
$vizinho = State::ref('vizinho'); // com alias, para self-join
$db = Database::fromConfig();
$u = Tables::users();
$db->select()->from($u)->all(); // list<UsersRow>
$db->select()->from($u)->where(eq($u->id, 1))->one(); // ?UsersRow
$db->select()->from($u)->where(eq($u->id, 1))->oneOrFail();// UsersRow, ou lança
$db->select()->from($u)->count(); // int
$db->select()->from($u)->cursor(); // Generator<UsersRow>, sem materializar
App/Models/Generated/
Tables.php Tables::users(), Tables::scheduleUser(), ...
UsersTable.php $u->email — propriedade declarada, com tipo
Rows/UsersRow.php final readonly, com fromRow() e toArray()
Inserts/UsersInsert.php construtor de argumentos nomeados
Enums/UsersStatus.php enum PHP para coluna ENUM