drocks

RocksServer db client


Keywords
library, vibed, web, communication, database, dlang, nosql, rocksdb
License
MIT
Install
dub fetch drocks --version 0.0.1

Documentation

Drocks is a Dlang driver for RocksDB server RocksServer Drocks is a Dlang driver for RocksDB server RocksServer

Dub version License

Usage

Create

auto db = Client(host, port);

or

auto db = Client.createDefault();

Get

By single key

string value = db.get(key);
string value = db[key];

By multi keys

auto values = db.get(key1, key2, key3);
auto values = db.get([key1, key2, key3]);
auto values = db.get(keysRange);

auto values = db[key1, key2, key3];
auto values = db[[key1, key2, key3]];
auto values = db[keysRange];

Set / Replace

By single key

db.set(key, value);
db.set(Pair(key, value));
db[key] = value;

By multi keys

auto range = [
    Pair(key1, val1),
    Pair(key2, val2),
    Pair(key3, val3),
];
db.set(range);
auto range = [
    tuple(key1, val1),
    tuple(key2, val2),
    tuple(key3, val3),
];
db.set(range);
auto map = [
    key1: val1,
    key2: val2,
    key3: val3,
];
db.set(map);

Delete keys

db.del(key);
db.del(key1, key2, key3);
db.del([key1, key2, key3]);
db.del(keysRange);

Increment value by key

db.incr(key, value);
db.incr(key);

db[key] += 7;
db[key] += -4;
db[key] -= 1;
++db[key];
--db[key];

Check if key exist

bool keyExist = db.has(key);
auto keyExist = db.has(key);
bool   has   = db.has(key).has;
string value = db.has(key).value;

Prefix iterator

auto range = db.getall(KeysPrefix);

More details

For more details see exmaples, tests and sources

How to extend

import drocks;
struct CustomClient
{
    mixin ExtendClient;
    //...
}

See exmaple:

struct CustomClient
{
    mixin ExtendClient;

    // incriment value by key
    long getIncr(string key, long value)
    {
        return _db.request.httpPost("get-incr", key, value).getValue().to!long;
    }
    long getIncr(string key)
    {
        return _db.request.httpPost("get-incr", key).getValue().to!long;
    }

    // Check if DB server is available
    bool ping() //const
    {
        return "pong" == _db.request.httpGet("ping").raw();
    }

    // Seack first pair by key prefix
    auto seekFirst(string prefix)
    {
        return _db.request.httpGet("seek-first", prefix).getPair();
    }

    // ...
}
try {
    auto db = CustomClient.createDefault();
    db.get("key1").writeln;
    db.getIncr("incr1").writeln;
    db.ping().writeln;
    db.seekFirst("key-prefix:").writeln;
} catch (ClientException e) {
    writeln(e.msg);
}

Tests

see tests readme

License

MIT