Typed callbacks work through FieldSet classes. Surqlize infers a model's fields at runtime, and can also generate explicit field adapter classes for better IDE completion and stricter static analysis.
Field adapters
A generated field adapter is a FieldSet subclass that declares each property as a typed field. It makes the closures in select(), where(), and the other builder methods fully analysable.
use App\Models\User;
use Surqlize\Query\Fields\FieldSet;
use Surqlize\Query\Fields\NumericField;
use Surqlize\Query\Fields\RecordIdField;
use Surqlize\Query\Fields\RecordLinkField;
use Surqlize\Query\Fields\StringField;
final class UserFields extends FieldSet
{
public readonly RecordIdField $id;
public readonly StringField $name;
public readonly NumericField $age;
public readonly RecordLinkField $address;
public function __construct()
{
parent::__construct(User::class);
$this->id = new RecordIdField('id', table: 'user');
$this->name = new StringField('name');
$this->age = new NumericField('age');
$this->address = new RecordLinkField('address');
}
}You write these by hand only if you want to. The generator produces them for you.
Configuration
The CLI reads a config file, by convention surqlize.config.php, that returns an array. For field generation it lists the models and where to write the adapters.
use App\Models\Address;
use App\Models\HasAddress;
use App\Models\User;
return [
'models' => [
User::class,
Address::class,
HasAddress::class,
],
'fields_namespace' => 'App\\Models\\Fields',
'fields_path' => __DIR__ . '/src/Models/Fields',
];For schema:apply, the config provides the models plus an SDK executor.
return [
'models' => [User::class, Address::class],
'executor' => $surreal,
];CLI commands
Surqlize ships a Composer binary named surqlize.
vendor/bin/surqlize generate:fields [config-path]
vendor/bin/surqlize schema:apply [config-path]
vendor/bin/surqlize memory:footprint [--iterations=1000] [--output=path]In a source checkout without Composer's bin proxy, run the binary directly with php bin/surqlize ....
generate:fields
Generates the *Fields classes and *FieldTyping traits for the configured models, into the configured namespace and path.
vendor/bin/surqlize generate:fields surqlize.config.phpschema:apply
Applies the schema definitions for the configured models through the configured executor.
vendor/bin/surqlize schema:apply surqlize.config.phpmemory:footprint
Generates a JSON memory report across the built-in scenarios (metadata reflection, field-set resolution, query compilation, hydration, graph traversal, and more), with retained, peak, and real memory deltas and durations.
vendor/bin/surqlize memory:footprint --iterations=5000 --output=memory-report.jsonLearn more
Querying for the typed callbacks adapters support
Schema for the definitions
schema:applyrunsLaravel integration for the Artisan schema commands