PHPackages                             jlaso/simple-memory-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. jlaso/simple-memory-db

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

jlaso/simple-memory-db
======================

A simple db in memory

1.5(9y ago)4111MITPHPPHP &gt;=5.4CI failing

Since Aug 27Pushed 8y ago2 watchersCompare

[ Source](https://github.com/jlaso/simple-memory-db)[ Packagist](https://packagist.org/packages/jlaso/simple-memory-db)[ Docs](https://github.com/jlaso/simple-memory-db)[ RSS](/packages/jlaso-simple-memory-db/feed)WikiDiscussions master Synced 4w ago

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

jlaso/simple-memory-db
======================

[](#jlasosimple-memory-db)

[![Build Status](https://camo.githubusercontent.com/3336573e9a451d37a41290ea4d2c5a1d6733b02ef3f288fc0354e72b1408eb97/68747470733a2f2f7472617669732d63692e6f72672f6a6c61736f2f73696d706c652d6d656d6f72792d64622e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jlaso/simple-memory-db)

### A simple db in memory, that has to be populated from JSON data.

[](#a-simple-db-in-memory-that-has-to-be-populated-from-json-data)

It lives entirely in memory, quick to access data and manipulate in order to process data at very high speed.

Installation
============

[](#installation)

You need only to require this package in your project

`composer require jlaso/simple-memory-db`

### Look at the Examples folders to see how to use it

[](#look-at-the-examples-folders-to-see-how-to-use-it)

#### Example

[](#example)

You have a very simple example with two tables: customers and taxes, each customer has a tax\_type associated.

In order to implement your data you have to create a class extending AbstractTable and declare the property $indexMap

by default `id` is automatically indexed. So, this field is mandatory in every table, must come in the json.

```
namespace JLaso\SimpleMemoryDb\Example;

use JLaso\SimpleMemoryDb\AbstractTable;

class CustomerTable extends AbstractTable
{
    protected $indexMap = [
        "tax_type_id",
    ];
}

```

#### BigExample

[](#bigexample)

You can just squeeze it in order to know how big is the limit of this database is in your system.

In order to populate the memory tables with real data, the json files can be generated parametrically:

`php BigExample/generate.php`

And to see the results

`php BigExample/demo.php`

### ProcessRecord

[](#processrecord)

If you need to add some extra fields or process the records somehow when they are loaded in memory you can implement the method `processRecord` in your table

```
class TaxTable extends AbstractTable
{
    protected $subtypes = [
        0 => 'mandatory',
        1 => 'optional',
        2 => 'regulated',
        3 => 'unknown',
    ];

    protected function processRecord(&$record)
    {
        $module = count($this->subtypes);
        $record['subtype'] = $this->subtypes[intval($record['value'] * 100) % $module];

        return true;  // or return false if you want to filter this record
    }
}

```

Modifier methods
================

[](#modifier-methods)

Although is not a real database you can insert new elements or remove the existent ones:

Insert
------

[](#insert)

- `insert($data)`

This insert the new record in memory and updates the indices to make it accessible. `$data` can be an array or an object that implements the `JLaso\SimpleMemoryDb\ToArrayInterface`

Update
------

[](#update)

This is an alias for insert, currently insert just replaces the existent copy of the record inserted if any.

Remove
------

[](#remove)

- `remove($id)`

This removes the record pointed by `$id` and updates the indices to make it not accessible.

Storing method
==============

[](#storing-method)

And, why not ... dump it into a json file again.

- `saveToJsonFile($fileName)`

Find methods
============

[](#find-methods)

find($id)
---------

[](#findid)

Just fetches the current record pointed by `$id` or null if does not exist.

findAll($field, $value, $filterCallback)
----------------------------------------

[](#findallfield-value-filtercallback)

if `$field` and `$value` are null returns all the records.

Always passes the record to `$filterCallback` being to added in order to know if passes the filter. Obviously if `$filterCallback` is null no filter applied.

You can check the examples on the Tests folder.

Exceptions
----------

[](#exceptions)

Since version 1.5 added the property `$notFoundThrowsException` in order to throw or not an Excepcion in the case the record is not found.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

3523d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f19216fd9d91bd7cfff14362e2ddb5728bd2d8f50d2e0174626fc61510ed33b?d=identicon)[jlaso](/maintainers/jlaso)

---

Top Contributors

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

---

Tags

jsonmemorydb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jlaso-simple-memory-db/health.svg)

```
[![Health](https://phpackages.com/badges/jlaso-simple-memory-db/health.svg)](https://phpackages.com/packages/jlaso-simple-memory-db)
```

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k328.4M741](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k493.5M159](/packages/mtdowling-jmespathphp)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k139.8M907](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k91.4M664](/packages/jms-serializer-bundle)[cerbero/json-parser

Zero-dependencies pull parser to read large JSON from any source in a memory-efficient way.

803550.1k5](/packages/cerbero-json-parser)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30524.1M52](/packages/colinodell-json5)

PHPackages © 2026

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