public void Snapshot() { // modify db var writeOptions = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, writeOptions, "key1", "value1"); Native.leveldb_writeoptions_destroy(writeOptions); // create snapshot var snapshot = Native.leveldb_create_snapshot(Database); // modify db again writeOptions = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, writeOptions, "key2", "value2"); Native.leveldb_writeoptions_destroy(writeOptions); // read from snapshot var readOptions = Native.leveldb_readoptions_create(); Native.leveldb_readoptions_set_snapshot(readOptions, snapshot); var val1 = Native.leveldb_get(Database, readOptions, "key1"); Assert.AreEqual("value1", val1); var val2 = Native.leveldb_get(Database, readOptions, "key2"); Assert.IsNull(val2); Native.leveldb_readoptions_destroy(readOptions); // release snapshot Native.leveldb_release_snapshot(Database, snapshot); snapshot = IntPtr.Zero; }
public void WriteBatch() { var writeOptions = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, writeOptions, "key1", "value1"); var writeBatch = Native.leveldb_writebatch_create(); Native.leveldb_writebatch_delete(writeBatch, "key1"); Native.leveldb_writebatch_put(writeBatch, "key2", "value2"); Native.leveldb_write(Database, writeOptions, writeBatch); var readOptions = Native.leveldb_readoptions_create(); var value1 = Native.leveldb_get(Database, readOptions, "key1"); Assert.IsNull(value1); var value2 = Native.leveldb_get(Database, readOptions, "key2"); Assert.AreEqual("value2", value2); Native.leveldb_writebatch_delete(writeBatch, "key2"); Native.leveldb_writebatch_clear(writeBatch); Native.leveldb_write(Database, writeOptions, writeBatch); value2 = Native.leveldb_get(Database, readOptions, "key2"); Assert.AreEqual("value2", value2); Native.leveldb_writebatch_destroy(writeBatch); Native.leveldb_writeoptions_destroy(writeOptions); Native.leveldb_writeoptions_destroy(readOptions); }
public void Enumerator() { var writeOptions = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, writeOptions, "key1", "value1"); Native.leveldb_put(Database, writeOptions, "key2", "value2"); Native.leveldb_put(Database, writeOptions, "key3", "value3"); var entries = new List <KeyValuePair <string, string> >(); var readOptions = Native.leveldb_readoptions_create(); IntPtr iter = Native.leveldb_create_iterator(Database, readOptions); for (Native.leveldb_iter_seek_to_first(iter); (int)Native.leveldb_iter_valid(iter) != 0; Native.leveldb_iter_next(iter)) { string key = Native.leveldb_iter_key(iter); string value = Native.leveldb_iter_value(iter); var entry = new KeyValuePair <string, string>(key, value); entries.Add(entry); } Native.leveldb_iter_destroy(iter); Native.leveldb_readoptions_destroy(readOptions); Assert.AreEqual(3, entries.Count); Assert.AreEqual("key1", entries[0].Key); Assert.AreEqual("value1", entries[0].Value); Assert.AreEqual("key2", entries[1].Key); Assert.AreEqual("value2", entries[1].Value); Assert.AreEqual("key3", entries[2].Key); Assert.AreEqual("value3", entries[2].Value); Native.leveldb_writeoptions_destroy(writeOptions); }
public void Get() { var options = Native.leveldb_readoptions_create(); Native.leveldb_put(Database, options, "key1", "value1"); var value1 = Native.leveldb_get(Database, options, "key1"); Assert.AreEqual("value1", value1); Native.leveldb_put(Database, options, "key2", "value2"); var value2 = Native.leveldb_get(Database, options, "key2"); Assert.AreEqual("value2", value2); Native.leveldb_put(Database, options, "key3", "value3"); var value3 = Native.leveldb_get(Database, options, "key3"); Assert.AreEqual("value3", value3); // verify checksums Native.leveldb_readoptions_set_verify_checksums(options, true); value1 = Native.leveldb_get(Database, options, "key1"); Assert.AreEqual("value1", value1); // no fill cache Native.leveldb_readoptions_set_fill_cache(options, false); value2 = Native.leveldb_get(Database, options, "key2"); Assert.AreEqual("value2", value2); Native.leveldb_readoptions_destroy(options); }
public void Put() { var options = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, options, "key1", "value1"); Native.leveldb_put(Database, options, "key2", "value2"); Native.leveldb_put(Database, options, "key3", "value3"); }
public void Put(WriteOptions options, string key, string value) { CheckDisposed(); if (options == null) { options = new WriteOptions(); } Native.leveldb_put(Handle, options.Handle, key, value, encoding); }
public void Put(WriteOptions options, byte[] key, byte[] value) { CheckDisposed(); if (options == null) { options = new WriteOptions(); } Native.leveldb_put(Handle, options.Handle, key, value); }
public void Put() { var options = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, options, "key1", "value1"); Native.leveldb_put(Database, options, "key2", "value2"); Native.leveldb_put(Database, options, "key3", "value3"); // sync Native.leveldb_writeoptions_set_sync(options, true); Native.leveldb_put(Database, options, "key4", "value4"); }
public void Delete() { var options = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, options, "key1", "value1"); var value1 = Native.leveldb_get(Database, options, "key1"); Assert.AreEqual("value1", value1); Native.leveldb_delete(Database, options, "key1"); value1 = Native.leveldb_get(Database, options, "key1"); Assert.IsNull(value1); }
public static void leveldb_put(IntPtr db, IntPtr writeOptions, byte[] key, byte[] value) { string error; var keyLength = GetArrayLength(key); var valueLength = GetArrayLength(value); Native.leveldb_put(db, writeOptions, key, keyLength, value, valueLength, out error); CheckError(error); }
public void IsValid() { var writeOptions = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, writeOptions, "key1", "value1"); var readOptions = Native.leveldb_readoptions_create(); IntPtr iter = Native.leveldb_create_iterator(Database, readOptions); Native.leveldb_iter_seek_to_last(iter); Assert.IsTrue(Native.leveldb_iter_valid(iter)); Native.leveldb_iter_next(iter); Assert.IsFalse(Native.leveldb_iter_valid(iter)); }
public void Delete() { var writeOptions = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, writeOptions, "key1", "value1"); var readOptions = Native.leveldb_readoptions_create(); var value1 = Native.leveldb_get(Database, readOptions, "key1"); Assert.AreEqual("value1", value1); Native.leveldb_delete(Database, writeOptions, "key1"); value1 = Native.leveldb_get(Database, readOptions, "key1"); Assert.IsNull(value1); Native.leveldb_writeoptions_destroy(writeOptions); Native.leveldb_readoptions_destroy(readOptions); }
public void Get() { var options = Native.leveldb_readoptions_create(); Native.leveldb_put(Database, options, "key1", "value1"); var value1 = Native.leveldb_get(Database, options, "key1"); Assert.AreEqual("value1", value1); Native.leveldb_put(Database, options, "key2", "value2"); var value2 = Native.leveldb_get(Database, options, "key2"); Assert.AreEqual("value2", value2); Native.leveldb_put(Database, options, "key3", "value3"); var value3 = Native.leveldb_get(Database, options, "key3"); Assert.AreEqual("value3", value3); }