PHPackages                             madesimple/database - 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. madesimple/database

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

madesimple/database
===================

Database entities and query builder

v0.0.1(9y ago)2157MITPHPPHP &gt;=5.6

Since Mar 3Pushed 5y ago1 watchersCompare

[ Source](https://github.com/pdscopes/database)[ Packagist](https://packagist.org/packages/madesimple/database)[ RSS](/packages/madesimple-database/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (5)Versions (3)Used By (0)

MadeSimple - Database
=====================

[](#madesimple---database)

[![Build Status](https://camo.githubusercontent.com/8eef863b2c689933f2ef54663c76727093eaf74bf7554f4e1f423d91c154e914/68747470733a2f2f7472617669732d63692e6f72672f706473636f7065732f64617461626173652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pdscopes/database)

The database package is a abstraction layer between PHP and an SQL database. The main features of the package are:

1. [Migration control](#migration-control)
2. [Database Seeding](#database-seeding)
3. [Query building](#query-building)
4. [Entities and Relationships](#entities-and-relationships)

Migration Control
-----------------

[](#migration-control)

You can control migrations of your database through an easy to use, reliable command line. Possible actions are to install the migrations table, upgrade, rollback, uninstall, and refresh. These are all called through `bin/database`.

For example, on first clone of a package using database:

```
> composer install
...
> vendor/bin/database database:install -e -v
[notice] Migration table created
> vendor/bin/database database:upgrade -ep examples/migrations -v
[notice] Migrated file: "/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php"
[notice] Migrated file: "/path/to/database/examples/migrations/v1.0.1-ExampleComment.php"
```

or you can use the shortcut:

```
> composer install
...
> vendor/bin/database database:migrate -e -p examples/migrations -v
[notice] Migration table created
[notice] Migrated file: "/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php"
[notice] Migrated file: "/path/to/database/examples/migrations/v1.0.1-ExampleComment.php"
```

For example, on rollback a migration:

```
> vendor/bin/database database:rollback -e -v
Rolling back batch: 1
[notice] Rolled back file: "/path/to/database/examples/migrations/v1.0.1-ExampleComment.php"
[notice] Rolled back file: "/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php"
```

For example, on uninstalling:

```
> vendor/bin/database database:uninstall -e -v
[notice] Migration table removed
```

For example, on refreshing:

```
> vendor/bin/database database:refresh -e -p examples/migrations/ -s examples/seeds/ -v
[notice] Migration table already installed
[notice] Rolled back file: "/path/to/database/examples/migrations/v1.0.1-ExampleComment.php"
[notice] Rolled back file: "/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php"
[notice] Migrated file: "/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php"
[notice] Migrated file: "/path/to/database/examples/migrations/v1.0.1-ExampleComment.php"
[notice] Seeded file: "/path/to/database/examples/seeds/v1.0.0-ExampleTableSeeder.php"
```

Database Seeding
----------------

[](#database-seeding)

You can create seeds for the database that should be used to populate the database with dummy data. This can be called through `bin/database`.

For example, on seeding that database:

```
> vendor/bin/database database:seed -e -v -s examples/seeds
[notice] Seeded file: "/path/to/database/examples/seeds/v1.0.0-ExampleTableSeeder.php"
```

Query Building
--------------

[](#query-building)

### Select

[](#select)

```
$connection
    ->select()
    ->from('table')
    ->where('column', '=', 'value');
// SELECT * FROM `table` WHERE `columns` = ?

```

### Update

[](#update)

```
$connection
    ->update()
    ->table('table')
    ->set('column', 'new-value')
    ->where('another-column', '=', 'value');
// UPDATE `table` SET `column`=? WHERE `another-column` = ?

```

### Insert

[](#insert)

```
$connection
    ->insert()
    ->into('table')
    ->columns('column1', 'column2')
    ->values(5, 'value');
// INSERT INTO `table` (`column1`,`column2`) VALUES (?,?)

$rows = [
    ['column1_value1', 'column2_value1'],
    ['column1_value2', 'column2_value2'],
    ['column1_value3', 'column2_value3'],
];
$connection
    ->insert()
    ->into('table')
    ->columns('column1', 'column2')
    ->chunkedQuery($rows, 2);
// INSERT INTO `table` (`column1`,`column2`) VALUES (?,?),(?,?)
// INSERT INTO `table` (`column1`,`column2`) VALUES (?,?)
```

### Delete

[](#delete)

```
$connection
    ->delete()
    ->from('table')
    ->where('column', '=', 'value');
// DELETE FROM `table` WHERE `column` = ?

```

### Statements

[](#statements)

```
$connection->statement(function (CreateTable $create) {
    $create->table('user')->ifNotExists();
    $create->column('id')->integer(10)->primaryKey()->autoIncrement();
    $create->column('uuid')->char(36)->unique()->notNull();
    $create->column('email')->char(255)->unique()->notNull();
    $create->column('password')->char(255)->notNull();
    $create->column('created_at')->timestamp()->notNull()->useCurrent();
    $create->column('updated_at')->timestamp()->notNull()->useCurrent();
    $create
        ->engine('InnoDB')
        ->charset('utf8mb4', 'utf8mb4_general_ci');
});
// CREATE TABLE IF NOT EXISTS `user` (
//   `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
//   `uuid` CHAR(36) NOT NULL UNIQUE,
//   `email` CHAR(255) NOT NULL UNIQUE,
//   `password` CHAR(255) NOT NULL,
//   `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
//   `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
// ) ENGINE=InnoDB,DEFAULT CHARACTER SET=utf8mb4,COLLATE=utf8mb4_general_ci
```

Entities and Relationships
--------------------------

[](#entities-and-relationships)

```
class User extends \MadeSimple\Database\Entity
{
    use \MadeSimple\Database\Entity\Relational;

    protected static function getMap()
    {
        return new \MadeSimple\Database\EntityMap(
            'user', // Table name
            ['id'], // Primary key(s)
            [       // Other columns: database name => property name
                'uuid',
                'email',
                'password',
                'created_at' => 'createdAt',
                'updated_at' => 'updatedAt',
            ]
        );
    }

    /**
     * @return \MadeSimple\Database\Relationship\ToMany
     */
    public function posts()
    {
        return $this->toMany()->has(Post::class, 'p', 'user_id');
    }
}
class Post extends \MadeSimple\Database\Entity
{
    use \MadeSimple\Database\Entity\Relational;

    protected static function getMap()
    {
        return new \MadeSimple\Database\EntityMap(
            'post', // Table name
            ['id'], // Primary key(s)
            [       // Other columns: database name => property name
                'uuid',
                'user_id' => 'userId',
                'title',
                'content',
                'created_at' => 'createdAt',
                'updated_at' => 'updatedAt',
            ]
        );
    }

    /**
     * @return \MadeSimple\Database\Relationship\ToOne
     */
    public function user()
    {
        return $this->toOne()->belongsTo(User::class, 'u', 'user_id');
    }
}
```

Supported Databases
-------------------

[](#supported-databases)

SQL databases currently supported are:

- MySQL
- SQLite

External Documentation
======================

[](#external-documentation)

Links to documentation for external dependencies:

- [PHP Docs](http://php.net/)
- [Logging PSR-3](http://www.php-fig.org/psr/psr-3/)

Links to documentation for development only external dependencies:

- [monolog/monolog](https://github.com/Seldaek/monolog)
- [symfony/console](http://symfony.com/doc/current/components/console.html)
- [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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 ~20 days

Total

2

Last Release

3339d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13329586?v=4)[Pete Scopes](/maintainers/pdscopes)[@pdscopes](https://github.com/pdscopes)

---

Top Contributors

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

---

Tags

databaseentitiesmigrationphpquery-builder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/madesimple-database/health.svg)

```
[![Health](https://phpackages.com/badges/madesimple-database/health.svg)](https://phpackages.com/packages/madesimple-database)
```

###  Alternatives

[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M191](/packages/spatie-laravel-backup)[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2592.8M263](/packages/ssch-typo3-rector)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

134391.5k12](/packages/rector-rector-src)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[guikingone/scheduler-bundle

A Symfony bundle that allows to schedule and create repetitive tasks

114217.4k](/packages/guikingone-scheduler-bundle)

PHPackages © 2026

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