{"id":15940974,"url":"https://github.com/fjvallarino/libmdbx-hs","last_synced_at":"2025-06-25T02:35:25.914Z","repository":{"id":44951845,"uuid":"349238391","full_name":"fjvallarino/libmdbx-hs","owner":"fjvallarino","description":"Haskell bindings for libmdbx","archived":false,"fork":false,"pushed_at":"2025-02-08T21:31:59.000Z","size":751,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-22T14:42:11.566Z","etag":null,"topics":["database","haskell","in-process","key-value-store"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fjvallarino.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}},"created_at":"2021-03-18T22:52:07.000Z","updated_at":"2025-06-06T13:01:02.000Z","dependencies_parsed_at":"2022-09-17T21:44:46.701Z","dependency_job_id":null,"html_url":"https://github.com/fjvallarino/libmdbx-hs","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/fjvallarino/libmdbx-hs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjvallarino%2Flibmdbx-hs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjvallarino%2Flibmdbx-hs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjvallarino%2Flibmdbx-hs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjvallarino%2Flibmdbx-hs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fjvallarino","download_url":"https://codeload.github.com/fjvallarino/libmdbx-hs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjvallarino%2Flibmdbx-hs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261791705,"owners_count":23210183,"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":["database","haskell","in-process","key-value-store"],"created_at":"2024-10-07T07:01:52.052Z","updated_at":"2025-06-25T02:35:25.904Z","avatar_url":"https://github.com/fjvallarino.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libmdbx-hs\n\nA [libmdbx](https://gitflic.ru/project/erthink/libmdbx) wrapper, providing low level\naccess to its API plus a set of high level functions for common operations.\n\nExcerpt from libmdbx's [documentation](https://gitflic.ru/project/erthink/libmdbx):\n\n_**libmdbx** is an extremely fast, compact, powerful, embedded, transactional [key-value database](https://en.wikipedia.org/wiki/Key-value_database), with [Apache 2.0 license](https://gitflic.ru/project/erthink/libmdbx/blob?file=LICENSE)._\n\n_Historically, **libmdbx** is a deeply revised and extended descendant of the amazing [Lightning Memory-Mapped Database](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database). **libmdbx** inherits all benefits from **LMDB**, but resolves some issues and adds [a set of improvements](#improvements-beyond-lmdb)_.\n\n## Usage\n\n### Low level interface\n\nUsing libmdbx's low level interface involves the following steps:\n\n- Opening an environment. This is the equivalent of a database.\n- Opening a database. This is the equivalent of a table.\n- Creating a transaction.\n- Performing CRUD operations, or using a cursor.\n- Committing or aborting the transaction.\n\nSee [Hackage](https://hackage.haskell.org/package/libmdbx-hs/Mdbx-API.html) for\nthe low level interface or [libmdbx's](https://libmdbx.dqdkfa.ru/)\ndocumentation for more details on internals.\n\n### High level interface\n\nAlternatively you can use the high level interface which, although providing\na limited set of operations, takes care of transaction handling and makes the\ncommon use cases really simple.\n\n```haskell\ndata User = User {\n  _username :: !Text,\n  _password :: !Text\n} deriving (Eq, Show, Generic, Binary)\n\nderiving via (MdbxItemBinary User) instance MdbxItem User\n\nopenEnvDbi :: IO MdbxEnv\nopenEnvDbi = envOpen \"./test.db\" def [MdbxNosubdir, MdbxCoalesce, MdbxLiforeclaim, MdbxNotls]\n\nuserKey :: User -\u003e Text\nuserKey user = \"user-\" \u003c\u003e _username user\n\nmain :: IO ()\nmain = bracket openEnvDbi envClose $ \\env -\u003e do\n  db \u003c- dbiOpen env Nothing []\n\n  putItem env db (userKey user1) user1\n  putItem env db (userKey user2) user2\n\n  getItem env db (userKey user2) \u003e\u003e= print @(Maybe User)\n  getRange env db (userKey user1) (userKey user2) \u003e\u003e= print @[User]\n  where\n    user1 = User \"john\" \"secret\"\n    user2 = User \"mark\" \"password\"\n```\n\nFor the high level interface see [Hackage](https://hackage.haskell.org/package/libmdbx-hs/Mdbx-Database.html)\nor the sample application [here](app/Main.hs).\n\n### Common\n\nIn both scenarios, you will want to check [Hackage](https://hackage.haskell.org/package/libmdbx-hs/Mdbx-Types.html)\nfor information on how to make your data types compatible with libmdbx-hs.\n\nIt is recommended that your serializable data types have strict fields, to avoid\nissues related to lazy IO. The library loads data from pointers that are valid\nonly during a transaction; delaying the operation may cause an invalid read and\nconsequently a crash.\n\nWrite operations should always be performed from the same OS thread.\n\nWhen using the multi-threaded runtime, the `MdbxNotls` flag is required at\nenvironment creation. Failing to include it in the list of flags will result in\na random crash.\n\n## Dependencies\n\nSource code for libmdbx is included in the repository and built with the rest of\nthe project, to avoid requiring a separate library install.\n\n## License\n\nlibmdbx is licensed under the [Apache 2.0 License](https://gitflic.ru/project/erthink/libmdbx/blob/?file=LICENSE\u0026branch=master).\n\nlibmdbx-hs is licensed under the [BSD-3 License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffjvallarino%2Flibmdbx-hs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffjvallarino%2Flibmdbx-hs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffjvallarino%2Flibmdbx-hs/lists"}