PHPackages                             vanqard/picotable - 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. vanqard/picotable

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

vanqard/picotable
=================

A small library to connect objects to db rows for rapid prototyping

0.1.3(10y ago)2171MITPHPPHP &gt;=5.5

Since Jan 10Pushed 10y ago1 watchersCompare

[ Source](https://github.com/vanqard/picotable)[ Packagist](https://packagist.org/packages/vanqard/picotable)[ Docs](https://phpbrilliance.com)[ RSS](/packages/vanqard-picotable/feed)WikiDiscussions master Synced 3w ago

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

Picotable
=========

[](#picotable)

A small library to add storage to any object. It's goal is to help with rapid prototyping.

It is not intended to replace a correctly specified and fully featured persistence layer and should certainly not be used in production code

Scenario
========

[](#scenario)

You need to run up a quick prototype. Pulling in your microframework of choice is all well and good but adding a database connection is a PITA

Not any more! Just add picotable to your prototype and add persistence to your models super quick and easy.

Basic premise
=============

[](#basic-premise)

Adding persistence to an object can be achieved by:

1. Adding the provided trait to an object's class
2. Providing the \_columnMap array property to the object's class to link object properties to table columns
3. Passing an instantiated object to the `Connector->connect()` method to link an object to a database table
4. Utilising the traits `load()`, `save()` and `delete()` methods to perform CRUD-like operations

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

[](#installation)

Simply use composer to add picotable to your prototype

```
composer require vanqard/picotable

```

Usage
=====

[](#usage)

You've already build out a demo model class and you need to hook each model up to a database table row.

Here are the steps to go through to get that working.

Modify your model class
-----------------------

[](#modify-your-model-class)

Supposing you have your POPO already to go, like this:

```
class UserModel
{
    private $name;
    private $email;
    private $age;
}

```

To connect it to a database table, with picotable installed, you'd edit the model class like this

```
use \Vanqard\Picotable\Traits\Storable as StorageTrait;
use \Vanqard\Picotable\Interfaces\StorableInterface;

class UserModel implements StorableInterface
{
    /**
     * Properties set to 'public' just for illustration. Feel free to
     * make them private and provide getters and setters / mutators as required
     */
    public $name;
    public $email;
    public $age;

    // Add the following
    private $usersId;

    private $_columnMap = [
        "usersId" => "users_id",  // Maps local property to db column
        "name",
        "email",
        "age"
    ];

    use StorageTrait;
}

```

Note what we have added there.

First of all, we've added a `$usersId` property to correspond to the primary key value of the table.

Secondly, we've added a `$_columnMap` property which declares which object properties should be persisted. Note how the first element of this array provides both a key and a value. In this instance, the key is the object property name and the value is the corresponding database table column name. This is to provide a translation for when the names differ.

The other elements of this array (name, email and age) do not require this treatment since the names are identical in both the object and the database table.

In any event, the good news is that you're now ready to persist your model objects.

Well, almost.

You need to set up the connection somewhere. You do this with the `Connector` object. Instantiating a `Connector` instance would normally be done somewhere in your bootstrap process before any requests are dealt with.

Here's the code to do that.

```
$connector = new \Vanqard\Picotable\Connector($dsn, $user, $pass);

```

As you can see, you need to provide connection parameters for the connector's construct. Here are some examples

```
// SQLite
$dsn = "sqlite:prototype.db";
$user = $pass = null;

// MySQL
$dsn = "mysql:host=localhost;dbname=prototype";
$user = "root";
$pass = "secret";

```

Ok, looking good.

So how do we connect a model object to a database table?

Like this

```
$myUser = new UserModel();
$connector->connect($myUser, 'users');  // Assume db table name is 'users'

```

That's it? Why yes, yes it is. Now you can do whatever you want with your model object

### Saving a new model

[](#saving-a-new-model)

```
$myUser = new UserModel();
$connector->connect($myUser, 'users');

$myUser->name = "joe";
$myUser->email = "joe@example.com";
$myUser->age = 42;

$myUser->_save();

echo $myUser->usersId;   // Just to confirm that we've saved successfully

```

### Loading a model from the db

[](#loading-a-model-from-the-db)

```
$myUser = new UserModel();
$connector->connect($myUser, 'users');

// Pass the primary key value to the _load method
$myUser->_load(1);

echo $myUser->name;  // Outputs 'joe' if joe is the name identified by the primary key value "1"

```

### Updating the db with a model

[](#updating-the-db-with-a-model)

```
$myUser = new UserModel();
$connector->connect($myUser, 'users');

$myUser->_load(1); // Loads the row for 'joe'

$myUser->name = "mary";
$myUser->email = "mary@example.com";
$myUser->age = "27";

$myUser->_save(); // Save knows when to insert and when to update

```

### Deleting a row in the db

[](#deleting-a-row-in-the-db)

```
$myUser = new UserModel();
$connector->connect($myUser, 'users');

$myUser->_load(1); // Loads the row for 'joe'

// ... sometime later

$myUser->_delete(); // Row is deleted for 'joe'

```

Todo
====

[](#todo)

- Error handling - There's virtually none in here at the moment
- Unit tests - These are also woefully absent but hey, this is the first commit. (And it works on my box)

Security issues
===============

[](#security-issues)

If you find any security problems with this code, please contact the author directly at

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

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

Total

3

Last Release

3811d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7ccc615e69aee8af93b347e31aa5fe3f0332ed83e45040e5b9c60fa7403c6380?d=identicon)[vanqard](/maintainers/vanqard)

---

Top Contributors

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

---

Tags

persistencetable gateway

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vanqard-picotable/health.svg)

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

###  Alternatives

[doctrine/doctrine-bundle

Symfony DoctrineBundle

4.8k249.9M3.9k](/packages/doctrine-doctrine-bundle)[doctrine/persistence

The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.

4.0k298.2M962](/packages/doctrine-persistence)[doctrine/doctrine-fixtures-bundle

Symfony DoctrineFixturesBundle

2.5k111.1M919](/packages/doctrine-doctrine-fixtures-bundle)[mongodb/mongodb

MongoDB driver library

1.6k66.6M593](/packages/mongodb-mongodb)[propel/propel

Propel2 is an open-source Object-Relational Mapping (ORM) for PHP.

1.3k5.5M112](/packages/propel-propel)[doctrine/mongodb-odm-bundle

Symfony Doctrine MongoDB Bundle

38519.4M227](/packages/doctrine-mongodb-odm-bundle)

PHPackages © 2026

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