{"id":37039500,"url":"https://github.com/stratisproject/leveldb.net","last_synced_at":"2026-01-14T04:41:13.443Z","repository":{"id":44943157,"uuid":"391018820","full_name":"stratisproject/leveldb.net","owner":"stratisproject","description":"LevelDB for Windows and .NET standard","archived":false,"fork":true,"pushed_at":"2022-01-17T09:50:14.000Z","size":7570,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-27T13:24:23.239Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"oodrive/leveldb.net","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stratisproject.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-30T10:07:05.000Z","updated_at":"2024-01-05T12:43:30.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/stratisproject/leveldb.net","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/stratisproject/leveldb.net","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratisproject%2Fleveldb.net","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratisproject%2Fleveldb.net/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratisproject%2Fleveldb.net/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratisproject%2Fleveldb.net/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stratisproject","download_url":"https://codeload.github.com/stratisproject/leveldb.net/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratisproject%2Fleveldb.net/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28409753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T04:41:12.996Z","updated_at":"2026-01-14T04:41:13.438Z","avatar_url":"https://github.com/stratisproject.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# leveldb for Windows and .NET #\n\n----------\n\n[leveldb](http://code.google.com/p/leveldb/) is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.\n\nThis project aims to provide .NET bindings to LevelDB in addition to making leveldb work well on Windows.\n\n# Building leveldb #\n\n- Install CMake 3.15+\n- Build\n\n    - Windows/VS2019:\n    ```sh\n    build-leveldb.cmd\n    ```\n\n    - Linux (x86-64 with ARM/AArch64 cross-compilers):\n        - Ubuntu (x86-64):\n        ```sh\n        sudo dpkg --add-architecture i386\n        sudo apt update\n        sudo apt install gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu \\\n        g++-arm-linux-gnueabihf g++-aarch64-linux-gnu \\\n        libc-dev:i386 libstdc++-7-dev:i386 gcc-multilib g++-multilib\n        ```\n    ```./build-leveldb.sh```\n\n    - macOS (x86-64):\n    ```\n    build-leveldb-osx.zsh\n    ```\n\n\n# Installation #\nLevelDB.Standard is available as a NuGet package:\n\n```\nPM\u003e Install-Package LevelDB.Standard\n```\n\n# Getting Started #\n\nHere's how you can get started with leveldb and .NET.\n\n## Opening A Database ##\n\nA Leveldb database has a name which corresponds to a directory on the system.  This then stores all files in this particular folder.  In this example, you can create a new database (if missing) in the C:\\temp\\tempdb directory.\n\n```csharp\n// Open a connection to a new DB and create if not found\nvar options = new Options { CreateIfMissing = true };\nvar db = new DB(options, @\"C:\\temp\\tempdb\");\n```\n\n## Closing a Database ##\n\nWhen you are finished, you can close the database by calling the Close method.\n\n```csharp\n// Close the connection\ndb.Close();\n```\n\nThe DB class also implements the IDisposable interface which allows you to use the using block:\n\n```csharp\nvar options = new Options { CreateIfMissing = true };\nusing (var db = new DB(options, @\"C:\\temp\\tempdb\"))\n{\n    // Use leveldb\n}\n```\n\n## Reads and Writes ##\n\nleveldb provides the Get, Put and Delete methods to query, update and delete database objects.\n\n```csharp\nconst string key = \"New York\";\n\n// Put in the key value\nkeyValue.Put(key, \"blue\");\n\n// Print out the value\nvar keyValue = db.Get(key);\nConsole.WriteLine(keyValue);\n\n// Delete the key\ndb.Delete(key);\n```\n\n## Atomic Updates ##\n\nleveldb also supports atomic updates through the WriteBatch class and the Write method on the DB.  This ensures atomic updates should a process exit abnormally.\n\n```csharp\nvar options = new Options { CreateIfMissing = true };\nusing (var db = new DB(options, path))\n{\n    db.Put(\"NA\", \"Na\");\n\n    using(var batch = new WriteBatch())\n    {\n        batch.Delete(\"NA\")\n             .Put(\"Tampa\", \"Green\")\n             .Put(\"London\", \"red\")\n             .Put(\"New York\", \"blue\");\n        db.Write(batch);\n    }\n}\n```\n\n## Synchronous Writes ##\n\nFor performance reasons, by default, every write to leveldb is asynchronous.  This behavior can be changed by providing a WriteOptions class with the Sync flag set to true to a Put method call on the DB instance.\n\n```csharp\n// Synchronously write\nvar writeOptions = new WriteOptions { Sync = true };\ndb.Put(\"New York\", \"blue\");\n```\n\nThe downside of this is that due to a process crash, these updates may be lost.\n\nAs an alternative, atomic updates can be used as a safer alternative with a synchronous write which the cost will be amortized across all of the writes in the batch.\n\n```csharp\nvar options = new Options { CreateIfMissing = true };\nusing (var db = new DB(options, path))\n{\n    db.Put(\"New York\", \"blue\");\n\n    // Create a batch to set key2 and delete key1\n    using (var batch = new WriteBatch())\n    {\n        var keyValue = db.Get(\"New York\");\n        batch.Put(\"Tampa\", keyValue);\n        batch.Delete(\"New York\");\n\n        // Write the batch\n        var writeOptions = new WriteOptions { Sync = true; }\n        db.Write(batch, writeOptions);\n    }\n}\n```\n\n## Iteration ##\n\nThe leveldb bindings also supports iteration using the standard GetEnumerator pattern.  In this example, we can select all keys in a LINQ expression and then iterate the results, printing out each key.\n\n```csharp\nvar keys =\n    from kv in db as IEnumerable\u003cKeyValuePair\u003cstring, string\u003e\u003e\n    select kv.Key;\n\nforeach (var key in keys)\n{\n    Console.WriteLine(\"Key: {0}\", key);\n}\n```\n\nThe following example shows how you can iterate all the keys as strings.\n\n```csharp\n// Create new iterator\nusing (var iterator = db.CreateIterator())\n{\n    // Iterate to print the keys as strings\n    for (it.SeekToFirst(); it.IsValid(); it.Next())\n    {\n        Console.WriteLine(\"Key as string: {0}\", it.KeyAsString());\n    }\n}\n```\n\nThe next example shows how you can iterate all the values in the leveldb instance in reverse.\n\n```csharp\n// Create new iterator\nusing (var iterator = db.CreateIterator())\n{\n    // Iterate in reverse to print the values as strings\n    for (it.SeekToLast(); it.IsValid(); it.Prev())\n    {\n        Console.WriteLine(\"Value as string: {0}\", it.ValueAsString());\n    }\n}\n```\n\n## Snapshots ##\n\nSnapshots in leveldb provide a consistent read-only view of the entire state of the current key-value store.  Note that the Snapshot implements IDisposable and should be disposed to allow leveldb to get rid of state that was being maintained just to support reading as of that snapshot.\n\n```csharp\nvar options = new Options { CreateIfMissing = true }\nusing (var db = new Db(options, path))\n{\n    db.Put(\"Tampa\", \"green\");\n    db.Put(\"London\", \"red\");\n    db.Delete(\"New York\");\n\n    using (var snapshot = db.CreateSnapshot())\n    {\n        var readOptions = new ReadOptions {Snapshot = snapShot};\n\n        db.Put(\"New York\", \"blue\");\n\n        // Will return null as the snapshot created before\n        // the updates happened\n        Console.WriteLine(db.Get(\"New York\", readOptions));\n    }\n}\n```\n\n## Comparators ##\n\nThe leveldb keystore uses a default ordering function which orders bytes lexicographically, however, you can specify your own custom comparator when opening a database.\n\nTo specify a comparator, set the Comparator property on the Options instance by calling Comparator.Create.  In this instance, we will compare both x and y modulo 2.\n\n```csharp\nvar options = new Options { CreateIfMissing = true };\noptions.Comparator = Comparator.Create(\n    \"integers mod 2\",\n    (xs, ys) =\u003e LexicographicalCompare(((NativeArray\u003cint\u003e) xs).Select(x =\u003e x % 2),\n                                       ((NativeArray\u003cint\u003e) ys).Select(y =\u003e y % 2)));\n\nusing (var db = new Db(options, path))\n{\n    db.Put(1, new[] { 1, 2, 3 }, new WriteOptions());\n    Console.WriteLine(\"put 1, [1,2,3]\");\n\n    var key = NativeArray.FromArray(new int[] { 3 });\n    using (var xs = db.GetRaw\u003cint\u003e(key))\n    {\n        // Prints 1 2 3\n        Console.WriteLine(\"get {0} =\u003e [{1}]\", key[0], string.Join(\",\", xs));\n    }\n}\n```\n\nAnd the implementation of the Comparator is below:\n\n```csharp\nprivate int LexicographicalCompare\u003cT\u003e(IEnumerable\u003cT\u003e xs, IEnumerable\u003cT\u003e ys)\n{\n    var comparator = System.Collections.Generic.Comparer\u003cT\u003e.Default;\n\n    using(var xe = xs.GetEnumerator())\n    using(var ye = ys.GetEnumerator())\n    {\n        for(;;)\n        {\n            var xh = xe.MoveNext();\n            var yh = ye.MoveNext();\n            if (xh != yh)\n                return yh ? -1 : 1;\n            if (!xh)\n                return 0;\n\n            // more elements\n            int diff = comparator.Compare(xe.Current, ye.Current);\n            if (diff != 0)\n                return diff;\n        }\n    }\n}\n```\n\n# LICENSE #\n\n----------\n\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstratisproject%2Fleveldb.net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstratisproject%2Fleveldb.net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstratisproject%2Fleveldb.net/lists"}