All Projects → matehat → Objective Leveldb

matehat / Objective Leveldb

Licence: mit
An Objective-C database library built over Google's LevelDB

Projects that are alternatives of or similar to Objective Leveldb

Avsqldebugger
A Simple Core Data Debugger that will look inside your apps DB
Stars: ✭ 30 (-93.27%)
Mutual labels:  database, cocoapods
Goleveldb
LevelDB key/value database in Go.
Stars: ✭ 4,783 (+972.42%)
Mutual labels:  database, leveldb
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+60.76%)
Mutual labels:  database, leveldb
Sqift
Powerful Swift wrapper for SQLite
Stars: ✭ 119 (-73.32%)
Mutual labels:  database, cocoapods
Ardb
A redis protocol compatible nosql, it support multiple storage engines as backend like Google's LevelDB, Facebook's RocksDB, OpenLDAP's LMDB, PerconaFT, WiredTiger, ForestDB.
Stars: ✭ 1,707 (+282.74%)
Mutual labels:  database, leveldb
Lev
The complete REPL & CLI for managing LevelDB instances.
Stars: ✭ 295 (-33.86%)
Mutual labels:  database, leveldb
Ldb
A C++ REPL / CLI for LevelDB
Stars: ✭ 201 (-54.93%)
Mutual labels:  database, leveldb
Wickdb
Pure Rust LSM-tree based embedded storage engine
Stars: ✭ 298 (-33.18%)
Mutual labels:  database, leveldb
Arslineprogress
iOS progress bar, replacement for the default activity indicator.
Stars: ✭ 434 (-2.69%)
Mutual labels:  cocoapods
Animatedcollectionviewlayout
A UICollectionViewLayout subclass that adds custom transitions/animations to the UICollectionView without effecting your existing code.
Stars: ✭ 4,333 (+871.52%)
Mutual labels:  cocoapods
Tinydb
TinyDB is a lightweight document oriented database optimized for your happiness :)
Stars: ✭ 4,713 (+956.73%)
Mutual labels:  database
Lodash Id
Makes it easy to manipulate id-based resources with lodash or lowdb
Stars: ✭ 434 (-2.69%)
Mutual labels:  database
Sidemenu
An interactive iOS side menu with rich features.
Stars: ✭ 442 (-0.9%)
Mutual labels:  cocoapods
Chromacolorpicker
🎨 An intuitive iOS color picker built in Swift.
Stars: ✭ 434 (-2.69%)
Mutual labels:  cocoapods
Qmgo
Qmgo - The Go driver for MongoDB. It‘s based on official mongo-go-driver but easier to use like Mgo.
Stars: ✭ 444 (-0.45%)
Mutual labels:  database
Hokusai
A Swift library to provide a bouncy action sheet
Stars: ✭ 431 (-3.36%)
Mutual labels:  cocoapods
Swiftuipager
Native Pager in SwiftUI
Stars: ✭ 430 (-3.59%)
Mutual labels:  cocoapods
Tensorbase
TensorBase BE is building a high performance, cloud neutral bigdata warehouse for SMEs fully in Rust.
Stars: ✭ 440 (-1.35%)
Mutual labels:  database
Tppdf
TPPDF is a simple-to-use PDF builder for iOS
Stars: ✭ 444 (-0.45%)
Mutual labels:  cocoapods
Urweatherview
Show the weather effects onto view written in Swift4.2
Stars: ✭ 439 (-1.57%)
Mutual labels:  cocoapods

CircleCI

Introduction

An Objective-C database library built over Google's LevelDB, a fast embedded key-value store written by Google.

Installation

By far, the easiest way to integrate this library in your project is by using CocoaPods.

  1. Have Cocoapods installed, if you don't already

  2. In your Podfile, add the line

     pod 'Objective-LevelDB'
    
  3. Run pod install

  4. Make something awesome.

How to use

Creating/Opening a database file on disk

LevelDB *ldb = [LevelDB databaseInLibraryWithName:@"test.ldb"];
Setup Encoder/Decoder blocks

By default, any object you store will be encoded and decoded using NSKeyedArchiver/NSKeyedUnarchiver. You can customize this by providing encoder and decoder blocks, like this:

ldb.encoder = ^ NSData * (LevelDBKey *key, id object) {
  // return some data, given an object
}
ldb.decoder = ^ id (LevelDBKey *key, NSData * data) {
  // return an object, given some data
}
NSMutableDictionary-like API
ldb[@"string_test"] = @"laval"; // same as:
[ldb setObject:@"laval" forKey:@"string_test"];

NSLog(@"String Value: %@", ldb[@"string_test"]); // same as:
NSLog(@"String Value: %@", [ldb objectForKey:@"string_test"]);

[ldb setObject:@{@"key1" : @"val1", @"key2" : @"val2"} forKey:@"dict_test"];
NSLog(@"Dictionary Value: %@", [ldb objectForKey:@"dict_test"]);

All available methods can be found in its header file (documented).

Enumeration
[ldb enumerateKeysAndObjectsUsingBlock:^(LevelDBKey *key, id value, BOOL *stop) {
    // This step is necessary since the key could be a string or raw data (use NSDataFromLevelDBKey in that case)
    NSString *keyString = NSStringFromLevelDBKey(key); // Assumes UTF-8 encoding
    // Do something clever
}];

// Enumerate with options
[ldb enumerateKeysAndObjectsBackward:TRUE
                              lazily:TRUE       // Block below will have a block(void) instead of id argument for value
                       startingAtKey:someKey    // Start iteration there (NSString or NSData)
                 filteredByPredicate:predicate  // Only iterate over values matching NSPredicate
                           andPrefix:prefix     // Only iterate over keys prefixed with something 
                          usingBlock:^(LevelDBKey *key, void(^valueGetter)(void), BOOL *stop) {
                             
    NSString *keyString = NSStringFromLevelDBKey(key);
    
    // If we had wanted the value directly instead of a valueGetter block, we would've set the 
    // above 'lazily' argument to FALSE
    id value = valueGetter();
}]

More iteration methods are available, just have a look at the header section

Snapshots, NSDictionary-like API (immutable)

A snapshot is a readonly interface to the database, permanently reflecting the state of the database when it was created, even if the database changes afterwards.

LDBSnapshot *snap = [ldb newSnapshot]; // You get ownership of this variable, so in non-ARC projects,
                                       // you'll need to release/autorelease it eventually
[ldb removeObjectForKey:@"string_test"];

// The result of these calls will reflect the state of ldb when the snapshot was taken
NSLog(@"String Value: %@", [snap objectForKey:@"string_test"]);
NSLog(@"Dictionary Value: %@", [ldb objectForKey:@"dict_test"]);

All available methods can be found in its header file

Write batches, atomic sets of updates

Write batches are a mutable proxy to a LevelDB database, accumulating updates without applying them, until you do using -[LDBWritebatch apply]

LDBWritebatch *wb = [ldb newWritebatch];
[wb setObject:@{ @"foo" : @"bar" } forKey: @"another_test"];
[wb removeObjectForKey:@"dict_test"];

// Those changes aren't yet applied to ldb
// To apply them in batch, 
[wb apply];

All available methods can be found in its header file

LevelDB options
// The following values are the default
LevelDBOptions options = [LevelDB makeOptions];
options.createIfMissing = true;
options.errorIfExists   = false;
options.paranoidCheck   = false;
options.compression     = true;
options.filterPolicy    = 0;      // Size in bits per key, allocated for a bloom filter, used in testing presence of key
options.cacheSize       = 0;      // Size in bytes, allocated for a LRU cache used for speeding up lookups

// Then, you can provide it when initializing a db instance.
LevelDB *ldb = [LevelDB databaseInLibraryWithName:@"test.ldb" andOptions:options];
Per-request options
db.safe = true; // Make sure to data was actually written to disk before returning from write operations.
[ldb setObject:@"laval" forKey:@"string_test"];
[ldb setObject:[NSDictionary dictionaryWithObjectsAndKeys:@"val1", @"key1", @"val2", @"key2", nil] forKey:@"dict_test"];
db.safe = false; // Switch back to default

db.useCache = false; // Do not use DB cache when reading data (default to true);
Concurrency

As Google's documentation states, updates and reads from a leveldb instance do not require external synchronization to be thread-safe. Write batches do, and we've taken care of it, by isolating every LDBWritebatch it inside a serial dispatch queue, and making every request dispatch synchronously to it. So use it from wherever you want, it'll just work.

However, if you are using something like JSONKit for encoding data to JSON in the database, and you are clever enough to preallocate a JSONDecoder instance for all data decoding, beware that this particular object is not thread-safe, and you will need to take care of it manually.

Testing

If you want to run the tests, you will need Xcode 5, as the test suite uses the new XCTest.

Clone this repository and, once in it,

./setup-test.sh
cd Tests && open Objective-LevelDB.xcworkspace

Currently, all tests were setup to work with the iOS test suite.

License

Distributed under the MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].