PHPackages                             walnut/lib\_dbdatamodel - 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. walnut/lib\_dbdatamodel

ActiveLibrary

walnut/lib\_dbdatamodel
=======================

0.0.3(2y ago)0751PHP

Since Sep 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/kapitancho/walnut-lib-dbdatamodel)[ Packagist](https://packagist.org/packages/walnut/lib_dbdatamodel)[ RSS](/packages/walnut-lib-dbdatamodel/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (1)

Database Data Model
===================

[](#database-data-model)

An elegant way to define relational models.

Examples
--------

[](#examples)

### Client Domain Model

[](#client-domain-model)

```
#[ModelRoot('clients')]
final class ClientDomainModel {
    public function __construct(
        #[Table("clients")]
        #[KeyField('id'), Fields('name')]
        #[OneOf(fieldName: 'address', targetName: 'addresses', sourceField: 'address_id')]
        #[OneOf(fieldName: 'account', targetName: 'accounts')]
        #[ListOf(fieldName: 'contacts', targetName: 'contacts')]
        public array $clients,

            #[Table('addresses')]
            #[KeyField('id'), ParentField('id'), Fields('city', 'street')]
            public array $addresses,

            #[Table('client_accounts')]
            #[KeyField('id'), ParentField('client_id'), Fields('account_name')]
            public array $accounts,

            #[Table("client_contacts")]
            #[KeyField('id'), ParentField('client_id'), Fields('contact_name', 'position'), SortField('sequence')]
            #[ListOf(fieldName: 'phones', targetName: 'phones')]
            public array $contacts,

            #[Table("client_contact_phones")]
            #[KeyField('id'), ParentField('contact_id'), Fields('phone_number')]
            public array $phones
    ) {}
}
```

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

### Tag User Groups Query Model

[](#tag-user-groups-query-model)

```
#[ModelRoot('tagUserGroups')]
class TagUserGroupQueryModel {
    public function __construct(
        #[Table("org_tag_user_groups"), KeyField('id'), Fields('name')]
        #[ListOf(fieldName: 'values', targetName: 'tagUserGroupValues')]
        public array $tagUserGroups,

            #[Table("org_tag_user_group_values"), KeyField('id'),
                ParentField('group_id'), Fields('value'),
                SortField('sequence'), GroupField('id')]
            public array $tagUserGroupValues

    ) {}
}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~430 days

Total

3

Last Release

847d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/12d2910601119ce65c373b7e21ffc647154bde10c5ad0a0598ab1143aa851701?d=identicon)[kapitancho](/maintainers/kapitancho)

---

Top Contributors

[![kapitancho](https://avatars.githubusercontent.com/u/792682?v=4)](https://github.com/kapitancho "kapitancho (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/walnut-lib-dbdatamodel/health.svg)

```
[![Health](https://phpackages.com/badges/walnut-lib-dbdatamodel/health.svg)](https://phpackages.com/packages/walnut-lib-dbdatamodel)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
