Skip to content
dddb a simple dlang database build on top of std.json
Branch: master
Clone or download
cvsae Merge pull request #3 from Mek101/patch-1
Fixed formatting and exception messages grammar
Latest commit 00da0cc Apr 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
source Fixed formatting and exception messages grammar Mar 30, 2019
.travis.yml Update .travis.yml Mar 25, 2018
CHANGELOG.md Update CHANGELOG.md Mar 25, 2018
README.md Update README.md Jul 1, 2018
dub.json First commit Mar 22, 2018

README.md

dddb

Build Status

dddb is lightweight and simple key-value dlang database (store) build on top of std.json

Usage

import std.stdio;
import dddb;

void main()
{
	
	auto db = new ddb("yes.db");
    

    // set multiple values to social_networks
    db.set("social_networks", "facebook");
    db.set("social_networks", "twitter");
    db.set("social_networks", "linkedin");

    writeln(db.get("social_networks"));
    // ["facebook", "twitter", "linkedin"]

    writeln(db.count("social_networks"));
    // will return 3, because we have add ["facebook", "twitter", "linkedin"]

    assert(db.count("social_networks") == 3);
    // no error because there are 3 ["facebook", "twitter", "linkedin"]

    db.update("social_networks", "facebook", "instagram");
    // update facebook to instagram 
    writeln(db.get("social_networks"));
    // ["instagram", "twitter", "linkedin"]

    assert(db.countkeys() == 1);
    writeln(db.getkeys()); 
    // db.getkeys() return a list of all keys,
    // ["social_networks"]

    assert(db.getsize() == 54);
    writeln(db.getsize());
    // db.getsize() return the database size in bytes
    // 58
    

    assert(db.havevalue("social_networks", "facebook") == false);
    writeln(db.havevalue("social_networks", "facebook")); // expected false
    // because facebook not exists in social_networks, we update it with instagram in line 240

    assert(db.havevalue("social_networks", "instagram") == true);
    writeln(db.havevalue("social_networks", "instagram")); // expected true 
    // true 


    // db.drop() delete database 
    // NOTE: all db data will be lost
    db.drop();
    assert(exists(db.db) == false);
}
You can’t perform that action at this time.