PHPackages                             walnut/lib\_dborm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. walnut/lib\_dborm

ActiveLibrary[Database &amp; ORM](/categories/database)

walnut/lib\_dborm
=================

0.0.7(2y ago)074PHP

Since Sep 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/kapitancho/walnut-lib-dborm)[ Packagist](https://packagist.org/packages/walnut/lib_dborm)[ RSS](/packages/walnut-lib-dborm/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (7)Dependencies (6)Versions (8)Used By (0)

Lightweight ORM
===============

[](#lightweight-orm)

Examples
--------

[](#examples)

### User Domain Model

[](#user-domain-model)

```
#[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
    ) {}
}
```

### User Query Model

[](#user-query-model)

```
#[ModelRoot('users')]
class UserQueryModel {
    public function __construct(
        #[Table("org_users")]
        #[KeyField('id'), Fields('first_name', 'org_id')]
        #[OneOf(fieldName: 'org', targetName: 'orgs', sourceField: 'org_id')]
        #[ListOf(fieldName: 'credentials', targetName: 'userCredentials')]
        #[ListOf(fieldName: 'roles', targetName: 'roles')]
        #[ListOf(fieldName: 'tags', targetName: 'tags')]
        public array $users,

            #[CrossTable('org_user_roles', parentField: 'user_id', sourceField: 'role_id', targetField: 'id')]
            #[Table('org_roles'), KeyField('id'), Fields('name', 'code'), GroupField('code')]
            public array $roles,

            #[Table('orgs')]
            #[KeyField('id'), Fields('name'), ParentField('id')]
            public array $orgs,

            #[Table('org_user_credentials')]
            #[KeyField('id'), ParentField('user_id'), Fields('username', 'password')]
            public array $userCredentials,

            #[CrossTable('org_user_tags', parentField: 'user_id', sourceField: 'tag_id', targetField: 'id')]
            #[Table("org_tag_user_group_values"), KeyField('id'), Fields('value', 'group_id'), GroupField('id')]
            #[OneOf(fieldName: 'group', targetName: 'tagGroups', sourceField: 'group_id')]
            public array $tags,

                #[Table("org_tag_user_groups"), KeyField('id'), Fields('name'), ParentField('id')]
                public array $tagGroups
    ) {}
}
```

Working with data
-----------------

[](#working-with-data)

### Preparation steps

[](#preparation-steps)

```
$queryExecutor = new PdoQueryExecutor($connector);
$factory = new DataModelFactory(new SqliteQuoter, $queryExecutor);
```

### Fetching data

[](#fetching-data)

```
$model = (new DataModelBuilder)->build(UserQueryModel::class);
$dataModelFetcher = $factory->getFetcher($model);
$data = $dataModelFetcher->fetchData(new QueryFilter(
    new FieldExpression('id', '
