1. Go to this page and download the library: Download walnut/lib_dborm 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/ */
walnut / lib_dborm example snippets
#[ModelRoot('users')]
class UserDomainModel {
public function __construct(
#[Table("org_users")]
#[KeyField('id'), Fields('first_name', 'org_id')]
#[ListOf(fieldName: 'credentials', targetName: 'userCredentials')]
#[ListOf(fieldName: 'roles', targetName: 'roles')]
#[ListOf(fieldName: 'tags', targetName: 'tags')]
public array $users,
#[Table('org_user_roles'), KeyField('id'), ParentField('user_id'), Fields('role_id'), GroupField('code')]
public array $roles,
#[Table('org_user_credentials')]
#[KeyField('id'), ParentField('user_id'), Fields('username', 'password')]
public array $userCredentials,
#[Table("org_user_tags"), KeyField('id'), ParentField('user_id'), Fields('tag_id')]
public array $tags
) {}
}
$queryExecutor = new PdoQueryExecutor($connector);
$factory = new DataModelFactory(new SqliteQuoter, $queryExecutor);
$model = (new DataModelBuilder)->build(UserQueryModel::class);
$dataModelFetcher = $factory->getFetcher($model);
$data = $dataModelFetcher->fetchData(new QueryFilter(
new FieldExpression('id', '<', new SqlValue(2))
)); //contains the full object as defined in the model above