{"id":16189382,"url":"https://github.com/caolan/chicken-level","last_synced_at":"2026-01-20T00:35:41.192Z","repository":{"id":18737539,"uuid":"21949214","full_name":"caolan/chicken-level","owner":"caolan","description":"abstract API layer for chicken-leveldb","archived":false,"fork":false,"pushed_at":"2016-07-05T07:39:10.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-13T16:46:27.913Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scheme","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caolan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-17T16:25:54.000Z","updated_at":"2016-02-06T15:11:20.000Z","dependencies_parsed_at":"2022-07-22T18:51:00.959Z","dependency_job_id":null,"html_url":"https://github.com/caolan/chicken-level","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fchicken-level","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fchicken-level/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fchicken-level/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fchicken-level/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caolan","download_url":"https://codeload.github.com/caolan/chicken-level/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247666005,"owners_count":20975787,"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-10-10T07:35:17.004Z","updated_at":"2026-01-20T00:35:41.137Z","avatar_url":"https://github.com/caolan.png","language":"Scheme","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chicken-level\n\nProvides a high-level API to leveldb implementations. Use in combination\nwith an implementation egg (eg, [leveldb][1]).\n\n## Interface API\n\nThis module exposes an interface, which other eggs provide implementations\nof. The API described below is what the interface provides.\n\n### Basic read and write\n\n```scheme\n(db-get db key)\n```\n\nReturns the value of `key` in `db` as a string. Causes an exception if the\nkey does not exist.\n\n```scheme\n(db-get/default db key default)\n```\n\nSame as db-get but returns default instead of causing an exception if the\nkey is missing.\n\n```scheme\n(db-put db key value #!key (sync #f))\n```\n\nStores `value` under `key` in datbase `db`. If the sync option can be set to\n`#t` to make the write operation not return until the data being written has\nbeen pushed all the way to persistent storage. See the *Synchronous Writes*\nsection for more information.\n\n```scheme\n(db-delete db key #!key (sync #f))\n```\n\nRemoves the value associated with `key` from `db`. If the sync option can be\nset to `#t` to make the write operation not return until the data being\nwritten has been pushed all the way to persistent storage. See the\n*Synchronous Writes* section for more information.\n\n### Atomic updates (batches)\n\n```scheme\n(db-batch db ops #!key (sync #f))\n```\n\nWhen making multiple changes that rely on each other you can apply a batch\nof operations atomically using `db-batch`. The `ops` argument is a list of\noperations which will be applied **in order** (meaning you can create then\nlater delete a value in the same batch, for example).\n\n```scheme\n(define myops '((put \"abc\" \"123\")\n                (put \"def\" \"456\")\n                (delete \"abc\")))\n\n;; apply all operations in myops\n(db-batch db myops)\n```\n\nThe first item in an operation should be the symbol `put` or `delete`, any\nother value will give an error. The next item is the key and in the case of\n`put` the third item is the value.\n\nApart from its atomicity benefits, `db-batch` may also be used to speed up\nbulk updates by placing lots of individual mutations into the same batch.\n\n### Range queries (streams)\n\n```scheme\n(db-stream db #!key start end limit reverse (key #t) (value #t) fillcache)\n```\n\nAllows forward and backward iteration over the keys in alphabetical order.\nReturns a lazy sequence of all key/value pairs from `start` to `end`\n(up to `limit`). This uses the [lazy-seq][2] egg.\n\n* __start__ - the key to start from (need not actually exist), if omitted\n  starts from the first key in the database\n* __end__ - the key to end on (need not actually exist), if omitted ends on\n  the last key in the database\n* __limit__ - stops after `limit` results have been returned\n* __reverse__ - iterates backwards through the keys (reverse\n  iteration may be somewhat slower than forward iteration)\n* __key__ - whether to return the key for each result (default #t)\n* __value__ - whether to return the value for each result (default #t)\n* __fillcache__ - whether to fill leveldb's read cache when reading (turned\n  off by default so the bulk read does not replace most of the cached\n  contents)\n\nWhen both `key: #t` and `value: #t` (as default) values are returned as a\nlist with two items, the `car` being the key and the `cadr` being the\nvalue. When only `key: #t` or `value: #t` the keys or values are not\nreturned as a list but as a string representing the single key or value.\n\n```scheme\n(lazy-map display (db-stream db start: \"foo:\" end: \"foo::\" limit: 10)))\n```\n\nYou can turn the lazy-seq into a list using `lazy-seq-\u003elist`, just be\nwarned that it will evaluate the entire key range and should be avoided\nunless you know the number of values is small (eg, when using `limit`).\n\n```scheme\n(db-batch db '((put \"foo\" \"1\")\n               (put \"bar\" \"2\")\n               (put \"baz\" \"3\")))\n\n(lazy-seq-\u003elist (db-stream db limit: 2)) ;; =\u003e ((\"foo\" \"1\") (\"bar\" \"2\"))\n(lazy-seq-\u003elist (db-stream db key: #f value: #t)) ;; =\u003e (\"1\" \"2\" \"3\")\n(lazy-seq-\u003elist (db-stream db key: #t value: #f)) ;; =\u003e (\"foo\" \"bar\" \"baz\")\n```\n\n### Synchronous Writes\n\n**Note:** this information is mostly copied from the [LevelDB docs][3]\n\nBy default, each write to leveldb is asynchronous: it returns after pushing\nthe write from the process into the operating system. The transfer from\noperating system memory to the underlying persistent storage happens\nasynchronously. The sync flag can be turned on for a particular write to\nmake the write operation not return until the data being written has been\npushed all the way to persistent storage. (On Posix systems, this is\nimplemented by calling either fsync(...) or fdatasync(...) or msync(...,\nMS\\_SYNC) before the write operation returns.)\n\nAsynchronous writes are often more than a thousand times as fast as\nsynchronous writes. The downside of asynchronous writes is that a\ncrash of the machine may cause the last few updates to be lost. Note\nthat a crash of just the writing process (i.e., not a reboot) will\nnot cause any loss since even when sync is false, an update is pushed\nfrom the process memory into the operating system before it is\nconsidered done.\n\n`db-batch` provides an alternative to asynchronous writes. Multiple\nupdates may be placed in the same batch and applied together\nusing a `sync: #t`. The extra cost of the synchronous write will be\namortized across all of the writes in the batch.\n\n\n## Creating an interface\n\nIf you want to provide your own storage impelmentation, import this egg\nand define the interface as follows:\n\n```scheme\n(use level)\n\n(define myleveldb\n  (implementation level-api\n\n    (define (level-get db key) ...)\n    (define (level-get/default db key default) ...)\n    (define (level-put db key value #!key (sync #f)) ...)\n    (define (level-delete db key #!key (sync #f)) ...)\n    (define (level-batch db ops #!key (sync #f)) ...)\n\n    (define (level-stream db\n                          #!key\n                          start\n                          end\n                          limit\n                          reverse\n                          (key #t)\n                          (value #t)\n                          fillcache)\n      ..)))\n```\n\n## Implementations\n\n- [leveldb](https://github.com/caolan/chicken-leveldb) - provides the `level`\n  API to libleveldb\n- [sublevel](https://github.com/caolan/chicken-sublevel) - provides namespaced\n  API access to another implementation\n\n[1]: https://github.com/caolan/chicken-leveldb\n[2]: http://wiki.call-cc.org/eggref/4/lazy-seq\n[3]: http://leveldb.googlecode.com/svn/trunk/doc/index.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaolan%2Fchicken-level","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaolan%2Fchicken-level","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaolan%2Fchicken-level/lists"}