@@ -20,15 +20,17 @@ let database = try FDBClient.openDatabase()
2020// Simple key-value operations
2121try await database.withTransaction { transaction in
2222 // Set a value
23- transaction.setValue (" world" , for : " hello" )
24-
23+ let key = " hello"
24+ let value = " world"
25+ transaction.setValue ([UInt8 ](value.utf8 ), for : [UInt8 ](key.utf8 ))
26+
2527 // Get a value
26- if let value = try await transaction.getValue (for : " hello " ) {
27- print (String (bytes : value )) // "world"
28+ if let valueBytes = try await transaction.getValue (for : [ UInt8 ](key. utf8 ) ) {
29+ print (String (decoding : valueBytes, as : UTF8 . self )) // "world"
2830 }
29-
31+
3032 // Delete a key
31- transaction.clear (key : " hello " )
33+ transaction.clear (key : [ UInt8 ](key. utf8 ) )
3234}
3335```
3436
@@ -37,13 +39,13 @@ try await database.withTransaction { transaction in
3739``` swift
3840// Efficient streaming over large result sets
3941let sequence = transaction.getRange (
40- beginSelector : .firstGreaterOrEqual (" user:" ),
41- endSelector : .firstGreaterOrEqual (" user;" )
42+ beginSelector : .firstGreaterOrEqual ([ UInt8 ]( " user:" . utf8 ) ),
43+ endSelector : .firstGreaterOrEqual ([ UInt8 ]( " user;" . utf8 ) )
4244)
4345
4446for try await (key, value) in sequence {
45- let userId = String (bytes : key)
46- let userData = String (bytes : value)
47+ let userId = String (decoding : key, as : UTF8 . self )
48+ let userData = String (decoding : value, as : UTF8 . self )
4749 // Process each key-value pair as it streams
4850}
4951```
@@ -55,7 +57,7 @@ try await database.withTransaction { transaction in
5557 // Atomic increment
5658 let counterKey = " counter"
5759 let increment = withUnsafeBytes (of : Int64 (1 ).littleEndian ) { Array ($0 ) }
58- transaction.atomicOp (key : counterKey, param : increment, mutationType : .add )
60+ transaction.atomicOp (key : [ UInt8 ]( counterKey. utf8 ) , param : increment, mutationType : .add )
5961}
6062```
6163
0 commit comments