Documente Academic
Documente Profesional
Documente Cultură
- Lightweight
- Very easy to install, with minimal/no configuration
- Simple intuitive API
- Suitable for small data sets, low-load applications, and testing/prototyping
## Example Usage
```php
<?php
$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"]
```
## Installation
## Usage
### Reading
```php
$flatbase->read()->in('users')->get(); // Flatbase\Collection
```
```php
$flatbase->read()->in('users')->where('id', '==', '5')->get();
```
- `=`
- `!=`
- `==`
- `!==`
- `<`
- `>`
```php
$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
```
```php
$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
```
```php
$flatbase->read()->in('users')->count();
```
### Deleting
```php
$flatbase->delete()->in('users')->execute();
```
```php
$flatbase->delete()->in('users')->where('id', '==', 5)->execute();
```
### Inserting
```php
$flatbase->insert()->in('users')->set([
'name' => 'Adam',
'country' => 'UK',
'language' => 'English'
])->execute();
```
### Updating
Update all records in a collection:
```php
$flatbase->update()->in('users')->set(['country' => 'IE',])->execute();
```
```php
$flatbase->update()
->in('users')
->set(['country' => 'IE',])
->where('name', '==', 'Adam')
->execute();
```
```bash
php vendor/bin/flatbase read users
```
### Installation
To use the CLI, you must define the path to your storage directory. This can either
be done with a `flatbase.json` file in the directory you call flatbase from
(usually your application root):
```json
{
"path": "some/path/to/storage"
}
```
Alternatively, simply include the `--path` option when issuing commands. Eg:
```bash
php vendor/bin/flatbase read users --path="some/path/to/storage"
```
### Demo
<img src="https://raw.githubusercontent.com/adamnicholson/flatbase/master/cli-
demo.gif" />
### Usage
```bash
# Get all records
php flatbase read users
For more info on the CLI, use one of the `help` commands
```bash
php flatbase help
php flatbase read --help
php flatbase update --help
php flatbase insert --help
php flatbase delete --help
```
```php
$flatbase->insert()->in('users')->set([
'id' => 1,
'name' => 'Adam',
'added' => new DateTime()
])->execute();
It also means that you can, at any point, easily unserialize() your data without
having to go through Flatbase if you wish.
> Note: Although serializing is possible, be careful when using this in production.
Remember that if you serialize an object, and then, later on, delete or move the
class it was an instance of, you won't be able to un-serialize it. Storing scalar
data is always a safer alternative.
Ok, that's a bit of a baiting title. Some operations are remarkably quick
considering this is a flat file database. On a mediocre Ubuntu desktop development
environment, it can process around 50,000 "inserts" in 1 second. No, that is still
nowhere near a database like MySQL or Mongo, but it's a hell of a lot more than
most people need.
Reading data out is certainly a lot slower, and although there are lots of places
we can optimise, ultimately you'd need to accept this is never going to be a high-
performance solution for persistence.
## Author
## Contributing
Contributions are welcome, and they can be made via GitHub issues or pull requests.
## License
Flatbase is licensed under the MIT License - see the `LICENSE.txt` file for details