A Swift wrapper for the CDB (Constant Database) implementation from howerj/cdb, providing a native Swift interface for creating and querying constant key-value databases.
Add this package to your Swift project dependencies:
// In your Package.swift
dependencies: [
.package(url: "https://github.com/your-username/swift-cdb.git", from: "1.0.0"),
]
import CDB
// Open a CDB file and read values
do {
let db = try CDB(filename: "example.cdb", mode: .read)
// Read string value
let value: String? = try db.get(key: "some_key")
print("Value: \(value ?? "not found")")
try db.close()
} catch {
print("Error: \(error)")
}
init(filename: String, mode: Mode) throws
- Open a CDB fileadd(key: String, value: String) throws
- Add a string valueadd(key: String, value: Data) throws
- Add binary dataget(key: String, at index: UInt64 = 0) throws -> String?
- Get string valueget(key: String, at index: UInt64 = 0) throws -> Data?
- Get binary datacount(key: String) throws -> UInt64
- Count values for a keyclose() throws
- Close the databasesubscript(key: String) -> String?
- Dictionary-like access
.read
- Open for reading only.write
- Open for writing (creates new database)
This project is licensed under the same terms as the original CDB library.