PHPackages                             guifcoelho/immu-table - 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. guifcoelho/immu-table

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

guifcoelho/immu-table
=====================

Package for using immutable ndjson models instead of regular SQL or NoSQL databases with sintax similar to Laravel Eloquent.

0.2.2(6y ago)110MITPHPPHP ~7.3

Since Jul 2Pushed 6y agoCompare

[ Source](https://github.com/guifcoelho/ImmuTable)[ Packagist](https://packagist.org/packages/guifcoelho/immu-table)[ RSS](/packages/guifcoelho-immu-table/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (9)Dependencies (9)Versions (11)Used By (0)

[![Build Status](https://camo.githubusercontent.com/d5a5b5ee29dfd630677d73386db040daa2ca0dc2a878143a9a601b83cecd07ac/68747470733a2f2f7472617669732d63692e636f6d2f67756966636f656c686f2f496d6d755461626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/guifcoelho/ImmuTable)[![Code Coverage Status](tests/report/coverage.svg)](tests/report/coverage.svg)

ImmuTable
=========

[](#immutable)

Package for using immutable ndjson models instead of regular SQL or NoSQL databases with sintax similar to Laravel Eloquent.

DO NOT use this package if your data are likely to change.

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

[](#installation)

`composer require guifcoelho/immu-table`

How to use it
=============

[](#how-to-use-it)

Configuration
-------------

[](#configuration)

The config class will look for a `config_path()` function. This function must return the configuration files repository where the `immutable.php` configuration file is located.

Copy `immutable.php` configuration file from `src/Config` and paste it into your own configuration folder.

By default, the tables will be stored in `storage/app/immutable/tables`.

The Engine class will load the tables in chunks of data. You can increase or decrese the `chunk_size` in the configuration file.

Declaring your model
--------------------

[](#declaring-your-model)

Create models the same way as in Laravel Eloquent:

```
use guifcoelho\ImmuTable\Model;

class Sample extends Model
{
    protected $table = "table_example";
}
```

It will load your data from the table `table_example.ndjson` and set all fields accordingly. If you want to restrict the fields to be loaded, just include the protected array `$fields`:

```
use guifcoelho\ImmuTable\Model;

class Sample extends Model
{
    protected $fields = ['id', 'name', 'email'];
}
```

If you do not want some fields to be returned in the `toArray()` or `toJson()` functions, just include their names in the `$hidden` array:

```
use guifcoelho\ImmuTable\Model;

class Sample extends Model
{
    protected $hidden = ['this', 'that'];
}
```

If you want your primary key to be anything but 'id', just declare it as below (remember that your primary key must be unique and integer):

```
use guifcoelho\ImmuTable\Model;

class Sample extends Model
{
    protected $primary_key = 'not_id';
}
```

Querying your models
--------------------

[](#querying-your-models)

You can query your model for data the same way as in Laravel Eloquent:

```
$query = SampleModel::where('id', 10)->first();
```

or,

```
$query = SampleModel::where('price', '>', 50)->first();
```

or chaining 'where' clauses,

```
$query = SampleModel::where('price', '>', 50)->where('id', '', 50)
            ->where('id', '
