PHP code example of flatbase / flatbase

1. Go to this page and download the library: Download flatbase/flatbase library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flatbase / flatbase example snippets




$storage = new Flatbase\Storage\Filesystem('/path/to/storage/dir');
$flatbase = new Flatbase\Flatbase($storage);

$flatbase->insert()->in('users')
    ->set(['name' => 'Adam', 'height' => "6'4"])
    ->execute();

$flatbase->read()->in('users')
    ->where('name', '=', 'Adam')
    ->first();
// (array) ['name' => 'Adam', 'height' => "6'4"]


$flatbase->read()->in('users')->get(); // Flatbase\Collection

$flatbase->read()->in('users')->where('id', '==', '5')->get();

$flatbase->read()
    ->in('users')
    ->where('age', '<', 40)
    ->where('age', '>', 20)
    ->where('country', '==', 'UK')
    ->get();

$flatbase->read()->in('users')->limit(10)->get(); // Get the first 10 records
$flatbase->read()->in('users')->skip(5)->limit(10)->get(); // Skip the first 5, then return the next 10
$flatbase->read()->in('users')->first(); // Get the first record

$flatbase->read()->in('users')->sort('age')->get(); // Sort by age in ascending order
$flatbase->read()->in('users')->sortDesc('age')->get(); // Sort by age in descending order

$flatbase->read()->in('users')->count();

$flatbase->delete()->in('users')->execute();

$flatbase->delete()->in('users')->where('id', '==', 5)->execute();

$flatbase->insert()->in('users')->set([
    'name' => 'Adam',
    'country' => 'UK',
    'language' => 'English'
])->execute();

$flatbase->update()->in('users')->set(['country' => 'IE',])->execute();

$flatbase->update()
    ->in('users')
    ->set(['country' => 'IE',])
    ->where('name', '==', 'Adam')
    ->execute();

$flatbase->insert()->in('users')->set([
    'id' => 1,
    'name' => 'Adam',
    'added' => new DateTime()
])->execute();

$record = $flatbase->read()->in('users')->where('id', '==', 1)->first();
var_dump($record['added']); // DateTime
bash
php vendor/bin/flatbase read users
bash
php flatbase help
php flatbase read --help
php flatbase update --help
php flatbase insert --help
php flatbase delete --help