PHPackages                             arc/store - 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. arc/store

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

arc/store
=========

Schema free JSON store with search, hierarchical structure and indexes

3.2(5y ago)0581MITPHPPHP &gt;=7

Since Feb 23Pushed 5y ago2 watchersCompare

[ Source](https://github.com/Ariadne-CMS/arc-store)[ Packagist](https://packagist.org/packages/arc/store)[ Docs](https://github.com/Ariadne-CMS/arc/wiki)[ RSS](/packages/arc-store/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (1)

arc\\store: fast schema-free JSON store
=======================================

[](#arcstore-fast-schema-free-json-store)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b64920edde0c6da0f87b2e255abe490f30229b4b5407b92bed0494a9f9e6dca8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f41726961646e652d434d532f6172632d73746f72652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Ariadne-CMS/arc-store/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/11472e4e3d3e0d6ad18a8bc09f1b9eed7abefc3c6b761593c5ea0b3e7bea1a03/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f41726961646e652d434d532f6172632d73746f72652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Ariadne-CMS/arc-store/)[![Latest Stable Version](https://camo.githubusercontent.com/b5094ed9f081a70c6c2d2562045bb18b7dc4365ac5515cd73eac55abf054d356/68747470733a2f2f706f7365722e707567782e6f72672f6172632f73746f72652f762f737461626c652e737667)](https://packagist.org/packages/arc/store)[![Total Downloads](https://camo.githubusercontent.com/fb3f6c2837e3c31ca3a93f5cc2a66c87b435ae362c9e81407186beb367afe835/68747470733a2f2f706f7365722e707567782e6f72672f6172632f73746f72652f646f776e6c6f6164732e737667)](https://packagist.org/packages/arc/store)[![Latest Unstable Version](https://camo.githubusercontent.com/28ebf65c0d1cb71cc87f02dfe84a50b25d8e0dbba23a81c661eabddb75ca45e8/68747470733a2f2f706f7365722e707567782e6f72672f6172632f73746f72652f762f756e737461626c652e737667)](https://packagist.org/packages/arc/store)[![License](https://camo.githubusercontent.com/67feedb28f4c837ed6d7dc2a22e77411c101c4a9f63d489a11ad32c5c32d3e2f/68747470733a2f2f706f7365722e707567782e6f72672f6172632f73746f72652f6c6963656e73652e737667)](https://packagist.org/packages/arc/store)

arc\\store is part of [ARC - a component library](http://www.github.com/Ariadne-CMS/arc-arc/).

ARC is a spinoff from the Ariadne Web Application Platform and Content Management System .

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

[](#installation)

You can install the full set of ARC components using composer:

```
composer require arc/arc

```

Or you can start a new project with arc/arc like this:

```
composer create-project arc/arc {$path}

```

Or just use this package:

```
composer require arc/store

```

Usage
-----

[](#usage)

Example DSN for PostgreSQL:

```
	$dsn = 'pgsql:host=localhost;dbname=arcstore;user=arcstore;password=arcstore';
```

Example DSN for MySQL:

```
	$dsn = 'mysql:host=localhost;dbname=arcstore;user=arcstore;password=arcstore';
```

```
    $store = \arc\store::connect($dsn);
    $store->initialize();
    if ($store->save(\arc\prototype::create(["foo" => "bar"]), "/foo/")) {
        $objects = $store->ls('/');
        var_dump($objects);
    }
```

This will show an array with one object, with parent '/', name 'foo', and a single property 'foo' =&gt; 'bar'.

What is ARC\\Store?
-------------------

[](#what-is-arcstore)

ARC\\Store is a minimal implementation of the structured object store implemented in Ariadne-CMS. It stores free form object data in a tree structure, similar to a filesystem. It provides seperate query and save and delete methods. The query has its own format and parser. The data is stored in PostgreSQL using JSONB data blobs, which are fully indexed.

This solution gives you flexible and fast storage of any kind of data, while keeping many advantages of using a proven technology like PostgreSQL. Although this implementation doesn't have it, it would be easy to add transactions with commit/rollback to gain atomic updates, even for batch operations.

Because of its tree structure, ARC\\Store integrates well with other ARC Components, like ARC\\Grants and ARC\\Config.

methods
-------

[](#methods)

### \\arc\\store::connect

[](#arcstoreconnect)

```
(\arc\store\Store) \arc\store::connect( (string) $dsn, (callable) $resultHandler=null)

```

This method creates a new PSQLStore instance and connects it to a PostgreSQL database. Optionally you can pass your own resultHandler function. The PSQLStore class contains two static functions predefined for this:

- \\arc\\store\\ResultHandlers::getDBHandler
- \\arc\\store\\ResultHandlers::getDBGeneratorHandler These functions take 1 argument, the database connection, and return a result handler function. The result handler is called with a compiled SQL query where clause and arguments and must execute this and return the results.

### \\arc\\store::disconnect

[](#arcstoredisconnect)

```
(void) \arc\store::disconnect()

```

Removes the last store connection from the context stack (\\arc\\context).

### \\arc\\store::cd

[](#arcstorecd)

```
(\arc\store\PSQLStore) \arc\store::cd($path)

```

Returns a new store istance, with its default path set to $path. This call will always succeed, even if $path doesn't exist in the object store. It does not update the path of the store instance in the context stack (\\arc\\context). To do that, you must push the new store onto the context stack:

```
	\arc\context::push([
		'arcStore' => \arc\store::cd('/foo/')
	]);
```

### \\arc\\store::find

[](#arcstorefind)

```
(mixed) \arc\store::find((string) $query, (string) $path)

```

Compiles the query to SQL, calls the resultHandler with it and returs the results. The query syntax is read only, it can only read data, never update or delete it. You can also call this method on a store istance, like this:

```
	$store = \arc\context::cd('/');
	$objects = $store->find("foo='bar'");
```

The query format supports the following operators:

- `` more than
- `=` equals
- `=` more than or equal
- ``, `!=` not equal
- `~=` similar to, supports `%` and `?` wildcards
- `!~` not similar to, supports `%` and `?` wildcards
- `?` object contains the key (property)

You can combine multiple query parts using `and` and `or`. You can use parenthesis to group them. And you can negate a part by prefixing it with `not`. Strings must be enclosed in single quotes. A single quote inside the string should be escaped with a `\`.

You can query any part of the object, but there are a few meta data properties you can search for:

- `nodes.path` matches the full path of the object in the tree
- `nodes.parent` matches the full path of the objects parent in the tree
- `nodes.mtime` matches the datetime when the object was last changed
- `nodes.ctime` matches the datetime when the object was created

Example queries:

```
    $results = $store->find("nodes.path ~= '/foo/%'");
    $results = $store->find("foo.bar>3");
    $results = $store->find("foo.bar>3 and foo.bar
