ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - shyiko/levelkt: LevelDB client for Kotlin and/or Java 8+
LevelDB client for Kotlin and/or Java 8+. Contribute to shyiko/levelkt development by creating an account on GitHub.
Visit Site

GitHub - shyiko/levelkt: LevelDB client for Kotlin and/or Java 8+

GitHub - shyiko/levelkt: LevelDB client for Kotlin and/or Java 8+

Initially project aimed to provide an alternative API for fusesource/leveldbjni's JNI layer fixing some of the issues around thread-safety, inefficient backward traversal, absent key-only iteration, Java 8 support. Later on, leveldbjni was replaced with protonail/leveldb-jna.

Compared to pure leveldb-jna, levelkt

  • hides the complexity associated with managing LevelDB Read/Write options
    (while optimizing number of JNA calls),
  • provides convenient API for range/prefix queries, existence checks and
  • makes it easier not to leak resources (you only need to close LevelDB, LevelDBSnapshot and LevelDBCursor instances (it will also warn you if you don't)).

Usage

<dependency>
    <groupId>com.github.shyiko.levelkt</groupId>
    <artifactId>levelkt</artifactId>
    <version>0.1.0</version>
    <!-- omit classifier below if you plan to use this library in koltin -->
    <classifier>kalvanized</classifier>
</dependency>

(example) Kotlin

import com.github.shyiko.levelkt.jna.JNALevelDB

JNALevelDB("/tmp/0.leveldb").use { levelDB ->

    levelDB.put("key1".toByteArray(), "value1".toByteArray())
    levelDB.put("key2.1".toByteArray(), "value2.1".toByteArray())
    levelDB.put("key2.2".toByteArray(), "value2.2".toByteArray())
    levelDB.put("key3".toByteArray(), "value3".toByteArray())

    assert(levelDB.get("key1".toByteArray())?.let { String(it) } == "value1")

    assert(levelDB.keySlice("key".toByteArray(), offset = 1, limit = 2).map { String(it) } == 
        listOf("key2.1", "key2.2"))
    assert(levelDB.keySlice("key2".toByteArray(), "key3".toByteArray()).map { String(it) } == 
        listOf("key2.1", "key2.2"))
    assert(levelDB.keySliceByPrefix("key2".toByteArray()).map { String(it) } == 
        listOf("key2.1", "key2.2"))

    levelDB.keyCursor().use { cursor ->
        assert(cursor.seek("key2".toByteArray())?.let { String(it) } == "key2.1")
        assert(cursor.next()?.let { String(it) } == "key2.2")
    }

    // slice/sliceByPrefix/cursor look exactly the same as keySlice/keySliceByPrefix/keyCursor
    // the only difference - they operate with LevelDBRecord instead of ByteArray

    levelDB.batch {
        put("key1".toByteArray(), "value1.updated".toByteArray())
        del("key3".toByteArray())
    }

    levelDB.del("key1".toByteArray())
    
}

(example) Java 8+

import com.github.shyiko.levelkt.LevelDB;
import com.github.shyiko.levelkt.jna.JNALevelDB;

try (LevelDB levelDB = new JNALevelDB("/tmp/0.levedb")) {

    levelDB.batch(batch -> batch
        .put("key1".getBytes(), "value1".getBytes())
        .put("key2.1".getBytes(), "value2.1".getBytes())
        .put("key2.2".getBytes(), "value2.2".getBytes())
        .put("key3".getBytes(), "value3".getBytes())
    );

    assert levelDB
        .sliceByPrefix("key2".getBytes())
        .stream()
        .map(record -> new String(record.getKey()) + "=" + new String(record.getValue()))
        .collect(Collectors.toList())
        .equals(Arrays.asList("key2.1=value2.1", "key2.2=value2.2"));

}

Development

git clone https://github.com/shyiko/levelkt && cd levelkt
./mvnw # shows how to build, test, etc. project

Legal

All code, unless specified otherwise, is licensed under the MIT license.
Copyright (c) 2017 Stanley Shyiko.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory