freekrai / schemaless
Schemaless database on top of SqLite
Installs: 195
Dependents: 0
Suggesters: 0
Security: 0
Watchers: 1
Open Issues: 0
pkg:composer/freekrai/schemaless
Requires
- php: >=5.3.2
This package is not auto-updated.
Last update: 2015-07-01 12:47:00 UTC
README
Schemaless database built on top of SqLite, based on MongoDB.
Sample Usage
$client = new Schemaless\Client( PATH_TO_WRITABLE_FOLDER );
$database = $client->testdb;
$collection = $database->products;
$entry = ["name"=>"Rocky Road", "price"=>20,'qty'=>20];
$collection->insert($entry);
$products = $collection->find(); // Get Cursor
if ( $products->count() ) {
echo 'Total Records: '.$products->count().'<br />';
foreach($products->sort( ["price"=>1] )->limit(5) as $product) {
echo '<pre>'.print_r($product,true).'</pre>';
}
}
Query collection
In general you can use a callback or simple array as criteria
$products = $collection->find(function($document) { // recommended to query data
return $document["price"] > 10;
});
foreach( $products as $product ){
echo '<pre>'.print_r($product,true).'</pre>';
}
echo '<hr />';
//or
$products = $collection->find( ["price"=>['$gt'=>10]] ); // only very simple criteria is supported (can be slow)
foreach( $products as $product ){
echo '<pre>'.print_r($product,true).'</pre>';
}
echo '<hr />';
//or just one
$product = $collection->findOne(function($document) { // recommended to query data
return $document["name"] == 'Rocky Road';
});
echo '<pre>'.print_r($product,true).'</pre>';
echo '<hr />';
$product = $collection->findOne( ["name"=>'Rocky Road'] );
echo '<pre>'.print_r($product,true).'</pre>';
Writing documents
$collection->insert($document); $collection->save($document); $collection->update($criteria, $data);
Delete documents
$collection->remove($criteria);
API
Client
Client::listDBs() Client::selectDB(databasename) Client::selectCollection(databasename, collectionname)
Database
Database::vacuum() Database::drop() Database::createCollection(collectionname) Database::dropCollection(collectionname) Database::getCollectionNames() Database::listCollections() Database::selectCollection(collectionname)
Collection
Collection::drop() Collection::renameCollection(newname) Collection::insert(document) Collection::save(document) Collection::update(criteria, data) Collection::remove(criteria) Collection::count() Collection::find(criteria) Collection::findOne(criteria)
Cursor
Cursor::count() Cursor::limit(number) Cursor::skip(number) Cursor::sort(array) Cursor::each($callable) Cursor::toArray()
Installation
To install and use Schemaless via the composer PHP package manager just take these steps:
If you don’t already have one, create the file composer.json in the root of your new project that is going to use Schemaless.
Add the following to the composer.json file..
{
"require": {
"freekrai/schemaless": "dev-master"
}
}
Install composer (if it isn’t already installed):
curl -s https://getcomposer.org/installer | php
php composer.phar install