{"id":16246860,"url":"https://github.com/chjj/lcdb","last_synced_at":"2025-09-10T08:32:12.784Z","repository":{"id":37283491,"uuid":"469002115","full_name":"chjj/lcdb","owner":"chjj","description":"LevelDB implemented in C (unofficial -- not affiliated with Google in any way)","archived":false,"fork":false,"pushed_at":"2024-03-14T07:32:31.000Z","size":1332,"stargazers_count":98,"open_issues_count":3,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-28T08:11:56.147Z","etag":null,"topics":["c","database","leveldb","lsm"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chjj.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-12T06:38:10.000Z","updated_at":"2024-10-20T02:01:08.000Z","dependencies_parsed_at":"2024-03-14T08:47:53.019Z","dependency_job_id":null,"html_url":"https://github.com/chjj/lcdb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chjj%2Flcdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chjj%2Flcdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chjj%2Flcdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chjj%2Flcdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chjj","download_url":"https://codeload.github.com/chjj/lcdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232518870,"owners_count":18536000,"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":["c","database","leveldb","lsm"],"created_at":"2024-10-10T14:34:18.160Z","updated_at":"2025-01-04T20:58:10.488Z","avatar_url":"https://github.com/chjj.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lcdb\n\n_DISCLAIMER: lcdb has **no** affiliation with or endorsement from Google Inc.\nwhatsoever despite the API prefix being `ldb_` (let's hope they don't [cease\nand desist][cad] us again)._\n\nA state-of-the-art database in C89 (originally designed by Jeffrey Dean and\nSanjay Ghemawat and [implemented in C++][ldb]).\n\n## Background\n\n[LevelDB][ldb] was _painstakingly_ ported from C++ to C89¹ for use with [mako].\n_mako_ is a C project which requires an LSM tree for its UTXO database (which\nin turn requires high write throughput with very effective compaction). _mako_\nhas a strict development policy of \"do not link to libstdc++\" and \"do not\nrequire a c++ compiler\".\n\nLevelDB is used by many bitcoin implementations for indexing the UTXO state.\nAfter experimenting with various databases written in C, it was clear that\nLevelDB was still the obvious choice, despite it being written in C++. Existing\ndatabases written in C weren't cutting it in terms of performance (in some\ncases maybe they were, but instead lacked effective compaction).\n\n_mako_'s strict policy of portability plus the lack of a production-ready LSM\ntree written in C ultimately led to the creation of _lcdb_.\n\n1. Note that the platform (or user) must still provide a working `\u003cstdint.h\u003e`\nas a build dependency.\n\n### Portability\n\nPortability is one of _lcdb_'s primary goals. _lcdb_ is written in such a way\nthat it should be usable on Windows 9x¹ as well as unices which predate\nPOSIX.1-2001.\n\nPortability to this degree was achieved by sifting through copies of MSDN from\nthe '90s, as well as examining header files from old unix releases to see which\nsystem calls were truly² available in practice.\n\n_lcdb_ also offers the option to build without pthread support (with compaction\ntaking place on the main thread).\n\n1. Unfortunately, kernel32.dll on Windows 9x does not provide `MoveFileEx`\nwhich is necessary for atomic renames. This means _lcdb_ will be more prone to\nrecovery errors on Windows 95/98/ME.\n\n2. A good example of the incongruence between standards and implementation is\n`fdatasync(2)` and `pread(2)`. The former was standardized by POSIX.1b (1993)\nand made mandatory by SUSv2 (1997) and POSIX.1-2001. The latter was\nstandardized by SUSv2 (1997) and mandated by POSIX.1-2008. In spite of this,\nsome conforming OSes only began providing them in the last decade (in some\ncases the past 5 years or so).\n\n### Cross Compilation\n\nDue to its portability, _lcdb_ is well-suited for common cross-compilation\nenvironments like mingw and wasi-sdk.\n\nThis repo includes some helper scripts for both mingw and wasi.\n\nBuilding with mingw:\n\n``` sh\n$ ./scripts/mingw-cmake cmake . -DCMAKE_BUILD_TYPE=Release\n$ make\n```\n\nBuilding with wasi-sdk:\n\n``` sh\n$ ./scripts/wasi-cmake cmake . -DCMAKE_BUILD_TYPE=Release\n$ make\n```\n\n## More Disclaimers \u0026 License Info\n\nDespite being written in another language, _lcdb_'s codebase is largely\nderivative of LevelDB's. As such, the LevelDB license must be shipped (and\nconformed to) with the distribution of lcdb in every form.\n\n_lcdb_ is still very immature and is not yet battle-hardened like LevelDB. It\nwill also likely be subject to breaking ABI changes in the near future. Use at\nyour own risk.\n\n## Usage\n\nThe API tries to mimic the C++ API as much as it can. Users of LevelDB should\nfind it familiar.\n\nExample:\n\n``` c\n#include \u003cassert.h\u003e\n#include \u003clcdb.h\u003e\n\nint main(void) {\n  ldb_dbopt_t opt = *ldb_dbopt_default;\n  ldb_slice_t key, val, ret;\n  ldb_t *db;\n  int rc;\n\n  opt.create_if_missing = 1;\n\n  rc = ldb_open(\"tmp\", \u0026opt, \u0026db);\n\n  assert(rc == LDB_OK);\n\n  key = ldb_string(\"hello\");\n  val = ldb_string(\"world\");\n\n  rc = ldb_put(db, \u0026key, \u0026val, 0);\n\n  assert(rc == LDB_OK);\n\n  rc = ldb_get(db, \u0026key, \u0026ret, 0);\n\n  assert(rc == LDB_OK);\n  assert(ldb_compare(db, \u0026ret, \u0026val) == 0);\n\n  ldb_free(ret.data);\n  ldb_close(db);\n\n  return 0;\n}\n```\n\nBuild with:\n\n``` sh\n$ cc -o example example.c -llcdb\n```\n\nOr:\n\n``` sh\n$ cc -o example -I./include example.c liblcdb.a -lpthread\n```\n\nSee the [header file][h] for more information.\n\n## Contribution and License Agreement\n\nIf you contribute code to this project, you are implicitly allowing your code\nto be distributed under the MIT license. You are also implicitly verifying that\nall code is your original work. `\u003c/legalese\u003e`\n\n## License\n\n- Copyright (c) 2022, Christopher Jeffrey (MIT License).\n\nParts of this software are based on [google/leveldb][ldb]:\n\n- Copyright (c) 2011, The LevelDB Authors. All rights reserved.\n\nParts of this software are based on [google/crc32c][crc32c]:\n\n- Copyright (c) 2017, The CRC32C Authors.\n\nParts of this software are based on [golang/snappy][snappy]:\n\n- Copyright (c) 2011 The Snappy-Go Authors. All rights reserved.\n\nSee [LICENSE] for more info.\n\n[cad]: https://github.com/Level/community/issues/66\n[ldb]: https://github.com/google/leveldb\n[h]: https://github.com/chjj/lcdb/blob/master/include/lcdb.h\n[crc32c]: https://github.com/google/crc32c\n[snappy]: https://github.com/golang/snappy\n[mako]: https://github.com/chjj/mako\n[LICENSE]: https://github.com/chjj/lcdb/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchjj%2Flcdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchjj%2Flcdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchjj%2Flcdb/lists"}