Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjdev/php-ext-sophia
PHP Extension for Sophia
https://github.com/kjdev/php-ext-sophia
Last synced: 25 days ago
JSON representation
PHP Extension for Sophia
- Host: GitHub
- URL: https://github.com/kjdev/php-ext-sophia
- Owner: kjdev
- License: mit
- Created: 2015-05-01T06:21:42.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-26T00:45:54.000Z (almost 9 years ago)
- Last Synced: 2024-11-18T00:52:35.529Z (about 2 months ago)
- Language: C
- Size: 27.3 KB
- Stars: 6
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Extension for Sophia
This extension allows Sophia.
Documentation for Sophia can be found at
[» http://sophia.systems](http://sophia.systems).## Build
Required install Sophia.
``` bash
% git submodule update --init
% phpize
% ./configure
% make
% make install
```## Configration
sophia.ini:
```
extension=sophia.so; sophia.path="./storage"
```## Class synopsis
```
Sophia\Db {
public __construct( string $db [ , array $options ] )
public bool set( string|array $key, string $value )
public mixed get( string|array $key )
public bool delete( string|array $key )
public bool close ( void )
public bool begin( void )
public bool commit( void )
public bool rollback( void )
public Sophia\Cursor cursor( [ string $order, string|array $key ] )
}
``````
Sophia\Cursor {
public __construct(Sophia\Db $db [ , string $order, string|array $key ] )
public bool rewind(void)
public bool next(void)
public bool valid(void)
public string current(void)
public string key(void)
public array keys(void)
}
```## Examples
### basic
```php
namespace Sophia;$sp = new Db("test");
// $sp = new Db("test", ["sophia.path" => __DIR__ . "/sophia.storage"]);// set, get, delete
$sp->set("key", "value");
$value = $sp->get("key");
$sp->delete("key");// iterator
$cursor = $sp->cursor();
// $cursor = $sp->cursor("<");
// $cursor = $sp->cursor(">=", "key");
foreach ($cursor as $key => $value) {
echo "{$key} => {$value}\n";
}
```### transaction
```php
namespace Sophia;$sp = new Db("test_transaction");
// transaction
$sp->begin();
$sp->set("key", "value");
$sp->commit();
// $sp->rollback();
```### multipart key
```php
namespace Sophia;$sp = new Db("test_multipart", [
"db.test_multipart.index.key" => "string",
"db.test_multipart.index" => "number",
"db.test_multipart.index.number" => "u32",
]);// set, get, delete
$sp->set(["key" => "key", "number" => 1], "value-1");
$sp->set(["key" => "key", "number" => 2], "value-2");
$sp->set(["key" => "key", "number" => 3], "value-3");$value = $sp->get(["key" => "key", "number" => 1]);
/*
output:
value-1
*/$sp->delete(["key" => "key", "number" => 2]);
// iterator
$cursor = $sp->cursor(">=", ["key" => "key", "number" => 2]);
foreach ($cursor as $key => $value) {
echo "{$key} => {$value}\n";
var_dump($cursor->keys());
}
/*
output:
key => values-3
array(2) {
["key"]=>
string(3) "key"
["number"]=>
int(3)
}
*/
```