{"id":18410654,"url":"https://github.com/vfk/swift-lmdb","last_synced_at":"2025-04-12T22:46:34.212Z","repository":{"id":77516510,"uuid":"237632036","full_name":"VFK/swift-lmdb","owner":"VFK","description":"A Swift wrapper for LMDB - Lightning Memory-Mapped Database","archived":false,"fork":false,"pushed_at":"2021-02-28T20:39:51.000Z","size":33,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-24T15:18:13.765Z","etag":null,"topics":["database","key-value","lmdb","spm","swift","wrapper"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VFK.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-02-01T15:08:34.000Z","updated_at":"2023-08-25T09:37:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d9610d4-a420-4d64-b6d2-5ca72708fe70","html_url":"https://github.com/VFK/swift-lmdb","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VFK%2Fswift-lmdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VFK%2Fswift-lmdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VFK%2Fswift-lmdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VFK%2Fswift-lmdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VFK","download_url":"https://codeload.github.com/VFK/swift-lmdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239092738,"owners_count":19580214,"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","key-value","lmdb","spm","swift","wrapper"],"created_at":"2024-11-06T03:33:13.922Z","updated_at":"2025-02-16T05:28:30.589Z","avatar_url":"https://github.com/VFK.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftLMDB [![SPM Version](https://img.shields.io/github/tag/VFK/swift-lmdb.svg?color=success\u0026label=SPM)](https://swift.org/package-manager/)\nA wrapper for [LMDB](https://symas.com/lmdb/) written in Swift for [Package Manager](https://swift.org/package-manager/).\n\nWorks on all platforms supported by Swift.\n\n## Usage\nSwiftLMDB works with [Data](https://developer.apple.com/documentation/foundation/data) types for keys and values.\nLet's say you have the following data:\n```swift\nlet key = \"master-key\".data(using: .utf8)!\nlet value = \"master-value\".data(using: .utf8)!\n```\nYou'll also need [filesystem url](https://developer.apple.com/documentation/foundation/nsurl/1417505-init) to a file or a directory like:\n```swift\nlet url = URL(fileURLWithPath: \"/usr/local/some-database\", isDirectory: true)\n```\n\nYou can use it like this:\n```swift\nimport LMDB\n\nlet lmdb = try LMDB(url: url)\ntry lmdb.beginTransaction { database in\n    try database.put(value: value, forKey: key)\n    \n    let dbValue = try database.get(key: key)\n    \n    try database.del(key: key)\n}\n```\n\nCursors are also supported:\n```swift\nimport LMDB\n\nlet lmdb = try LMDB(url: url)\ntry lmdb.beginTransactionWithCursor { database, cursor in\n    try cursor.put(value: value, forKey: key)\n    \n    let dbValue = try cursor.get(.first)\n    \n    try cursor.del()\n}\n```\n\n* This library abstracts many things. You don't need to create environment, open a database and start/commit/abort transactions, this is all done for you.\n* You don't need to create intermediate directories in your path, those will be created if needed.\n* Successful transaction commits automatically and if something throws inside `beginTransaction` block - transaction aborts.\n* Some lmdb flags are set automatically: if url points to a file - `MDB_NOSUBDIR` will be set on environment. If you pass `isReadOnly` to SwiftLMDB constructor - `MDB_RDONLY` flag will be added etc.\n\nFor named databases use `beginTransaction(name: String?, flags: DatabaseFlags?)` but also make sure to `setMaxDbs` to something \u003e0 _before_ this call like:\n```swift\nlet lmdb = try LMDB(url: url)\n\ntry lmdb.configureEnvironment { configuration in\n    configuration.setMaxDbs(1)\n}\n\ntry lmdb.beginTransaction(name: \"my-database\") { database in\n    ...\n}\n```\n\n### Additionally direct mappings to lmdb methods are also provided\nYou can [follow official guide](http://www.lmdb.tech/doc/starting.html) and do things the way you'd them with the original lmdb library:\n```swift\nlet url = URL(fileURLWithPath: \"/usr/local/some-database\", isDirectory: true)\nlet key = \"master-key\".data(using: .utf8)!\nlet value = \"master-value\".data(using: .utf8)!\n\nlet environment = try Environment(url: url, isReadOnly: false)\nlet transaction = Transaction(environment: environment, isReadOnly: false)\nlet database = Database(transaction: transaction)\n\ntry environment.configure { (configiration) in \n    try configuration.setMaxDbs(10)\n    try configuration.setFlags([.noSync, .noTls])\n}\n\ntry environment.open()\ntry database.open(name: \"some-database\", flags: [.dupSort])\n\ntry transaction.begin()\ntry database.put(value: value, forKey: key, flags: [.noDupData])\ntry transaction.commit()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvfk%2Fswift-lmdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvfk%2Fswift-lmdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvfk%2Fswift-lmdb/lists"}