Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ let database = try FDBClient.openDatabase()
// Simple key-value operations
try await database.withTransaction { transaction in
// Set a value
transaction.setValue("world", for: "hello")

let key = "hello"
let value = "world"
transaction.setValue([UInt8](value.utf8), for: [UInt8](key.utf8))

// Get a value
if let value = try await transaction.getValue(for: "hello") {
print(String(bytes: value)) // "world"
if let valueBytes = try await transaction.getValue(for: [UInt8](key.utf8)) {
print(String(decoding: valueBytes, as: UTF8.self)) // "world"
}

// Delete a key
transaction.clear(key: "hello")
transaction.clear(key: [UInt8](key.utf8))
}
```

Expand All @@ -37,13 +39,13 @@ try await database.withTransaction { transaction in
```swift
// Efficient streaming over large result sets
let sequence = transaction.getRange(
beginSelector: .firstGreaterOrEqual("user:"),
endSelector: .firstGreaterOrEqual("user;")
beginSelector: .firstGreaterOrEqual([UInt8]("user:".utf8)),
endSelector: .firstGreaterOrEqual([UInt8]("user;".utf8))
)

for try await (key, value) in sequence {
let userId = String(bytes: key)
let userData = String(bytes: value)
let userId = String(decoding: key, as: UTF8.self)
let userData = String(decoding: value, as: UTF8.self)
// Process each key-value pair as it streams
}
```
Expand All @@ -55,7 +57,7 @@ try await database.withTransaction { transaction in
// Atomic increment
let counterKey = "counter"
let increment = withUnsafeBytes(of: Int64(1).littleEndian) { Array($0) }
transaction.atomicOp(key: counterKey, param: increment, mutationType: .add)
transaction.atomicOp(key: [UInt8](counterKey.utf8), param: increment, mutationType: .add)
}
```

Expand Down
4 changes: 2 additions & 2 deletions Sources/FoundationDB/FoundationdDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/// and transaction retry logic. Implementations handle the underlying database
/// connection and resource management.
/// Database interface for FoundationDB operations
protocol DatabaseProtocol {
public protocol DatabaseProtocol {
associatedtype Transaction: TransactionProtocol

/// Creates a new transaction for database operations.
Expand Down Expand Up @@ -52,7 +52,7 @@ protocol DatabaseProtocol {
/// a FoundationDB transaction, including reads, writes, atomic operations,
/// and transaction management.
/// Transaction interface for FoundationDB operations
protocol TransactionProtocol: Sendable {
public protocol TransactionProtocol: Sendable {
/// Retrieves a value for the given key.
///
/// - Parameters:
Expand Down
8 changes: 4 additions & 4 deletions Sources/FoundationDB/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
}
}

func getRangeNative(
public func getRangeNative(
beginSelector: FDB.KeySelector, endSelector: FDB.KeySelector, limit: Int = 0,
snapshot: Bool
snapshot: Bool = false
) async throws -> ResultRange {
let future = beginSelector.key.withUnsafeBytes { beginKeyBytes in
endSelector.key.withUnsafeBytes { endKeyBytes in
Expand Down Expand Up @@ -262,8 +262,8 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
}


func getRangeNative(
beginKey: FDB.Bytes, endKey: FDB.Bytes, limit: Int = 0, snapshot: Bool
public func getRangeNative(
beginKey: FDB.Bytes, endKey: FDB.Bytes, limit: Int = 0, snapshot: Bool = false
) async throws -> ResultRange {
let future = beginKey.withUnsafeBytes { beginKeyBytes in
endKey.withUnsafeBytes { endKeyBytes in
Expand Down