From bb389f317e664a16b10722f072ab9bd05caeba9e Mon Sep 17 00:00:00 2001 From: Vishesh Yadav Date: Fri, 24 Oct 2025 10:35:32 -0700 Subject: [PATCH 1/2] Make protocols public The methods implemented by protocols are not public otherwise. --- Sources/FoundationDB/FoundationdDB.swift | 4 ++-- Sources/FoundationDB/Transaction.swift | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/FoundationDB/FoundationdDB.swift b/Sources/FoundationDB/FoundationdDB.swift index e259446..18d7e13 100644 --- a/Sources/FoundationDB/FoundationdDB.swift +++ b/Sources/FoundationDB/FoundationdDB.swift @@ -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. @@ -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: diff --git a/Sources/FoundationDB/Transaction.swift b/Sources/FoundationDB/Transaction.swift index 2e8315c..c77f43f 100644 --- a/Sources/FoundationDB/Transaction.swift +++ b/Sources/FoundationDB/Transaction.swift @@ -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 @@ -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 From 656f758ee4139b58fbc6e2c9be68e3aaccf6a92a Mon Sep 17 00:00:00 2001 From: Vishesh Yadav Date: Fri, 24 Oct 2025 10:36:11 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 14347f1..3660841 100644 --- a/README.md +++ b/README.md @@ -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)) } ``` @@ -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 } ``` @@ -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) } ```