2014-02-18 01:35:28 +01:00
|
|
|
SDB (string database)
|
2012-09-04 01:46:12 +02:00
|
|
|
=====================
|
|
|
|
|
2013-04-01 05:52:21 +02:00
|
|
|
sdb is a simple string key/value database based on djb's cdb
|
|
|
|
disk storage and supports JSON and arrays introspection.
|
|
|
|
|
2012-09-04 01:46:12 +02:00
|
|
|
mcsdbd is a memcache server with disk storage based on sdb.
|
2013-04-01 05:52:21 +02:00
|
|
|
It is distributed as a standalone binary and a library.
|
2012-09-04 01:46:12 +02:00
|
|
|
|
2013-04-01 05:52:21 +02:00
|
|
|
There's also the sdbtypes: a vala library that implements
|
|
|
|
several data structures on top of an sdb or a memcache instance.
|
2012-09-04 01:46:12 +02:00
|
|
|
|
2020-12-28 21:07:32 +01:00
|
|
|
[](https://github.com/radareorg/sdb/actions?query=workflow%3Aci)
|
|
|
|
[](https://travis-ci.org/radareorg/sdb)
|
2020-04-09 12:14:29 +02:00
|
|
|
[](https://travis-ci.org/radareorg/sdb)
|
2014-04-16 06:26:47 +02:00
|
|
|
[](https://scan.coverity.com/projects/1651)
|
|
|
|
|
2013-04-01 05:52:21 +02:00
|
|
|
Author
|
|
|
|
------
|
|
|
|
pancake <pancake@nopcode.org>
|
2012-09-04 01:46:12 +02:00
|
|
|
|
|
|
|
Contains
|
|
|
|
--------
|
2013-04-01 05:52:21 +02:00
|
|
|
* namespaces (multiple sdb paths)
|
|
|
|
* atomic database sync (never corrupted)
|
|
|
|
* bindings for vala, luvit, newlisp and nodejs
|
2021-05-25 10:51:18 +02:00
|
|
|
* command-line frontend for sdb databases
|
2012-09-04 01:46:12 +02:00
|
|
|
* memcache client and server with sdb backend
|
2013-04-01 05:52:21 +02:00
|
|
|
* arrays support (syntax sugar)
|
2012-09-04 01:46:12 +02:00
|
|
|
* json parser/getter (js0n.c)
|
|
|
|
|
|
|
|
Rips
|
|
|
|
----
|
|
|
|
* disk storage based on cdb code
|
|
|
|
* linked lists from r2 api
|
|
|
|
|
2016-10-20 21:12:52 +02:00
|
|
|
Compilation
|
|
|
|
-----------
|
|
|
|
For native builds just type `make`. Everything will be compiled twice to get the .dylib and .a and sdb in PIC and nonPIC modes.
|
|
|
|
|
|
|
|
To compile with Emscripten for Javascript:
|
|
|
|
|
|
|
|
make CC=emcc EXT_EXE=.js
|
|
|
|
|
2020-12-27 12:09:20 +01:00
|
|
|
To crosscompile with meson:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ cat > cross-file.txt <<EOF
|
|
|
|
[properties]
|
|
|
|
exe_wrapper = 'wine'
|
|
|
|
and then run meson build --cross-file cross-file.txt ; ninja -C build. It should work and it should create another binary called sdb_native.
|
|
|
|
EOF
|
|
|
|
$ meson build --cross-file cross-file.txt
|
|
|
|
$ ninja -C build
|
|
|
|
```
|
|
|
|
|
2012-09-04 01:46:12 +02:00
|
|
|
Changes
|
|
|
|
-------
|
2013-04-01 05:52:21 +02:00
|
|
|
I have modified cdb code a little to create smaller databases and
|
|
|
|
be memory leak free in order to use it from a library.
|
2012-09-04 01:46:12 +02:00
|
|
|
|
|
|
|
The sdb's cdb database format is 10% smaller than the original
|
|
|
|
one. This is because keylen and valuelen are encoded in 4 bytes:
|
|
|
|
1 for the key length and 3 for the value length.
|
|
|
|
|
|
|
|
In a test case, a 4.3MB cdb database takes only 3.9MB after this
|
|
|
|
file format change.
|
|
|
|
|
2013-04-01 05:52:21 +02:00
|
|
|
Usage example
|
|
|
|
-------------
|
2012-09-04 01:46:12 +02:00
|
|
|
Let's create a database!
|
|
|
|
|
2021-06-10 13:52:29 +02:00
|
|
|
```
|
|
|
|
$ sdb d hello=world
|
|
|
|
$ sdb d hello
|
|
|
|
world
|
|
|
|
```
|
2012-09-04 01:46:12 +02:00
|
|
|
|
2013-04-01 05:52:21 +02:00
|
|
|
Using arrays (>=0.6):
|
|
|
|
|
2021-06-10 13:52:29 +02:00
|
|
|
```
|
|
|
|
$ sdb - '[]list=1,2' '[0]list' '[0]list=foo' '[]list' '[+1]list=bar'
|
|
|
|
1
|
|
|
|
foo
|
|
|
|
2
|
|
|
|
```
|
2013-04-01 05:52:21 +02:00
|
|
|
|
2012-09-04 01:46:12 +02:00
|
|
|
Let's play with json:
|
|
|
|
|
2021-06-10 13:52:29 +02:00
|
|
|
```
|
|
|
|
$ sdb d g='{"foo":1,"bar":{"cow":3}}'
|
|
|
|
$ sdb d g:bar.cow
|
|
|
|
3
|
|
|
|
$ sdb - user='{"id":123}' user:id=99 user:id
|
|
|
|
99
|
|
|
|
```
|
2012-09-04 01:46:12 +02:00
|
|
|
|
2021-05-25 10:51:18 +02:00
|
|
|
Using the command-line without any disk database:
|
2013-04-01 05:52:21 +02:00
|
|
|
|
2021-06-10 13:52:29 +02:00
|
|
|
```
|
|
|
|
$ sdb - foo=bar foo a=3 +a -a
|
|
|
|
bar
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
|
|
|
$ sdb -
|
|
|
|
foo=bar
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
a=3
|
|
|
|
+a
|
|
|
|
4
|
|
|
|
-a
|
|
|
|
3
|
|
|
|
```
|
2012-09-04 01:46:12 +02:00
|
|
|
|
|
|
|
Remove the database
|
|
|
|
|
2021-06-10 13:52:29 +02:00
|
|
|
```
|
|
|
|
$ rm -f d
|
|
|
|
```
|