Download the PHP package guifcoelho/immu-table without Composer
On this page you can find all versions of the php package guifcoelho/immu-table. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download guifcoelho/immu-table
More information about guifcoelho/immu-table
Files in guifcoelho/immu-table
Package immu-table
Short Description Package for using immutable ndjson models instead of regular SQL or NoSQL databases with sintax similar to Laravel Eloquent.
License MIT
Informations about the package immu-table
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
composer require guifcoelho/immu-table
How to use it
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
Create models the same way as in Laravel Eloquent:
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
:
If you do not want some fields to be returned in the toArray()
or toJson()
functions, just include their names in the $hidden
array:
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):
Querying your models
You can query your model for data the same way as in Laravel Eloquent:
or,
or chaining 'where' clauses,
or chaining 'orWhere' clauses
Declaring relations
You can declare relations between models the same way as Laravel Eloquent. Please, look into the Model
class to see which relations are implemented.
In the example above, the fields inside brackets are optional. See below a better explanation:
ImmuTable_belongsTo
: You must provide the parent class name. If necessary, provide the foreign key name inside the child model, and the related field name inside the parent model.ImmuTable_belongsToMany
: You must provide the parent class name. If necessary, provide the pivot table name, the current model's foreign key name in the pivot table, the parent model's foreign key name in the pivot table, the related current model's field name, and the related parent model's field name.ImmuTable_hasOne
: You must provide the child class name. If necessary, provide the foreign key name inside the child model and the related field name inside the parent model.ImmuTable_hasMany
: You must provide the children class name. If necessary, provide the foreign key name inside the children models and the related field name inside the parent model.
Contributing and testing
- Only tests:
./vendor/bin/phpunit
- Tests and coverage report:
composer tests-report-[linux|win]