PHPackages                             alexstandiford/underpin-berlindb - 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. alexstandiford/underpin-berlindb

Abandoned → [underpin/berlindb-extension](/?search=underpin%2Fberlindb-extension)Library[Database &amp; ORM](/categories/database)

alexstandiford/underpin-berlindb
================================

BerlinDB Implementation for Underpin

1.3.0(4y ago)171[1 issues](https://github.com/Underpin-WP/underpin-berlindb/issues)GPL-2.0-or-laterPHP

Since Dec 31Pushed 4y ago2 watchersCompare

[ Source](https://github.com/Underpin-WP/underpin-berlindb)[ Packagist](https://packagist.org/packages/alexstandiford/underpin-berlindb)[ RSS](/packages/alexstandiford-underpin-berlindb/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (2)Versions (7)Used By (0)

Underpin BerlinDB Extension
===========================

[](#underpin-berlindb-extension)

[BerlinDB](https://github.com/berlindb/core/) Integration for the [Underpin](https://github.com/underpin-wp/underpin) WordPress framework.

A few key benefits:

1. Tables are registered through a `Database_Model` class. This class provides useful context that makes working with BerlinDB a little easier helps keep your code DRY.
2. All tables are stored in a registry. This allows you to interact with *all* tables at one time. Need to uninstall everything? You can do that with a single method, instead of manually looping through tables.
3. All CRUD actions happen through database model instead of creating `Query` instances everywhere.

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

[](#installation)

### Using Composer

[](#using-composer)

`composer require underpin/berlindb-extension`

### Manually

[](#manually)

This plugin uses a built-in autoloader, so as long as BerlinDB is required *before*this extension, it should work as-expected.

`require_once(__DIR__ . '/underpin-berlin-db/underpin-berlin-db.php');`

Setup
-----

[](#setup)

1. Install [BerlinDB](https://www.github.com/berlindb/core)
2. Install Underpin. See [Underpin Docs](https://www.github.com/underpin-wp/underpin)
3. Create BerlinDB classes.
4. Register new database models as-needed.

Example
-------

[](#example)

If you currently have all BerlinDB classes built, you can reference them directly like-so. This will create a new database model called `example`, which can be referenced with `underpin()->berlin_db()->get('example')`.

```
underpin()->berlin_db()->add( 'example', [
	'table'             => 'Namespace\To\Berlin_DB\Table',
	'schema'            => 'Namespace\To\Berlin_DB\Schema',
	'query'             => 'Namespace\To\Berlin_DB\Query',
	'name'              => 'Human Readable Table Name',
	'description'       => 'Description of the purpose of this table',
	'sanitize_callback' => function( $key, $value ){
		// Function to sanitize fields before saving.
	}
] );
```

Alternatively, you can extend `Database_Model` and reference the extended class directly, like so:

```
underpin()->berlin_db()->add('database-model-key','Namespace\To\Class');
```

Working With the Model
----------------------

[](#working-with-the-model)

Once registered, you can access any of the classes inside the model using the various helper methods.

```
// Run a query using the specified model
underpin()->berlin_db()->get('example')->query([/*...*/]);

// Get table object
underpin()->berlin_db()->get('example')->table();

// Get schema
underpin()->berlin_db()->get('example')->schema();
```

Creating, Updating, and Deleting
--------------------------------

[](#creating-updating-and-deleting)

The model includes a handful of helper functions to make it a little easier to update data.

```
// Automatically sanitize, and then create/update a record.
// If the provided arguments include an ID, it will update that record.
// Otherwise, it will simply create a new record.
$id = underpin()->berlin_db()->get('example')->save( [/*...*/] );

// Delete a record
$deleted = underpin()->berlin_db()->get('example')->delete( $id );
```

Table Setup
-----------

[](#table-setup)

```
// Install all tables
underpin()->berlin_db()->install();

// Reset all tables
underpin()->berlin_db()->reset();

// Delete all tables
underpin()->berlin_db()->uninstall();
```

Meta Tables
-----------

[](#meta-tables)

If a database model also has a meta table, it is possible to instruct the model to make that table accessible in the model. To-do this, you simply have to use the `Database_Model_With_Meta_Instance` when registering your model.

```
// Meta Table
underpin()->berlin_db()->add( 'example-meta-table', [
	'table'             => 'Namespace\To\Berlin_DB\Table',
	'schema'            => 'Namespace\To\Berlin_DB\Schema',
	'query'             => 'Namespace\To\Berlin_DB\Query',
	'name'              => 'Human Readable Table Name',
	'description'       => 'Description of the purpose of this table',
	'sanitize_callback' => function( $key, $value ){
		// Function to sanitize fields before saving.
	}
] );

// Table
underpin()->berlin_db()->add( 'example', [
    'class' => 'Underpin_BerlinDB\Factories\Database_Model_With_Meta_Instance',
    'args' => [
       'table'             => 'Namespace\To\Berlin_DB\Table',
       'schema'            => 'Namespace\To\Berlin_DB\Schema',
       'query'             => 'Namespace\To\Berlin_DB\Query',
       'name'              => 'Human Readable Table Name',
       'description'       => 'Description of the purpose of this table',
       'sanitize_callback' => function( $key, $value ){
           // Function to sanitize fields before saving.
       },
       'get_meta_table_callback' => function(){
          return underpin()->berlin_db()->get('example-meta-table');
       }
	]
] );
```

Alternatively, you can extend `Database_Model`, use the `With_Meta` trait, and then reference the extended class directly, like so:

```
underpin()->berlin_db()->add('database-model-key','Namespace\To\Class\Using\With_Meta\Trait');
```

With this setup, you now have access to a few other methods from within the `example` model's context.

```
//add_meta
underpin()->berlin_db()->get('example')->add_meta(/*...*/);

//update_meta
underpin()->berlin_db()->get('example')->update_meta(/*...*/);

//delete_meta
underpin()->berlin_db()->get('example')->delete_meta(/*...*/);

//get_meta
underpin()->berlin_db()->get('example')->get_meta(/*...*/);
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.7% 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 ~108 days

Total

4

Last Release

1682d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e6206223bd6f2a57b8ac80605b1b5c3521faaec18ad3f20f25fb728a9a13784?d=identicon)[tstandiford](/maintainers/tstandiford)

---

Top Contributors

[![alexstandiford](https://avatars.githubusercontent.com/u/8210827?v=4)](https://github.com/alexstandiford "alexstandiford (22 commits)")[![ibes](https://avatars.githubusercontent.com/u/383277?v=4)](https://github.com/ibes "ibes (1 commits)")

---

Tags

berlindbdatabaseunderpinwordpress

### Embed Badge

![Health badge](/badges/alexstandiford-underpin-berlindb/health.svg)

```
[![Health](https://phpackages.com/badges/alexstandiford-underpin-berlindb/health.svg)](https://phpackages.com/packages/alexstandiford-underpin-berlindb)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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