maymeow/may-db

MayDB is NoSQL database for simple php projects

This package's canonical repository appears to be gone and the package has been frozen as a result.

v1.0.1 2017-03-21 19:30 UTC

This package is auto-updated.

Last update: 2019-05-13 15:11:09 UTC


README

NoSQL Datastore

Requirements

  • PHP 5.5 and up
  • Composer

Installation

composer require maymeow/may-db

Table, Row, Field?

SQL MayDB
Table Kind
Row Entity
Field Property
ID KEY

Usage

Configuration

Add this to your application. MayDb using constant DATASTORE to define path to files.

define('DATASTORE', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'datastore' . DIRECTORY_SEPARATOR);

Creating Kinds and Entities

  • Load class
use MayMeow\Db\MayDb;
$maydb = new MayDb(); 
  • Create new Kind
$maydb->addKind([
    'name' => 'profiles',
    'description' => 'Users profiles',
    'category' => 'Personal'
]);
  • Add entity
$maydb->getKind('users')
    ->addEntity(['name' => 'May', 'lastname' => 'Meow])
    ->write();

// or add more entities at once

$maydb->getKind('users')
    ->addEntity(['name' => 'May', 'lastname' => 'Meow])
    ->addEntity(['name' => 'Emma', 'lastname' => 'Meow])
    ->write();

Do not forget to save changes to datastore with write() function.

Retrieving data

  • Select all entities
$result = $maydb->getKind('users')->all();
  • Select first entity
$result = $maydb->getKind('users')->first();
  • Filtering entities
$result = $maydb->getKind('users')->filter('name', 'may')->all();

// or you can filter by more properties

$result = $maydb->getKind('users')
    ->filter('key', '2def3869-6146-4f5e-ba14-d1dbfc06c91e')
    ->filter('name', 'may')->all();

Filter can be combined with all()and first() functions;

Deleting data

  • Delete entity. In this version is recommended deletion by KEY.
$maydb->getKind('users')->deleteEntity('key', 'd60a0a18-bf07-47a7-9493-d70187377cdd');
  • Delete Kind
$maydb->getKind('profiles')->deleteKind();

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.

Credits

Charlotta Jung - MayMeow

License

MIT [LICENSE][]