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
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
fdb-version:
- "7.3.43"
swift-version:
- "6.1"

name: FDB/Swift Bindings - ${{ matrix.fdb-version }} (Swift ${{ matrix.swift-version }})

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install FoundationDB ${{ matrix.fdb-version }}
run: |
# Download and install FoundationDB
FDB_VERSION="${{ matrix.fdb-version }}"
wget https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-clients_${FDB_VERSION}-1_amd64.deb
wget https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-server_${FDB_VERSION}-1_amd64.deb
sudo dpkg -i foundationdb-clients_${FDB_VERSION}-1_amd64.deb foundationdb-server_${FDB_VERSION}-1_amd64.deb

# Wait for FoundationDB to be ready
sleep 5
fdbcli --exec status --timeout 10

- name: Setup Swift ${{ matrix.swift-version }}
run: |
# Download and install Swift
SWIFT_VERSION="${{ matrix.swift-version }}"
SWIFT_URL="https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2204/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04.tar.gz"

wget $SWIFT_URL
tar xzf swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04.tar.gz
sudo mv swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04 /usr/share/swift

echo "/usr/share/swift/usr/bin" >> $GITHUB_PATH

- name: Build Bindings
run: swift build

- name: Run Unit Tests
run: swift test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ try await database.withTransaction { transaction in

## Requirements

- Swift 6.0+
- Swift 6.1+
- FoundationDB 7.1+
- macOS 12+ / Linux

Expand Down
12 changes: 6 additions & 6 deletions Sources/FoundationDB/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,30 @@ public final class FDBClient: Sendable {
/// Sets a network option with an optional byte array value.
///
/// - Parameters:
/// - option: The network option to set.
/// - value: Optional byte array value for the option.
/// - option: The network option to set.
/// - Throws: `FDBError` if the option cannot be set.
public static func setNetworkOption(_ option: FDB.NetworkOption, value: [UInt8]? = nil) throws {
public static func setNetworkOption(to value: [UInt8]? = nil, forOption option: FDB.NetworkOption) throws {
try FDBNetwork.shared.setNetworkOption(to: value, forOption: option)
}

/// Sets a network option with a string value.
///
/// - Parameters:
/// - option: The network option to set.
/// - value: String value for the option.
/// - option: The network option to set.
/// - Throws: `FDBError` if the option cannot be set.
public static func setNetworkOption(_ option: FDB.NetworkOption, value: String) throws {
public static func setNetworkOption(to value: String, forOption option: FDB.NetworkOption) throws {
try FDBNetwork.shared.setNetworkOption(to: value, forOption: option)
}

/// Sets a network option with an integer value.
///
/// - Parameters:
/// - option: The network option to set.
/// - value: Integer value for the option.
/// - option: The network option to set.
/// - Throws: `FDBError` if the option cannot be set.
public static func setNetworkOption(_ option: FDB.NetworkOption, value: Int) throws {
public static func setNetworkOption(to value: Int, forOption option: FDB.NetworkOption) throws {
try FDBNetwork.shared.setNetworkOption(to: value, forOption: option)
}
}
16 changes: 8 additions & 8 deletions Sources/FoundationDB/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public final class FDBDatabase: DatabaseProtocol {
/// Sets a database option with a byte array value.
///
/// - Parameters:
/// - option: The database option to set.
/// - value: The value for the option (optional).
/// - option: The database option to set.
/// - Throws: `FDBError` if the option cannot be set.
public func setOption(_ option: FDB.DatabaseOption, value: FDB.Value? = nil) throws {
public func setOption(to value: FDB.Value? = nil, forOption option: FDB.DatabaseOption) throws {
let error: Int32
if let value = value {
error = value.withUnsafeBytes { bytes in
Expand All @@ -96,23 +96,23 @@ public final class FDBDatabase: DatabaseProtocol {
/// Sets a database option with a string value.
///
/// - Parameters:
/// - option: The database option to set.
/// - value: The string value for the option.
/// - option: The database option to set.
/// - Throws: `FDBError` if the option cannot be set.
public func setOption(_ option: FDB.DatabaseOption, value: String) throws {
try setOption(option, value: Array(value.utf8))
public func setOption(to value: String, forOption option: FDB.DatabaseOption) throws {
try setOption(to: Array(value.utf8), forOption: option)
}

/// Sets a database option with an integer value.
///
/// - Parameters:
/// - option: The database option to set.
/// - value: The integer value for the option.
/// - option: The database option to set.
/// - Throws: `FDBError` if the option cannot be set.
public func setOption(_ option: FDB.DatabaseOption, value: Int) throws {
public func setOption(to value: Int, forOption option: FDB.DatabaseOption) throws {
var val = Int64(value).littleEndian
try withUnsafeBytes(of: &val) { bytes in
try setOption(option, value: Array(bytes))
try setOption(to: Array(bytes), forOption: option)
}
}
}
24 changes: 12 additions & 12 deletions Sources/FoundationDB/FoundationdDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,26 +252,26 @@ public protocol TransactionProtocol: Sendable {
/// Sets a transaction option with an optional value.
///
/// - Parameters:
/// - option: The transaction option to set.
/// - value: Optional byte array value for the option.
/// - option: The transaction option to set.
/// - Throws: `FDBError` if the option cannot be set.
func setOption(_ option: FDB.TransactionOption, value: FDB.Value?) throws
func setOption(to value: FDB.Value?, forOption option: FDB.TransactionOption) throws

/// Sets a transaction option with a string value.
///
/// - Parameters:
/// - option: The transaction option to set.
/// - value: String value for the option.
/// - option: The transaction option to set.
/// - Throws: `FDBError` if the option cannot be set.
func setOption(_ option: FDB.TransactionOption, value: String) throws
func setOption(to value: String, forOption option: FDB.TransactionOption) throws

/// Sets a transaction option with an integer value.
///
/// - Parameters:
/// - option: The transaction option to set.
/// - value: Integer value for the option.
/// - option: The transaction option to set.
/// - Throws: `FDBError` if the option cannot be set.
func setOption(_ option: FDB.TransactionOption, value: Int) throws
func setOption(to value: Int, forOption option: FDB.TransactionOption) throws
}

/// Default implementation of transaction retry logic for `DatabaseProtocol`.
Expand Down Expand Up @@ -394,17 +394,17 @@ extension TransactionProtocol {
try await getRange(beginKey: beginKey, endKey: endKey, limit: limit, snapshot: snapshot)
}

public func setOption(_ option: FDB.TransactionOption) throws {
try setOption(option, value: nil)
public func setOption(forOption option: FDB.TransactionOption) throws {
try setOption(to: nil, forOption: option)
}

public func setOption(_ option: FDB.TransactionOption, value: String) throws {
public func setOption(to value: String, forOption option: FDB.TransactionOption) throws {
let valueBytes = [UInt8](value.utf8)
try setOption(option, value: valueBytes)
try setOption(to: valueBytes, forOption: option)
}

public func setOption(_ option: FDB.TransactionOption, value: Int) throws {
public func setOption(to value: Int, forOption option: FDB.TransactionOption) throws {
let valueBytes = withUnsafeBytes(of: Int64(value)) { [UInt8]($0) }
try setOption(option, value: valueBytes)
try setOption(to: valueBytes, forOption: option)
}
}
2 changes: 1 addition & 1 deletion Sources/FoundationDB/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public final class FDBTransaction: TransactionProtocol, @unchecked Sendable {
}
}

public func setOption(_ option: FDB.TransactionOption, value: FDB.Value?) throws {
public func setOption(to value: FDB.Value?, forOption option: FDB.TransactionOption) throws {
let error: Int32
if let value = value {
error = value.withUnsafeBytes { bytes in
Expand Down
10 changes: 5 additions & 5 deletions Tests/FoundationDBTests/FoundationDBTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ func transactionTimeoutOption() async throws {
let newTransaction = try database.createTransaction()

// Set a very short timeout (1ms) to test timeout functionality
try newTransaction.setTimeout(1)
try newTransaction.setOption(to: 1, forOption: .timeout)

// This should timeout very quickly
do {
Expand Down Expand Up @@ -1293,7 +1293,7 @@ func transactionSizeLimitOption() async throws {
let newTransaction = try database.createTransaction()

// Set a very small size limit (100 bytes)
try newTransaction.setSizeLimit(100)
try newTransaction.setOption(to: 100, forOption: .sizeLimit)

// Try to write more data than the limit allows
let largeValue = String(repeating: "x", count: 200)
Expand All @@ -1314,9 +1314,9 @@ func transactionOptionConvenienceMethods() throws {
// Note: These tests verify the API exists but don't actually set options

// Test timeout and retry methods
// transaction.setTimeout(30000) - would set timeout
// transaction.setRetryLimit(10) - would set retry limit
// transaction.setMaxRetryDelay(5000) - would set max retry delay
// transaction.setOption(to: 30000, forOption: .timeout) - would set timeout
// transaction.setOption(to: 10, forOption: .retryLimit) - would set retry limit
// transaction.setOption(to: 5000, forOption: .maxRetryDelay) - would set max retry delay
// transaction.setSizeLimit(1000000) - would set size limit

// Test idempotency methods
Expand Down
2 changes: 1 addition & 1 deletion Tests/StackTester/Sources/StackTester/StackTester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ class StackMachine {
case "DISABLE_WRITE_CONFLICT":
// Not directly available in Swift bindings, could use transaction option
let transaction = try currentTransaction()
try transaction.setOption(.nextWriteNoWriteConflictRange, value: nil)
try transaction.setOption(to: nil, forOption: .nextWriteNoWriteConflictRange)

case "TUPLE_PACK":
let numElements = waitAndPop().item as! Int64
Expand Down