LevelDB is a kind of key-value C++ database developped by Google engineers.
My installation script is simple on Arch Linux:
1 | sudo pacman -Syu leveldb |
Example 1
We create and then delete a leveldb database instance. Another important thing is to learn how to build with leveldb dynamic link library.
1 | #include <iostream> |
compile and link: g++ test-leveldb.cc -Iinclude -l:libleveldb.so
-Iinclude
means searching *.h
files under /usr/include
, so that we can write the relevant referencing path as #include <leveldb/db.h>
since the full path of the header file is /usr/include/leveldb/db.h
. By default /usr/include
is included by gcc. Therefore, omitting -Iinclude
is also acceptable.
-l:libleveldb.so
means searching for libleveldb.so
under link library path, which by default is /usr/lib/
. -l:libleveldb.so
also has a shorten form: -lleveldb
.
Example 2
Create, Delete, Update, Query
1 | #include <iostream> |
compile and link as example 1 shows.
run ./a.out
. /tmp/testdb will appear:
Here we can notice that even though db
is deleted, the files created under /tmp/cduq-db
are still exist. If you want to delete this file, we can use leveldb::DestroyDB
.
LevelDB Structure:
Comments
shortname
for Disqus. Please set it in_config.yml
.