{"id":13630926,"url":"https://github.com/dain/leveldb","last_synced_at":"2025-05-14T00:08:27.606Z","repository":{"id":38485500,"uuid":"2101910","full_name":"dain/leveldb","owner":"dain","description":"Port of LevelDB to Java","archived":false,"fork":false,"pushed_at":"2022-11-19T02:04:32.000Z","size":653,"stargazers_count":1541,"open_issues_count":36,"forks_count":429,"subscribers_count":113,"default_branch":"master","last_synced_at":"2025-04-10T02:18:04.620Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dain.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":"2011-07-25T15:55:24.000Z","updated_at":"2025-04-09T03:33:19.000Z","dependencies_parsed_at":"2023-01-22T02:49:39.983Z","dependency_job_id":null,"html_url":"https://github.com/dain/leveldb","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dain%2Fleveldb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dain%2Fleveldb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dain%2Fleveldb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dain%2Fleveldb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dain","download_url":"https://codeload.github.com/dain/leveldb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043996,"owners_count":22005055,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2024-08-01T22:02:03.486Z","updated_at":"2025-05-14T00:08:22.598Z","avatar_url":"https://github.com/dain.png","language":"Java","readme":"# LevelDB in Java\n\nThis is a rewrite (port) of [LevelDB](http://code.google.com/p/leveldb/) in\nJava.  This goal is to have a feature complete implementation that is within\n10% of the performance of the C++ original and produces byte-for-byte exact\ncopies of the C++ code.\n\n# Current status\n\nCurrently the code base is basically functional, but only trivially tested.\nIn some places, this code is a literal conversion of the C++ code and in\nothers it has been converted to a more natural Java style.  The plan is to\nleave the code closer to the C++ original until the baseline performance has\nbeen established.\n\n## API Usage:\n\nRecommended Package imports:\n\n```java\nimport org.iq80.leveldb.*;\nimport static org.iq80.leveldb.impl.Iq80DBFactory.*;\nimport java.io.*;\n```\n\nOpening and closing the database.\n\n```java\nOptions options = new Options();\noptions.createIfMissing(true);\nDB db = factory.open(new File(\"example\"), options);\ntry {\n  // Use the db in here....\n} finally {\n  // Make sure you close the db to shutdown the \n  // database and avoid resource leaks.\n  db.close();\n}\n```\n\nPutting, Getting, and Deleting key/values.\n\n```java\ndb.put(bytes(\"Tampa\"), bytes(\"rocks\"));\nString value = asString(db.get(bytes(\"Tampa\")));\ndb.delete(bytes(\"Tampa\"), wo);\n```\n\nPerforming Batch/Bulk/Atomic Updates.\n\n```java\nWriteBatch batch = db.createWriteBatch();\ntry {\n  batch.delete(bytes(\"Denver\"));\n  batch.put(bytes(\"Tampa\"), bytes(\"green\"));\n  batch.put(bytes(\"London\"), bytes(\"red\"));\n\n  db.write(batch);\n} finally {\n  // Make sure you close the batch to avoid resource leaks.\n  batch.close();\n}\n```\n\nIterating key/values.\n\n```java\nDBIterator iterator = db.iterator();\ntry {\n  for(iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {\n    String key = asString(iterator.peekNext().getKey());\n    String value = asString(iterator.peekNext().getValue());\n    System.out.println(key+\" = \"+value);\n  }\n} finally {\n  // Make sure you close the iterator to avoid resource leaks.\n  iterator.close();\n}\n```\n\nWorking against a Snapshot view of the Database.\n\n```java\nReadOptions ro = new ReadOptions();\nro.snapshot(db.getSnapshot());\ntry {\n  \n  // All read operations will now use the same \n  // consistent view of the data.\n  ... = db.iterator(ro);\n  ... = db.get(bytes(\"Tampa\"), ro);\n\n} finally {\n  // Make sure you close the snapshot to avoid resource leaks.\n  ro.snapshot().close();\n}\n```\n\nUsing a custom Comparator.\n\n```java\nDBComparator comparator = new DBComparator(){\n    public int compare(byte[] key1, byte[] key2) {\n        return new String(key1).compareTo(new String(key2));\n    }\n    public String name() {\n        return \"simple\";\n    }\n    public byte[] findShortestSeparator(byte[] start, byte[] limit) {\n        return start;\n    }\n    public byte[] findShortSuccessor(byte[] key) {\n        return key;\n    }\n};\nOptions options = new Options();\noptions.comparator(comparator);\nDB db = factory.open(new File(\"example\"), options);\n```\n    \nDisabling Compression\n\n```java\nOptions options = new Options();\noptions.compressionType(CompressionType.NONE);\nDB db = factory.open(new File(\"example\"), options);\n```\n\nConfiguring the Cache\n\n```java    \nOptions options = new Options();\noptions.cacheSize(100 * 1048576); // 100MB cache\nDB db = factory.open(new File(\"example\"), options);\n```\n\nGetting approximate sizes.\n\n```java\nlong[] sizes = db.getApproximateSizes(new Range(bytes(\"a\"), bytes(\"k\")), new Range(bytes(\"k\"), bytes(\"z\")));\nSystem.out.println(\"Size: \"+sizes[0]+\", \"+sizes[1]);\n```\n    \nGetting database status.\n\n```java\nString stats = db.getProperty(\"leveldb.stats\");\nSystem.out.println(stats);\n```\n\nGetting informational log messages.\n\n```java\nLogger logger = new Logger() {\n  public void log(String message) {\n    System.out.println(message);\n  }\n};\nOptions options = new Options();\noptions.logger(logger);\nDB db = factory.open(new File(\"example\"), options);\n```\n\nDestroying a database.\n\n```java    \nOptions options = new Options();\nfactory.destroy(new File(\"example\"), options);\n```\n\n# Projects using this port of LevelDB\n\n* [ActiveMQ Apollo](http://activemq.apache.org/apollo/): Defaults to using leveldbjni, but falls \n  back to this port if the jni port is not available on your platform.\n","funding_links":[],"categories":["Java","II. Databases, search engines, big data and machine learning","数据库","Memory and concurrency"],"sub_categories":["1. Databases and storages"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdain%2Fleveldb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdain%2Fleveldb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdain%2Fleveldb/lists"}