Code Monkey home page Code Monkey logo

leveldb.jl's Introduction

LevelDB

LevelDB is Google's open source on-disk key-value storage library that provides an ordered mapping from string keys to binary values. In many applications where only key based accesses are needed, it tends to be a faster alternative than databases. LevelDB was written in C++ with a C calling API included. This module provides a Julia interface to LevelDB using Julia's ccall mechanism.

Install LevelDB

You can build LevelDB from its source code at https://github.com/google/leveldb. Please install the final dynamic library into a system directory such as /usr/lib or make sure libleveldb.so is in one of your LD_LIBRARY_PATH directories.

Run Testing Code

julia test/runtests.jl

This will exercise batched and non-batched writes and reads for string and float array values.

Create/Open/Close a LevelDB database

function open_db(file_path, create_if_missing)

Here file_path is the full path to a directory that hosts a LevelDB database, create_if_missing is a boolean flag when true the database will be created if it does not exist. The return value is a database object for passing to read/write calls.

function close_db(db)

Close a database, db is the object returned from a open_db call.

Read and Write Operations

function db_put(db, key, value, val_len)

key is a string, value is a pointer to a byte array, val_len is its length

function db_get(db, key)

Return value is a Uint8 array, one can use the reinterpret Julia function to cast it into the right array type (see test code).

function db_delete(db, key)

Batched Write

LevelDB supports grouping a number of put operations into a WriteBatch, the batch will either succeed as a whole or fail altogether, behaving like an atomic update.

function create_write_batch()

Create a WriteBatch object.

function batch_put(batch, key, value, val_len)

Add one key value Put operation into a WriteBatch

function write_batch(db, batch)

Commit the WriteBatch into the database as an atomic write.

General for loop

range = db_range(db, "key_start", "key_end")
for (k, v) in range
  #do something
end

Note: if you break the loop, you had to manually close the range by range_close(range).

Author

Jerry Zhenlei Cai ( jpenguin@gmail dot com )

leveldb.jl's People

Contributors

huwenshuo avatar jerry-cai-chanjet avatar jerryzhenleicai avatar

Watchers

 avatar  avatar

Forkers

zeta1999

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.