Skip to content

Commit c3cc108

Browse files
committed
Move SQLRow to a separate file
1 parent b831eeb commit c3cc108

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

Sources/SwiftSQL/SQLRow.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2020 Alexander Grebenyuk (github.com/kean).
4+
5+
import Foundation
6+
import SQLite3
7+
8+
/// Represents a single row returned by the SQL statement.
9+
public struct SQLRow {
10+
let statement: SQLStatement // Storing as strong reference doesn't seem to affect performance
11+
var ref: OpaquePointer { statement.ref }
12+
13+
#warning("TODO: document")
14+
public subscript<T: SQLDataType>(index: Int) -> T {
15+
T.sqlColumn(statement: ref, index: Int32(index))
16+
}
17+
18+
public subscript<T: SQLDataType>(index: Int) -> T? {
19+
if sqlite3_column_type(ref, Int32(index)) == SQLITE_NULL {
20+
return nil
21+
} else {
22+
return T.sqlColumn(statement: ref, index: Int32(index))
23+
}
24+
}
25+
26+
public subscript<T: SQLDataType>(name: String) -> T {
27+
fatalError()
28+
}
29+
30+
public subscript<T: SQLDataType>(name: String) -> T? {
31+
fatalError()
32+
}
33+
}

Sources/SwiftSQL/SQLStatement.swift

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -221,31 +221,3 @@ public final class SQLStatement {
221221
throw error
222222
}
223223
}
224-
225-
#warning("TODO: is retaining statement fine in terms of performance?")
226-
public struct SQLRow {
227-
let statement: SQLStatement // Storing as strong reference doesn't seem to affect performance
228-
var ref: OpaquePointer { statement.ref }
229-
230-
#warning("TODO: document")
231-
#warning("TODO: add null checks")
232-
public subscript<T: SQLDataType>(index: Int) -> T {
233-
T.sqlColumn(statement: ref, index: Int32(index))
234-
}
235-
236-
public subscript<T: SQLDataType>(index: Int) -> T? {
237-
if sqlite3_column_type(ref, Int32(index)) == SQLITE_NULL {
238-
return nil
239-
} else {
240-
return T.sqlColumn(statement: ref, index: Int32(index))
241-
}
242-
}
243-
244-
public subscript<T: SQLDataType>(name: String) -> T {
245-
fatalError()
246-
}
247-
248-
public subscript<T: SQLDataType>(name: String) -> T? {
249-
fatalError()
250-
}
251-
}

0 commit comments

Comments
 (0)