https://github.com/aisk/swift-cdb
Simple constant db in swift
https://github.com/aisk/swift-cdb
Last synced: 24 days ago
JSON representation
Simple constant db in swift
- Host: GitHub
- URL: https://github.com/aisk/swift-cdb
- Owner: aisk
- Created: 2024-07-28T13:53:49.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-29T14:57:53.000Z (almost 2 years ago)
- Last Synced: 2025-01-28T12:23:00.948Z (over 1 year ago)
- Language: C
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# swift-cdb
A Swift wrapper for the CDB (Constant Database) implementation from [howerj/cdb](https://github.com/howerj/cdb), providing a native Swift interface for creating and querying constant key-value databases.
## Installation
Add this package to your Swift project dependencies:
```swift
// In your Package.swift
dependencies: [
.package(url: "https://github.com/aisk/swift-cdb.git", from: "0.1.0"),
]
```
## Usage
```swift
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)")
}
```
## API Reference
### Main Methods
- `init(filename: String, mode: Mode) throws` - Open a CDB file
- `add(key: String, value: String) throws` - Add a string value
- `add(key: String, value: Data) throws` - Add binary data
- `get(key: String, at index: UInt64 = 0) throws -> String?` - Get string value
- `get(key: String, at index: UInt64 = 0) throws -> Data?` - Get binary data
- `count(key: String) throws -> UInt64` - Count values for a key
- `close() throws` - Close the database
- `subscript(key: String) -> String?` - Dictionary-like access
### Modes
- `.read` - Open for reading only
- `.write` - Open for writing (creates new database)
## License
This project is licensed under the same terms as the original [CDB library](https://github.com/howerj/cdb).