-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLiteConnection.swift
More file actions
48 lines (45 loc) · 1.37 KB
/
SQLiteConnection.swift
File metadata and controls
48 lines (45 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// SQLiteConnection.swift
// feather-sqlite-database
//
// Created by Tibor Bödecs on 2026. 01. 10..
//
import FeatherDatabase
import SQLiteNIO
extension SQLiteConnection: @retroactive DatabaseConnection {
/// Execute a SQLite query on this connection.
///
/// This wraps `SQLiteNIO` query execution and maps errors.
/// - Parameter query: The SQLite query to execute.
/// - Throws: A `DatabaseError` if the query fails.
/// - Returns: A query result containing the returned rows.
@discardableResult
public func execute(
query: SQLiteQuery
) async throws(DatabaseError) -> SQLiteQueryResult {
let maxAttempts = 8
var attempt = 0
while true {
do {
let result = try await self.query(
query.sql,
query.bindings
)
return SQLiteQueryResult(elements: result)
}
catch {
attempt += 1
if attempt >= maxAttempts {
throw .query(error)
}
let delayMilliseconds = min(1000, 25 << (attempt - 1))
do {
try await Task.sleep(for: .milliseconds(delayMilliseconds))
}
catch {
throw .query(error)
}
}
}
}
}