LocalDB is a small package to read and write JSON files in a Laravel Eloquent like style.
It was originally developed for small web servers that cannot connect to classic databases.
This package ist available via composer.
composer require vollborn/local-db
In the base path all json files are stored. The default value is ../storage/local-db.
You can change it if you need to:
LocalDB::setBasePath(<your path>);
Every table or json file needs to be registered beforehand.
LocalDB::table('test', static function (Table $table) {
$table->int('int')->autoincrements();
$table->array('array')->nullable();
$table->boolean('boolean');
$table->float('float');
$table->string('string');
});
As you can see, there are multiple data types available:
Name | Function |
---|---|
Integer | int |
Array | array |
Boolean | boolean |
Float | float |
String | string |
In addition, integers can have autoincrements.
All data types can also be nullable.
LocalDB::query('test')->create([
'float' => 1.00,
'string' => null,
'boolean' => false,
'array' => []
]);
You can either get all data...
LocalDB::query('test')->get();
or just the first entry...
LocalDB::query('test')->first();
The data can also be filtered.
LocalDB::query('test')->where('float', '=', 1.00)->get();
Available operators:
- =
- !=
- <
- >
- <=
- >=
Furthermore, the data can be ordered.
// ascending
LocalDB::query('test')->orderBy('float')->get();
// descending
LocalDB::query('test')->orderBy('float', true)->get();
There are some numeric operations available too.
// minimal value
LocalDB::query('test')->min('float');
// maximal value
LocalDB::query('test')->max('float');
// average value
LocalDB::query('test')->avg('float');
// summed value
LocalDB::query('test')->sum('float');
LocalDB::query('test')
->where('boolean', '=', false)
->update([
'boolean' => true
]);
LocalDB::query('test')
->where('boolean', '=', false)
->delete();