This is a fork of agisboye/SwiftLMDB but the functionality has been altered to better suit its purpose in an internal project.
- Small and lightweight
- Fast
- Unit tested
- Xcode documentation
- Cross platform (tests passing on macOS and Linux)
- iOS 11.0+, macOS 10.11+ or Linux
- Swift 4.1
// swift-tools-version:4.0
import PackageDescription
let package = Package(
...
dependencies: [
.package(url: "https://github.com/jernejstrasner/SwiftLMDB.git", .branch("master"))
],
...
)
Start by importing the module.
import SwiftLMDB
Databases are contained within an environment. An environment may contain multiple databases, each identified by their name.
let environment: Environment
let database: Database
do {
// The folder in which the environment is opened must already exist.
try FileManager.default.createDirectory(at: envURL, withIntermediateDirectories: true, attributes: nil)
environment = try Environment(path: envURL.path, flags: [], maxDBs: 32)
database = try environment.openDatabase(named: "db1", flags: [.create])
} catch {
print(error)
}
do {
let val = "Hello World!".data(using: .utf8)
ley key = "key1".data(using: .utf8)
try database.put(value: val, forKey: key)
} catch {
print(error)
}
do {
ley key = "key1".data(using: .utf8)
if let value = try database.get(forKey: key) {
// Data
}
} catch {
print(error)
}
do {
ley key = "key1".data(using: .utf8)
try database.deleteValue(forKey: key)
} catch {
print(error)
}
Contributions are very welcome. Open an issue or submit a pull request.
SwiftLMDB is available under the MIT license. See the LICENSE file for more info. LMDB is licensen under the OpenLDAP Public License.