PHPackages                             alexanderduring/ember-db - 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. alexanderduring/ember-db

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

alexanderduring/ember-db
========================

An embeddable document based database for php.

481[3 issues](https://github.com/alexanderduring/php-ember-db/issues)PHP

Since Mar 21Pushed 7y ago1 watchersCompare

[ Source](https://github.com/alexanderduring/php-ember-db)[ Packagist](https://packagist.org/packages/alexanderduring/ember-db)[ RSS](/packages/alexanderduring-ember-db/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![License](https://camo.githubusercontent.com/8e9b0a2b1f30db5c3f4ff5549ed967739f47da426fa4d48ecf69efe24970ca92/68747470733a2f2f706f7365722e707567782e6f72672f616c6578616e646572647572696e672f656d6265722d64622f6c6963656e7365)](https://packagist.org/packages/alexanderduring/ember-db)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2aecb15dd5a74cd43adf87b294f39e94fddee9e56972ddd29e5905d6bf69461a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c6578616e646572647572696e672f7068702d656d6265722d64622f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alexanderduring/php-ember-db/?branch=master)[![Build Status](https://camo.githubusercontent.com/feb9296aebcf26648c2fb126dfaa55fe3502cadafd3554fde82b7ecea160e40d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c6578616e646572647572696e672f7068702d656d6265722d64622f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alexanderduring/php-ember-db/build-status/master)[![Total Downloads](https://camo.githubusercontent.com/ee3bf25ed206bc697f88fcbd267d5daa8e6f283080f415f12c90eaa86e37d931/68747470733a2f2f706f7365722e707567782e6f72672f616c6578616e646572647572696e672f656d6265722d64622f646f776e6c6f616473)](https://packagist.org/packages/alexanderduring/ember-db)[![Latest Stable Version](https://camo.githubusercontent.com/cde43192e63a5c1f9113514d6320d90f39f4d314b2e0b131b5889841dcbeda1a/68747470733a2f2f706f7365722e707567782e6f72672f616c6578616e646572647572696e672f656d6265722d64622f762f737461626c65)](https://packagist.org/packages/alexanderduring/ember-db)[![Latest Unstable Version](https://camo.githubusercontent.com/6cb4dc8096f1cb55acd9c18aab9b55e25db286e5f339c0476538def8228926e6/68747470733a2f2f706f7365722e707567782e6f72672f616c6578616e646572647572696e672f656d6265722d64622f762f756e737461626c65)](https://packagist.org/packages/alexanderduring/ember-db)

Ember DB
========

[](#ember-db)

EmberDb is planned to be a light, embeddable implementation of a document based database for php projects.

Overview
--------

[](#overview)

The project consists of two parts:

- the library that you need to embed in your application
- a command line client to directly access your database.

Usage
-----

[](#usage)

Via composer:

```
$ composer require alexanderduring/ember-db

```

Demo
----

[](#demo)

To try it out just clone the repository and in the project home type

```
$ php demo/index.php

```

You will see some example output of creating a collection, inserting documents und querying for documents. There is also a command line client which you can start with

```
$ bin/ember-db --directory=demo/data

```

Features
--------

[](#features)

### Setting up the database

[](#setting-up-the-database)

To set up the database, you need to tell the documentManager where he should store and search for database files (\*.edb).

```
$documentManager = new DocumentManager();
$documentManager->setDatabasePath(__DIR__.'/data');
```

### Create a collection

[](#create-a-collection)

To create a collection just insert a document into it.

### Remove a collection

[](#remove-a-collection)

To remove the entire 'cars' collection:

```
$documentManager->remove('cars');
```

### Insert documents

[](#insert-documents)

To insert a document into a collection:

```
// Set up database
$documentManager = new DocumentManager();
$documentManager->setDatabasePath(__DIR__.'/data');

$car = [
    'license-number' => 'HH-DS 1243',
    'manufacturer' => 'BMW',
    'model' => '325i'
];

// Add an entry to the collection
$documentManager->insert('cars', $car);
```

To insert multiple documents into a collection:

```
$cars = [
    ['manufacturer' => 'BMW', 'model' => '325i', 'color' => 'blue'],
    ['manufacturer' => 'VW', 'model' => 'Golf', 'color' => 'yellow'],
    ['manufacturer' => 'Fiat', 'model' => 'Punto', 'color' => 'blue']
];
$documentManager->insertMany('cars', $cars);
```

### Remove documents

[](#remove-documents)

-not implemented yet-

### Query documents

[](#query-documents)

To select all documents in the collection 'cars':

```
$documents = $documentManager->find('cars');
```

To select all cars, that have a blue color:

```
$filter = ['color' => 'blue'];
$documents = $documentManager->find('cars', $filter);
```

### Filters

[](#filters)

The implementation of filters in Ember Db is inspired by the query operators used in [BSON/MongoDB](https://docs.mongodb.com/).

These filter operators are currently available:

- $gt (greater than)
- $gte (greater than or equal)
- $lt (lower than)
- $lte (lower than or equal)
- $ne (not equal)
- $elementMatch (matches at least one element in an array)

#### Examples

[](#examples)

Query for all cars with more than 36 kw engine power:

```
$filter = ['engine' => [
    'powerInKw' => ['$gt' => 36]
]];
$documents = $documentManager->find('cars', $filter);
```

Query for all cars with a manufacturer other than Fiat:

```
$filter = ['manufacturer' => ['$ne' => 'Fiat']];
$documents = $documentManager->find('cars', $filter);
```

Implemetation Brainstorming
---------------------------

[](#implemetation-brainstorming)

There will probably be a "Manager" class as the unique access point to the database. A decision has to be made, if this class should return a document as an array or as an object.

### Arrays

[](#arrays)

#### Advantages

[](#advantages)

- An array has no methods, so there is no possibility to add business logic into the row object. There is a stronger need to implement such classes in the domain model layer.

### Objects

[](#objects)

#### Advantages

[](#advantages-1)

- The implementation of accessor methods provides hooks that could execute things on every set/get event.
- Because of the unstructured nature of documents some of them could have an entry "foo" and some may not. In order to check this, you would need to do several calls to array\_key\_exists to walk to the structure of the document. Having an document object providing helper methods to easily achieve this task is an advantage.

```
class document
{
    private $data;

    public __construct($jsonData = null)
    {
        $this->data = is_null($jsonData) ? array() : json_decode($jsonData, true);
    }

    public function has($path)
    {
        // Check if array key decribed by $path exists.
    }

    public function get($path)
    {
        // Return array value indexed by array key decribed by $path.
    }

    public function toJson()
    {
        return json_encode($this->data);
    }
}
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance5

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/69ff1766def9f9ba361fbb879b8d659149b6ac85d3ae610b5b43bbf188b21efc?d=identicon)[alexanderduring](/maintainers/alexanderduring)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/alexanderduring-ember-db/health.svg)

```
[![Health](https://phpackages.com/badges/alexanderduring-ember-db/health.svg)](https://phpackages.com/packages/alexanderduring-ember-db)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M543](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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