Code Monkey home page Code Monkey logo

radareorg / sdb Goto Github PK

View Code? Open in Web Editor NEW
212.0 17.0 61.0 2.25 MB

Simple and fast string based key-value database with support for arrays and json

Home Page: https://www.radare.org/

License: MIT License

Makefile 6.08% Java 0.14% Lua 0.20% NewLisp 0.69% JavaScript 2.09% Python 2.73% C 56.50% Vala 3.01% C# 0.14% D 0.22% Go 0.44% C++ 21.71% HTML 0.90% Shell 3.66% Roff 0.26% Meson 0.74% Perl 0.14% V 0.34%
key-value database hashtable c data-structures hacktoberfest

sdb's Introduction

SDB (string database)

sdb is a simple string key/value database based on djb's cdb disk storage and supports JSON and arrays introspection.

mcsdbd is a memcache server with disk storage based on sdb. It is distributed as a standalone binary and a library.

There's also the sdbtypes: a vala library that implements several data structures on top of an sdb or a memcache instance.

GHA COV

Author

pancake [email protected]

Contains

  • namespaces (multiple sdb paths)
  • atomic database sync (never corrupted)
  • bindings for vala, luvit, newlisp and nodejs
  • command-line frontend for sdb databases
  • memcache client and server with sdb backend
  • arrays support (syntax sugar)
  • json parser/getter (js0n.c)

Rips

  • disk storage based on cdb code
  • linked lists from r2 api

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

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

Changes

I have modified cdb code a little to create smaller databases and be memory leak free in order to use it from a library.

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.

Usage example

Let's create a database!

$ sdb d hello=world
$ sdb d hello
world

Using arrays (>=0.6):

$ sdb - '[]list=1,2' '[0]list' '[0]list=foo' '[]list' '[+1]list=bar'
1
foo
2

Let's play with json:

$ sdb d g='{"foo":1,"bar":{"cow":3}}'
$ sdb d g:bar.cow
3
$ sdb - user='{"id":123}' user:id=99 user:id
99

Using the command-line without any disk database:

$ sdb - foo=bar foo a=3 +a -a
bar
4
3

$ sdb -
foo=bar
foo
bar
a=3
+a
4
-a
3

Remove the database

$ rm -f d

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.