Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vollborn/local-db
LocalDB is a small package to read and write JSON files in a Laravel Eloquent like style.
https://github.com/vollborn/local-db
composer database eloquent json laravel package packagist php php-json
Last synced: about 4 hours ago
JSON representation
LocalDB is a small package to read and write JSON files in a Laravel Eloquent like style.
- Host: GitHub
- URL: https://github.com/vollborn/local-db
- Owner: vollborn
- License: mit
- Created: 2021-08-25T18:40:06.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-21T16:29:30.000Z (about 2 years ago)
- Last Synced: 2024-07-18T12:33:15.703Z (4 months ago)
- Topics: composer, database, eloquent, json, laravel, package, packagist, php, php-json
- Language: PHP
- Homepage: https://packagist.org/packages/vollborn/local-db
- Size: 15.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# LocalDB
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.
## Installation
This package ist available via [composer](https://getcomposer.org/).
```shell
composer require vollborn/local-db
```
## Configuration
### Set the base path
In the base path all json files are stored. The default value is **../storage/local-db**.You can change it if you need to:
```php
LocalDB::setBasePath();
```### Register a table
Every table or json file needs to be registered beforehand.
```php
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*.
## Usage
### Create data
```php
LocalDB::query('test')->create([
'float' => 1.00,
'string' => null,
'boolean' => false,
'array' => []
]);
```### Get data
You can either get all data...
```php
LocalDB::query('test')->get();
```or just the first entry...
```php
LocalDB::query('test')->first();
```The data can also be filtered.
```php
LocalDB::query('test')->where('float', '=', 1.00)->get();
```Available operators:
- =
- !=
- <
- \>
- <=
- \>=Furthermore, the data can be ordered.
```php
// ascending
LocalDB::query('test')->orderBy('float')->get();// descending
LocalDB::query('test')->orderBy('float', true)->get();
```There are some numeric operations available too.
```php
// 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');
```### Update data
```php
LocalDB::query('test')
->where('boolean', '=', false)
->update([
'boolean' => true
]);
```### Delete data
```php
LocalDB::query('test')
->where('boolean', '=', false)
->delete();
```