sophia

Modern transactional key-value / row storage library

History

Unknow, but it seems that Dmitry Simonenko started this after an extensive reseach on kv-databases.

Some random thougths

  • It seems that there is some serious, one-sided, flamewar is going on between LMDB and Sophia
  • It seems that sophia is consistant faster then LevelDB

FAQ

What is it?

Key value database.

How cool is it?

Very.

Competitors?

many, many, many. Here is a curated list: https://github.com/pmwkaa/engine.so

When to use it?

When you want to store arbitrary data by key, and have the power of a cursor

Is it dead?

No.

Where is it?

http://sophia.systems

How to use it

The documentation is extensive.

Download

file: 1_download.sh

#!/bin/bash

mkdir -p tmp
cd ./tmp
wget -q -O sophia-2.2.tgz https://github.com/pmwkaa/sophia/archive/version_2.2.tar.gz
tar -xaf sophia-2.2.tgz 
cd sophia-version_2.2
make libsophia.a

Init

file: main.c

#include <stdio.h>

#include <sophia.h>

int main(const int argc, const char **argv) {
	void *env = sp_env();
	sp_setstring(env, "sophia.path", "./storage", 0);
	sp_setstring(env, "db", "test", 0);
	sp_setint(env, "db.test.compaction.cache", 4ULL * 1024 * 1024 * 1024);
	sp_open(env);
	void *db = sp_getobject(env, "db.test");

	/* single statement transaction */
	{
		void *o = sp_document(db);

		sp_setstring(o, "key", "hello", 0);
		sp_setstring(o, "value", "world", 0);
		sp_set(db, o); /* transaction */
		o = sp_document(db);
		sp_setstring(o, "key", "hello", 0);
		sp_delete(db, o);
	}
	/* working with cursors */
	{
		void *o = sp_document(db);
		void *cursor = sp_cursor(env);

		sp_setstring(o, "order", ">=", 0);
		while ((o = sp_get(cursor, o))) {
			char *key = sp_getstring(o, "key", NULL);
			char *value = sp_getstring(o, "value", NULL);
			printf("%s = %s\n", key, value);
		}
		sp_destroy(cursor);
	}

	sp_destroy(env);
}

## Compile and link

__**file**: [2_compile_and_run.sh](2_compile_and_run.sh)__

```bash
#!/bin/bash

gcc -o ./tmp/main main.c \
    -O2 -DNDEBUG \
    -std=c99 \
    -lpthread \
    -I./tmp/sophia-version_2.2 \
    -L./tmp/sophia-version_2.2/ -lsophia
./tmp/main

Further reading:

We only tipped the top of the iceberg here. There is much more:

http://sophia.systems/v2.2/index.html