PHPackages                             web-complete/micro-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. [File &amp; Storage](/categories/file-storage)
4. /
5. web-complete/micro-db

ActiveLibrary[File &amp; Storage](/categories/file-storage)

web-complete/micro-db
=====================

MicroDB

1.0.1(8y ago)03221MITPHPPHP &gt;=7.0.0

Since Nov 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/web-complete/microDb)[ Packagist](https://packagist.org/packages/web-complete/micro-db)[ RSS](/packages/web-complete-micro-db/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (2)Versions (3)Used By (1)

MicroDB
=======

[](#microdb)

[![Build Status](https://camo.githubusercontent.com/b484b65996a0b029d1fdfe97b0a277f7aacd55df9bef1c67b040a179f0fab30e/68747470733a2f2f7472617669732d63692e6f72672f7765622d636f6d706c6574652f6d6963726f44622e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/web-complete/microDb)[![Coverage Status](https://camo.githubusercontent.com/d2e4f2e2714007d11927d0df532c6b96648d371581306c9197fe42aaa3635dca/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7765622d636f6d706c6574652f6d6963726f44622f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/web-complete/microDb?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a404738d256305b0fe11c8d4c8f3d73490860ceda8d789fbb018e68cb274e039/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7765622d636f6d706c6574652f6d6963726f44622f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/web-complete/microDb/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/75c9bc29a283a6162c9013a35807b6710b17714b8f5d4e716033023b2d607c68/68747470733a2f2f706f7365722e707567782e6f72672f7765622d636f6d706c6574652f6d6963726f44622f76657273696f6e)](https://packagist.org/packages/web-complete/micro-db)[![License](https://camo.githubusercontent.com/f3ca17a76150494a4cf7510b0fa85de3d13013273c9fed5572d4c421132d596f/68747470733a2f2f706f7365722e707567782e6f72672f7765622d636f6d706c6574652f6d6963726f44622f6c6963656e7365)](https://packagist.org/packages/web-complete/micro-db)

Tiny schemaless file DB library with no dependencies. Most suitable for small sites and fast prototyping

Installation
------------

[](#installation)

```
composer require web-complete/microDb

```

Usage
-----

[](#usage)

#### create client

[](#create-client)

```
$microDb = new MicroDb(__DIR__ . '/storage', 'mydb1');
```

- you can switch it to runtime in-memory storage (for example, in tests)

```
$microDb->setType('runtime');
```

#### get collection

[](#get-collection)

Think about collection as a table in mysql-world

```
$usersCollection = $microDb->getCollection('users');
```

#### insert item

[](#insert-item)

```
$id = $usersCollection->insert(['name' => 'John Smith', 'some_data' => [1,2,3]]);
```

Collection will assign the item a new id. Default id field is "id", but you can use any you wish instead:

```
$id = $usersCollection->insert(['name' => 'John Smith', 'some_data' => [1,2,3]], "uid");
```

#### batch insert

[](#batch-insert)

Insert many items in one transaction

```
$usersCollection->insertBatch(
    ['name' => 'John Smith 1', 'some_data' => [1,2,3]],
    ['name' => 'John Smith 2', 'some_data' => [3,4,5]],
    ['name' => 'John Smith 3', 'some_data' => [5,6,7]],
);
```

#### update item

[](#update-item)

```
$filter = function ($item) {
    return $item['id'] == 2;
};
$usersCollection->update($filter, ['name' => 'John Smith 2 updated']);
```

update can affect many items as well:

```
$filter = function ($item) {
    return $item['last_visit'] < $newYear;
};
$usersCollection->update($filter, ['active' => false]);
```

#### delete item

[](#delete-item)

delete one or more items by filter

```
$filter = function ($item) {
    return $item['id'] == 2;
};
$usersCollection->delete($filter);
```

#### fetch many items

[](#fetch-many-items)

```
$filter = function ($item) {
    return $item['active'] == true;
};
$activeUsers = $usersCollection->fetchAll($filter);
```

or with sorting:

```
$filter = function ($item) {
    return $item['active'] == true;
};
$sort = function ($item1, $item2) {
    return $item1['last_visit']  $item2['last_visit'];
};
$activeUsers = $usersCollection->fetchAll($filter, $sort);
```

and limit 20, offset 100:

```
...
$activeUsers = $usersCollection->fetchAll($filter, $sort, 20, 100);
```

#### fetch one item

[](#fetch-one-item)

The same syntax as fetchAll (without limit, offset), but returns one item or null

```
...
$activeUser = $usersCollection->fetchOne($filter, $sort);
```

Find by id:

```
$user = $usersCollection->fetchOne(function ($item) {
    return $item['id'] == 15;
});
```

#### drop collection

[](#drop-collection)

```
$collection->drop();
```

#### runtime storage

[](#runtime-storage)

Runtime storage has 2 useful static methods to use in testing:

- **StorageRuntime::dump()** - returns current storage stage
- **StorageRuntime::clear()** - clears runtime storage

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

3028d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e557e816560f9c9295e3d74205ce5ac83f84ac226ffe51de5375556acae3f9e9?d=identicon)[mvkasatkin](/maintainers/mvkasatkin)

---

Top Contributors

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

---

Tags

filestoragenosqldb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/web-complete-micro-db/health.svg)

```
[![Health](https://phpackages.com/badges/web-complete-micro-db/health.svg)](https://phpackages.com/packages/web-complete-micro-db)
```

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.2k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M790](/packages/league-flysystem-aws-s3-v3)[league/flysystem-async-aws-s3

AsyncAws S3 filesystem adapter for Flysystem.

2610.5M31](/packages/league-flysystem-async-aws-s3)[microsoft/azure-storage-file

This project provides a set of PHP client libraries that make it easy to access Microsoft Azure Storage File APIs.

152.4M9](/packages/microsoft-azure-storage-file)[czim/file-handling

File Handling Helper

15803.8k1](/packages/czim-file-handling)[unisharp/laravel-fileapi

Laravel File API - Handle Files with Laravel Storage

5345.3k](/packages/unisharp-laravel-fileapi)

PHPackages © 2026

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