mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Merge pull request #1037 from groue/dev/BUILD_LIBRARY_FOR_DISTRIBUTION
Support BUILD_LIBRARY_FOR_DISTRIBUTION
This commit is contained in:
28 files changed
+75
-190
No files matched your search
@@ -7,6 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
#### 5.x Releases
|
||||
|
||||
- [Development Branch](#development-branch)
|
||||
- `5.9.x` Releases - [5.9.0](#590)
|
||||
- `5.8.x` Releases - [5.8.0](#580)
|
||||
- `5.7.x` Releases - [5.7.0](#570) | [5.7.1](#571) | [5.7.2](#572) | [5.7.3](#573) | [5.7.4](#574)
|
||||
@@ -76,6 +77,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
---
|
||||
|
||||
## Development Branch
|
||||
|
||||
- **New**: [#1036](https://github.com/groue/GRDB.swift/pull/1036) by [@groue](https://github.com/groue): Restore minimal CI tests
|
||||
- **New**: [#1037](https://github.com/groue/GRDB.swift/pull/1037) by [@groue](https://github.com/groue): Support BUILD_LIBRARY_FOR_DISTRIBUTION
|
||||
|
||||
|
||||
## 5.9.0
|
||||
|
||||
Released August 15, 2021 • [diff](https://github.com/groue/GRDB.swift/compare/v5.8.0...v5.9.0)
|
||||
|
||||
@@ -19,7 +19,6 @@ extension RangeReplaceableCollection {
|
||||
/// let strings = try Array(cursor)
|
||||
///
|
||||
/// - parameter cursor: The cursor whose elements feed the collection.
|
||||
@inlinable
|
||||
public init<C: Cursor>(_ cursor: C) throws where C.Element == Element {
|
||||
self.init()
|
||||
while let element = try cursor.next() {
|
||||
@@ -36,7 +35,6 @@ extension RangeReplaceableCollection {
|
||||
/// - parameter cursor: The cursor whose elements feed the collection.
|
||||
/// - parameter minimumCapacity: Prepares the returned collection to store
|
||||
/// the specified number of elements.
|
||||
@inlinable
|
||||
public init<C: Cursor>(_ cursor: C, minimumCapacity: Int) throws where C.Element == Element {
|
||||
self.init()
|
||||
reserveCapacity(minimumCapacity)
|
||||
|
||||
@@ -6,7 +6,6 @@ public typealias SQLiteConnection = OpaquePointer
|
||||
/// A raw SQLite function argument.
|
||||
typealias SQLiteValue = OpaquePointer
|
||||
|
||||
@usableFromInline
|
||||
let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_destructor_type.self)
|
||||
|
||||
/// A Database connection.
|
||||
@@ -1597,6 +1596,7 @@ extension Database {
|
||||
}
|
||||
|
||||
/// Confirms or cancels the changes performed by a transaction or savepoint.
|
||||
@frozen
|
||||
public enum TransactionCompletion {
|
||||
/// Confirms changes
|
||||
case commit
|
||||
|
||||
@@ -13,6 +13,7 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon
|
||||
public static let null = DatabaseValue(storage: .null)
|
||||
|
||||
/// An SQLite storage (NULL, INTEGER, REAL, TEXT, BLOB).
|
||||
@frozen
|
||||
public enum Storage: Equatable {
|
||||
/// The NULL storage class.
|
||||
case null
|
||||
@@ -86,7 +87,6 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon
|
||||
|
||||
// MARK: - Not Public
|
||||
|
||||
@inlinable
|
||||
init(storage: Storage) {
|
||||
self.storage = storage
|
||||
}
|
||||
@@ -116,7 +116,6 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon
|
||||
}
|
||||
|
||||
/// Returns a DatabaseValue initialized from a raw SQLite statement pointer.
|
||||
@usableFromInline
|
||||
init(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
switch sqlite3_column_type(sqliteStatement, index) {
|
||||
case SQLITE_NULL:
|
||||
@@ -142,7 +141,6 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon
|
||||
}
|
||||
|
||||
extension DatabaseValue: StatementBinding {
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
switch storage {
|
||||
case .null:
|
||||
@@ -221,7 +219,6 @@ extension DatabaseValue {
|
||||
// DatabaseValueConvertible
|
||||
extension DatabaseValue {
|
||||
/// Returns self
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
self
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ extension DatabaseValueConvertible {
|
||||
.databaseValue(databaseValue)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
databaseValue.bind(to: sqliteStatement, at: index)
|
||||
}
|
||||
@@ -48,7 +47,6 @@ extension DatabaseValueConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
static func decode(
|
||||
fromStatement sqliteStatement: SQLiteStatement,
|
||||
atUncheckedIndex index: Int32,
|
||||
@@ -87,7 +85,6 @@ extension DatabaseValueConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
static func decodeIfPresent(
|
||||
fromStatement sqliteStatement: SQLiteStatement,
|
||||
atUncheckedIndex index: Int32,
|
||||
@@ -130,14 +127,14 @@ extension DatabaseValueConvertible {
|
||||
/// }
|
||||
/// }
|
||||
public final class DatabaseValueCursor<Value: DatabaseValueConvertible>: Cursor {
|
||||
@usableFromInline enum _State {
|
||||
private enum _State {
|
||||
case idle, busy, done, failed
|
||||
}
|
||||
|
||||
@usableFromInline let _statement: Statement
|
||||
@usableFromInline let _sqliteStatement: SQLiteStatement
|
||||
@usableFromInline let _columnIndex: Int32
|
||||
@usableFromInline var _state = _State.idle
|
||||
private let _statement: Statement
|
||||
private let _sqliteStatement: SQLiteStatement
|
||||
private let _columnIndex: Int32
|
||||
private var _state = _State.idle
|
||||
|
||||
init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws {
|
||||
_statement = statement
|
||||
@@ -163,7 +160,6 @@ public final class DatabaseValueCursor<Value: DatabaseValueConvertible>: Cursor
|
||||
try? _statement.reset()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func next() throws -> Value? {
|
||||
switch _state {
|
||||
case .done:
|
||||
@@ -211,14 +207,14 @@ public final class DatabaseValueCursor<Value: DatabaseValueConvertible>: Cursor
|
||||
/// }
|
||||
/// }
|
||||
public final class NullableDatabaseValueCursor<Value: DatabaseValueConvertible>: Cursor {
|
||||
@usableFromInline enum _State {
|
||||
private enum _State {
|
||||
case idle, busy, done, failed
|
||||
}
|
||||
|
||||
@usableFromInline let _statement: Statement
|
||||
@usableFromInline let _sqliteStatement: SQLiteStatement
|
||||
@usableFromInline let _columnIndex: Int32
|
||||
@usableFromInline var _state = _State.idle
|
||||
private let _statement: Statement
|
||||
private let _sqliteStatement: SQLiteStatement
|
||||
private let _columnIndex: Int32
|
||||
private var _state = _State.idle
|
||||
|
||||
init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws {
|
||||
_statement = statement
|
||||
@@ -244,7 +240,6 @@ public final class NullableDatabaseValueCursor<Value: DatabaseValueConvertible>:
|
||||
try? _statement.reset()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func next() throws -> Value?? {
|
||||
switch _state {
|
||||
case .done:
|
||||
|
||||
+18
-21
@@ -14,8 +14,9 @@ public final class Row: Equatable, Hashable, RandomAccessCollection,
|
||||
///
|
||||
/// let rows = try Row.fetchCursor(db, sql: "SELECT ...")
|
||||
/// let players = try Player.fetchAll(db, sql: "SELECT ...")
|
||||
@usableFromInline let statement: Statement?
|
||||
@usableFromInline let sqliteStatement: SQLiteStatement?
|
||||
let statement: Statement?
|
||||
@usableFromInline
|
||||
let sqliteStatement: SQLiteStatement?
|
||||
|
||||
/// The number of columns in the row.
|
||||
public let count: Int
|
||||
@@ -165,8 +166,8 @@ extension Row {
|
||||
// MARK: - Extracting Values
|
||||
|
||||
/// Fatal errors if index is out of bounds
|
||||
@inlinable
|
||||
func checkedIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) -> Int {
|
||||
@usableFromInline
|
||||
/* private */ func _checkedIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) -> Int {
|
||||
GRDBPrecondition(index >= 0 && index < count, "row index out of range", file: file, line: line)
|
||||
return index
|
||||
}
|
||||
@@ -203,7 +204,7 @@ extension Row {
|
||||
/// in performance-critical code because it can avoid decoding database
|
||||
/// values.
|
||||
public func hasNull(atIndex index: Int) -> Bool {
|
||||
impl.hasNull(atUncheckedIndex: checkedIndex(index))
|
||||
impl.hasNull(atUncheckedIndex: _checkedIndex(index))
|
||||
}
|
||||
|
||||
/// Returns Int64, Double, String, Data or nil, depending on the value
|
||||
@@ -212,7 +213,7 @@ extension Row {
|
||||
/// Indexes span from 0 for the leftmost column to (row.count - 1) for the
|
||||
/// righmost column.
|
||||
public subscript(_ index: Int) -> DatabaseValueConvertible? {
|
||||
impl.databaseValue(atUncheckedIndex: checkedIndex(index)).storage.value
|
||||
impl.databaseValue(atUncheckedIndex: _checkedIndex(index)).storage.value
|
||||
}
|
||||
|
||||
/// Returns the value at given index, converted to the requested type.
|
||||
@@ -363,7 +364,6 @@ extension Row {
|
||||
/// the same name, the leftmost column is considered.
|
||||
///
|
||||
/// The result is nil if the row does not contain the column.
|
||||
@inlinable
|
||||
public subscript<Column: ColumnExpression>(_ column: Column) -> DatabaseValueConvertible? {
|
||||
self[column.name]
|
||||
}
|
||||
@@ -712,7 +712,7 @@ extension Row {
|
||||
atIndex index: Int)
|
||||
throws -> Value?
|
||||
{
|
||||
try Value.decodeIfPresent(fromRow: self, atUncheckedIndex: checkedIndex(index))
|
||||
try Value.decodeIfPresent(fromRow: self, atUncheckedIndex: _checkedIndex(index))
|
||||
}
|
||||
|
||||
/// Returns the value at given index, converted to the requested type.
|
||||
@@ -728,7 +728,7 @@ extension Row {
|
||||
atIndex index: Int)
|
||||
throws -> Value
|
||||
{
|
||||
try Value.decode(fromRow: self, atUncheckedIndex: checkedIndex(index))
|
||||
try Value.decode(fromRow: self, atUncheckedIndex: _checkedIndex(index))
|
||||
}
|
||||
|
||||
/// Returns the value at given column, converted to the requested type.
|
||||
@@ -793,7 +793,7 @@ extension Row {
|
||||
atIndex index: Int)
|
||||
throws -> Value?
|
||||
{
|
||||
try Value.fastDecodeIfPresent(fromRow: self, atUncheckedIndex: checkedIndex(index))
|
||||
try Value.fastDecodeIfPresent(fromRow: self, atUncheckedIndex: _checkedIndex(index))
|
||||
}
|
||||
|
||||
/// Returns the value at given index, converted to the requested type.
|
||||
@@ -813,7 +813,7 @@ extension Row {
|
||||
atIndex index: Int)
|
||||
throws -> Value
|
||||
{
|
||||
try Value.fastDecode(fromRow: self, atUncheckedIndex: checkedIndex(index))
|
||||
try Value.fastDecode(fromRow: self, atUncheckedIndex: _checkedIndex(index))
|
||||
}
|
||||
|
||||
/// Returns the value at given column, converted to the requested type.
|
||||
@@ -899,7 +899,7 @@ extension Row {
|
||||
/// The returned data does not owns its bytes: it must not be used longer
|
||||
/// than the row's lifetime.
|
||||
func decodeDataNoCopyIfPresent(atIndex index: Int) throws -> Data? {
|
||||
try impl.fastDecodeDataNoCopyIfPresent(atUncheckedIndex: checkedIndex(index))
|
||||
try impl.fastDecodeDataNoCopyIfPresent(atUncheckedIndex: _checkedIndex(index))
|
||||
}
|
||||
|
||||
/// Returns the Data at given index.
|
||||
@@ -913,7 +913,7 @@ extension Row {
|
||||
/// The returned data does not owns its bytes: it must not be used longer
|
||||
/// than the row's lifetime.
|
||||
func decodeDataNoCopy(atIndex index: Int) throws -> Data {
|
||||
try impl.fastDecodeDataNoCopy(atUncheckedIndex: checkedIndex(index))
|
||||
try impl.fastDecodeDataNoCopy(atUncheckedIndex: _checkedIndex(index))
|
||||
}
|
||||
|
||||
/// Returns the optional Data at given column.
|
||||
@@ -953,13 +953,11 @@ extension Row {
|
||||
}
|
||||
|
||||
// Support for fast decoding in scoped rows
|
||||
@usableFromInline
|
||||
func fastDecodeDataNoCopy(atUncheckedIndex index: Int) throws -> Data {
|
||||
try impl.fastDecodeDataNoCopy(atUncheckedIndex: index)
|
||||
}
|
||||
|
||||
// Support for fast decoding in scoped rows
|
||||
@usableFromInline
|
||||
func fastDecodeDataNoCopyIfPresent(atUncheckedIndex index: Int) throws -> Data? {
|
||||
try impl.fastDecodeDataNoCopyIfPresent(atUncheckedIndex: index)
|
||||
}
|
||||
@@ -1189,15 +1187,15 @@ extension Row {
|
||||
/// let rows: RowCursor = try Row.fetchCursor(db, sql: "SELECT * FROM player")
|
||||
/// }
|
||||
public final class RowCursor: Cursor {
|
||||
@usableFromInline enum _State {
|
||||
private enum _State {
|
||||
case idle, busy, done, failed
|
||||
}
|
||||
|
||||
/// The statement iterated by this cursor
|
||||
public let statement: Statement
|
||||
@usableFromInline let _sqliteStatement: SQLiteStatement
|
||||
@usableFromInline let _row: Row // Reused for performance
|
||||
@usableFromInline var _state = _State.idle
|
||||
private let _sqliteStatement: SQLiteStatement
|
||||
private let _row: Row // Reused for performance
|
||||
private var _state = _State.idle
|
||||
|
||||
init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws {
|
||||
self.statement = statement
|
||||
@@ -1218,7 +1216,6 @@ public final class RowCursor: Cursor {
|
||||
try? statement.reset()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func next() throws -> Row? {
|
||||
switch _state {
|
||||
case .done:
|
||||
@@ -1660,7 +1657,7 @@ extension Row {
|
||||
|
||||
/// Accesses the (ColumnName, DatabaseValue) pair at given index.
|
||||
public subscript(position: RowIndex) -> (String, DatabaseValue) {
|
||||
let index = checkedIndex(position.index)
|
||||
let index = _checkedIndex(position.index)
|
||||
return (
|
||||
impl.columnName(atUncheckedIndex: index),
|
||||
impl.databaseValue(atUncheckedIndex: index))
|
||||
|
||||
@@ -35,7 +35,6 @@ enum RowDecodingError: Error {
|
||||
/// The SQL query arguments
|
||||
let statementArguments: StatementArguments?
|
||||
|
||||
@usableFromInline
|
||||
init(decodingContext: RowDecodingContext, debugDescription: String) {
|
||||
self.debugDescription = debugDescription
|
||||
self.row = decodingContext.row
|
||||
@@ -89,7 +88,6 @@ enum RowDecodingError: Error {
|
||||
|
||||
/// Convenience method that builds the
|
||||
/// `could not decode <Type> from database value <value>` error message.
|
||||
@usableFromInline
|
||||
static func valueMismatch(
|
||||
_ type: Any.Type,
|
||||
statement: Statement,
|
||||
|
||||
@@ -129,7 +129,6 @@ public final class Statement {
|
||||
sqlite3_finalize(sqliteStatement)
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
final func reset() throws {
|
||||
SchedulingWatchdog.preconditionValidQueue(database)
|
||||
let code = sqlite3_reset(sqliteStatement)
|
||||
@@ -141,11 +140,9 @@ public final class Statement {
|
||||
|
||||
// MARK: Arguments
|
||||
|
||||
@usableFromInline
|
||||
var argumentsNeedValidation = true
|
||||
private var argumentsNeedValidation = true
|
||||
|
||||
@usableFromInline
|
||||
var _arguments = StatementArguments()
|
||||
private var _arguments = StatementArguments()
|
||||
|
||||
lazy var sqliteArgumentCount: Int = {
|
||||
Int(sqlite3_bind_parameter_count(self.sqliteStatement))
|
||||
@@ -260,7 +257,6 @@ public final class Statement {
|
||||
}
|
||||
|
||||
// 1-based index
|
||||
@inlinable
|
||||
func bind<T: StatementBinding>(_ value: T, at index: CInt) {
|
||||
let code = value.bind(to: sqliteStatement, at: index)
|
||||
|
||||
@@ -272,7 +268,6 @@ public final class Statement {
|
||||
}
|
||||
|
||||
// Don't make this one public unless we keep the arguments property in sync.
|
||||
@usableFromInline
|
||||
func clearBindings() {
|
||||
// It looks like sqlite3_clear_bindings() does not access the file system.
|
||||
// This function call should thus succeed, unless a GRDB bug: there is
|
||||
@@ -340,13 +335,13 @@ extension Statement {
|
||||
/// try cursor.next()
|
||||
/// }
|
||||
final class StatementCursor: Cursor {
|
||||
@usableFromInline enum _State {
|
||||
private enum _State {
|
||||
case idle, busy, done, failed
|
||||
}
|
||||
|
||||
let _statement: Statement
|
||||
let _sqliteStatement: SQLiteStatement
|
||||
var _state = _State.idle
|
||||
/* private, internal for testability */ let _statement: Statement
|
||||
private let _sqliteStatement: SQLiteStatement
|
||||
private var _state = _State.idle
|
||||
|
||||
// Use Statement.makeCursor() instead
|
||||
init(statement: Statement, arguments: StatementArguments? = nil) throws {
|
||||
@@ -368,7 +363,6 @@ final class StatementCursor: Cursor {
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@inlinable
|
||||
func next() throws -> Void? {
|
||||
switch _state {
|
||||
case .done:
|
||||
@@ -592,8 +586,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable,
|
||||
self.init(values)
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
mutating func set(databaseValues: [DatabaseValue]) {
|
||||
private mutating func set(databaseValues: [DatabaseValue]) {
|
||||
self.values = databaseValues
|
||||
namedValues.removeAll(keepingCapacity: true)
|
||||
}
|
||||
|
||||
@@ -129,7 +129,8 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// }
|
||||
/// }
|
||||
public final class FastDatabaseValueCursor<Value: DatabaseValueConvertible & StatementColumnConvertible> : Cursor {
|
||||
@usableFromInline enum _State {
|
||||
@usableFromInline
|
||||
enum _State {
|
||||
case idle, busy, done, failed
|
||||
}
|
||||
|
||||
@@ -213,7 +214,8 @@ public final class FastDatabaseValueCursor<Value: DatabaseValueConvertible & Sta
|
||||
public final class FastNullableDatabaseValueCursor<Value>: Cursor
|
||||
where Value: DatabaseValueConvertible & StatementColumnConvertible
|
||||
{
|
||||
@usableFromInline enum _State {
|
||||
@usableFromInline
|
||||
enum _State {
|
||||
case idle, busy, done, failed
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import Foundation
|
||||
|
||||
/// Data is convertible to and from DatabaseValue.
|
||||
extension Data: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
@inlinable
|
||||
public init(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
if let bytes = sqlite3_column_blob(sqliteStatement, index) {
|
||||
let count = Int(sqlite3_column_bytes(sqliteStatement, index))
|
||||
@@ -13,7 +12,6 @@ extension Data: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
DatabaseValue(storage: .blob(self))
|
||||
}
|
||||
@@ -33,7 +31,6 @@ extension Data: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
withUnsafeBytes {
|
||||
sqlite3_bind_blob(sqliteStatement, index, $0.baseAddress, Int32($0.count), SQLITE_TRANSIENT)
|
||||
@@ -44,7 +41,6 @@ extension Data: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
// MARK: - Conversions
|
||||
|
||||
extension Data {
|
||||
@inlinable
|
||||
static func fastDecodeNoCopy(
|
||||
fromStatement sqliteStatement: SQLiteStatement,
|
||||
atUncheckedIndex index: Int32,
|
||||
@@ -65,7 +61,6 @@ extension Data {
|
||||
return Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes), count: count, deallocator: .none)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func fastDecodeNoCopy(
|
||||
fromRow row: Row,
|
||||
atUncheckedIndex index: Int)
|
||||
@@ -81,7 +76,6 @@ extension Data {
|
||||
return try row.fastDecodeDataNoCopy(atUncheckedIndex: index)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func fastDecodeNoCopyIfPresent(
|
||||
fromStatement sqliteStatement: SQLiteStatement,
|
||||
atUncheckedIndex index: Int32,
|
||||
@@ -98,7 +92,6 @@ extension Data {
|
||||
return Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes), count: count, deallocator: .none)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func fastDecodeNoCopyIfPresent(
|
||||
fromRow row: Row,
|
||||
atUncheckedIndex index: Int)
|
||||
|
||||
@@ -58,7 +58,6 @@ extension Date: DatabaseValueConvertible {
|
||||
return nil
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
init?(databaseDateComponents: DatabaseDateComponents) {
|
||||
guard databaseDateComponents.format.hasYMDComponents else {
|
||||
// Refuse to turn hours without any date information into Date:
|
||||
@@ -118,7 +117,6 @@ extension Date: StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
switch sqlite3_column_type(sqliteStatement, index) {
|
||||
case SQLITE_INTEGER, SQLITE_FLOAT:
|
||||
|
||||
@@ -161,13 +161,11 @@ final class SQLiteDateParser {
|
||||
var cString: UnsafePointer<CChar>
|
||||
var length: Int
|
||||
|
||||
@inline(__always)
|
||||
private mutating func shift() {
|
||||
cString += 1
|
||||
length -= 1
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
mutating func parse(_ scalar: Unicode.Scalar) -> Bool {
|
||||
guard length > 0, cString[0] == UInt8(ascii: scalar) else {
|
||||
return false
|
||||
@@ -176,7 +174,6 @@ final class SQLiteDateParser {
|
||||
return true
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
mutating func parseDigit() -> Int? {
|
||||
guard length > 0 else {
|
||||
return nil
|
||||
@@ -190,7 +187,6 @@ final class SQLiteDateParser {
|
||||
return Int(digit)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
mutating func parseDigit(into number: inout Int) -> Bool {
|
||||
guard let digit = parseDigit() else {
|
||||
return false
|
||||
@@ -199,7 +195,6 @@ final class SQLiteDateParser {
|
||||
return true
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
mutating func parseNNNN() -> Int? {
|
||||
var number = 0
|
||||
guard parseDigit(into: &number)
|
||||
@@ -213,7 +208,6 @@ final class SQLiteDateParser {
|
||||
return number
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
mutating func parseNN() -> Int? {
|
||||
var number = 0
|
||||
guard parseDigit(into: &number)
|
||||
|
||||
@@ -49,7 +49,6 @@ extension UUID: DatabaseValueConvertible {
|
||||
}
|
||||
|
||||
extension UUID: StatementColumnConvertible {
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
switch sqlite3_column_type(sqliteStatement, index) {
|
||||
case SQLITE_TEXT:
|
||||
|
||||
@@ -18,7 +18,6 @@ extension SQLExpressible where Self: RawRepresentable, Self.RawValue: SQLExpress
|
||||
}
|
||||
|
||||
extension StatementBinding where Self: RawRepresentable, Self.RawValue: StatementBinding {
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
rawValue.bind(to: sqliteStatement, at: index)
|
||||
}
|
||||
@@ -38,7 +37,6 @@ extension StatementBinding where Self: RawRepresentable, Self.RawValue: Statemen
|
||||
/// // adopt DatabaseValueConvertible:
|
||||
/// extension Color: DatabaseValueConvertible { }
|
||||
extension DatabaseValueConvertible where Self: RawRepresentable, Self.RawValue: DatabaseValueConvertible {
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
rawValue.databaseValue
|
||||
}
|
||||
|
||||
@@ -8,13 +8,11 @@ extension Bool: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
self = sqlite3_column_int64(sqliteStatement, index) != 0
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
(self ? 1 : 0).databaseValue
|
||||
}
|
||||
@@ -87,7 +85,6 @@ extension Bool: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, self ? 1 : 0)
|
||||
}
|
||||
@@ -101,7 +98,6 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let v = Int(exactly: int64) else { return nil }
|
||||
@@ -109,7 +105,6 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
@@ -119,7 +114,6 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int(exactly: $0) }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
}
|
||||
@@ -133,7 +127,6 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let v = Int8(exactly: int64) else { return nil }
|
||||
@@ -141,7 +134,6 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
@@ -151,7 +143,6 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int8(exactly: $0) }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
}
|
||||
@@ -165,7 +156,6 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let v = Int16(exactly: int64) else { return nil }
|
||||
@@ -173,7 +163,6 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
@@ -183,7 +172,6 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int16(exactly: $0) }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
}
|
||||
@@ -197,7 +185,6 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let v = Int32(exactly: int64) else { return nil }
|
||||
@@ -205,7 +192,6 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
@@ -215,7 +201,6 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int32(exactly: $0) }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
}
|
||||
@@ -229,13 +214,11 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
self = sqlite3_column_int64(sqliteStatement, index)
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
DatabaseValue(storage: .int64(self))
|
||||
}
|
||||
@@ -254,7 +237,6 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, self)
|
||||
}
|
||||
@@ -268,7 +250,6 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let v = UInt(exactly: int64) else { return nil }
|
||||
@@ -276,7 +257,6 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
@@ -286,7 +266,6 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt(exactly: $0) }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
}
|
||||
@@ -300,7 +279,6 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let v = UInt8(exactly: int64) else { return nil }
|
||||
@@ -308,7 +286,6 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
@@ -318,7 +295,6 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt8(exactly: $0) }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
}
|
||||
@@ -332,7 +308,6 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let v = UInt16(exactly: int64) else { return nil }
|
||||
@@ -340,7 +315,6 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
@@ -350,7 +324,6 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt16(exactly: $0) }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
}
|
||||
@@ -364,7 +337,6 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let v = UInt32(exactly: int64) else { return nil }
|
||||
@@ -372,7 +344,6 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
@@ -382,7 +353,6 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt32(exactly: $0) }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
}
|
||||
@@ -396,7 +366,6 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init?(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
let int64 = sqlite3_column_int64(sqliteStatement, index)
|
||||
guard let v = UInt64(exactly: int64) else { return nil }
|
||||
@@ -404,7 +373,6 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
@@ -414,7 +382,6 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt64(exactly: $0) }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_int64(sqliteStatement, index, Int64(self))
|
||||
}
|
||||
@@ -428,13 +395,11 @@ extension Double: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
self = sqlite3_column_double(sqliteStatement, index)
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
DatabaseValue(storage: .double(self))
|
||||
}
|
||||
@@ -451,7 +416,6 @@ extension Double: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_double(sqliteStatement, index, self)
|
||||
}
|
||||
@@ -465,13 +429,11 @@ extension Float: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
self = Float(sqlite3_column_double(sqliteStatement, index))
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
Double(self).databaseValue
|
||||
}
|
||||
@@ -488,7 +450,6 @@ extension Float: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_double(sqliteStatement, index, Double(self))
|
||||
}
|
||||
@@ -502,13 +463,11 @@ extension String: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - sqliteStatement: A pointer to an SQLite statement.
|
||||
/// - index: The column index.
|
||||
@inlinable
|
||||
public init(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
self = String(cString: sqlite3_column_text(sqliteStatement, index)!)
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
@inlinable
|
||||
public var databaseValue: DatabaseValue {
|
||||
DatabaseValue(storage: .string(self))
|
||||
}
|
||||
@@ -527,7 +486,6 @@ extension String: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt {
|
||||
sqlite3_bind_text(sqliteStatement, index, self, -1, SQLITE_TRANSIENT)
|
||||
}
|
||||
|
||||
@@ -881,6 +881,7 @@ typealias StatementObservation = (TransactionObservation, DatabaseEventPredicate
|
||||
|
||||
/// A kind of database event. See the `TransactionObserver` protocol for
|
||||
/// more information.
|
||||
@frozen
|
||||
public enum DatabaseEventKind {
|
||||
/// The insertion of a row in a database table
|
||||
case insert(tableName: String)
|
||||
|
||||
@@ -45,7 +45,6 @@ public protocol Association: _Association, DerivableRequest {
|
||||
|
||||
extension Association {
|
||||
/// Returns self modified with the *update* function.
|
||||
@inline(__always)
|
||||
func with(_ update: (inout Self) throws -> Void) rethrows -> Self {
|
||||
var result = self
|
||||
try update(&result)
|
||||
@@ -53,7 +52,6 @@ extension Association {
|
||||
}
|
||||
|
||||
/// Returns self with destination relation modified with the *update* function.
|
||||
@inline(__always)
|
||||
fileprivate func withDestinationRelation(_ update: (inout SQLRelation) throws -> Void) rethrows -> Self {
|
||||
var result = self
|
||||
try update(&result._sqlAssociation.destination.relation)
|
||||
|
||||
@@ -52,6 +52,12 @@ public struct Column: ColumnExpression, Equatable {
|
||||
public init(_ codingKey: CodingKey) {
|
||||
self.name = codingKey.stringValue
|
||||
}
|
||||
|
||||
// Avoid a wrong resolution when BUILD_LIBRARY_FOR_DISTRIBUTION is set
|
||||
@_disfavoredOverload
|
||||
public static func == (lhs: Column, rhs: Column) -> Bool {
|
||||
lhs.name == rhs.name
|
||||
}
|
||||
}
|
||||
|
||||
/// Support for column enums:
|
||||
|
||||
@@ -965,20 +965,17 @@ protocol ColumnAddressable {
|
||||
struct DummyRow: ColumnAddressable {
|
||||
struct DummyIndex { }
|
||||
func index(forColumn column: String) -> DummyIndex? { DummyIndex() }
|
||||
@inline(__always)
|
||||
func databaseValue(at index: DummyIndex) -> DatabaseValue { DatabaseValue(storage: .int64(1)) }
|
||||
}
|
||||
|
||||
/// Row has columns
|
||||
extension Row: ColumnAddressable {
|
||||
@inline(__always)
|
||||
func databaseValue(at index: Int) -> DatabaseValue { self[index] }
|
||||
}
|
||||
|
||||
/// PersistenceContainer has columns
|
||||
extension PersistenceContainer: ColumnAddressable {
|
||||
func index(forColumn column: String) -> String? { column }
|
||||
@inline(__always)
|
||||
func databaseValue(at column: String) -> DatabaseValue {
|
||||
self[caseInsensitive: column]?.databaseValue ?? .null
|
||||
}
|
||||
|
||||
@@ -120,12 +120,10 @@ private class RecordEncoder<Record: EncodableRecord>: Encoder {
|
||||
}
|
||||
|
||||
/// Helper methods
|
||||
@inline(__always)
|
||||
fileprivate func persist(_ value: DatabaseValueConvertible?, forKey key: CodingKey) {
|
||||
_persistenceContainer[key.stringValue] = value
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
fileprivate func encode<T>(_ value: T, forKey key: CodingKey) throws where T: Encodable {
|
||||
if let date = value as? Date {
|
||||
persist(Record.databaseDateEncodingStrategy.encode(date), forKey: key)
|
||||
@@ -236,7 +234,6 @@ private var iso8601Formatter: ISO8601DateFormatter = {
|
||||
}()
|
||||
|
||||
extension DatabaseDateEncodingStrategy {
|
||||
@inline(__always)
|
||||
fileprivate func encode(_ date: Date) -> DatabaseValueConvertible? {
|
||||
switch self {
|
||||
case .deferredToDate:
|
||||
@@ -264,7 +261,6 @@ extension DatabaseDateEncodingStrategy {
|
||||
}
|
||||
|
||||
extension DatabaseUUIDEncodingStrategy {
|
||||
@inline(__always)
|
||||
fileprivate func encode(_ uuid: UUID) -> DatabaseValueConvertible? {
|
||||
switch self {
|
||||
case .deferredToUUID:
|
||||
|
||||
@@ -195,14 +195,13 @@ public struct PersistenceContainer {
|
||||
// fileprivate for Row(_:PersistenceContainer)
|
||||
// The ordering of the OrderedDictionary helps generating always the same
|
||||
// SQL queries, and hit the statement cache.
|
||||
@usableFromInline var storage: OrderedDictionary<String, DatabaseValueConvertible?>
|
||||
fileprivate var storage: OrderedDictionary<String, DatabaseValueConvertible?>
|
||||
|
||||
/// Accesses the value associated with the given column.
|
||||
///
|
||||
/// It is undefined behavior to set different values for the same column.
|
||||
/// Column names are case insensitive, so defining both "name" and "NAME"
|
||||
/// is considered undefined behavior.
|
||||
@inlinable
|
||||
public subscript(_ column: String) -> DatabaseValueConvertible? {
|
||||
get { storage[column] ?? nil }
|
||||
set { storage.updateValue(newValue, forKey: column) }
|
||||
@@ -213,7 +212,6 @@ public struct PersistenceContainer {
|
||||
/// It is undefined behavior to set different values for the same column.
|
||||
/// Column names are case insensitive, so defining both "name" and "NAME"
|
||||
/// is considered undefined behavior.
|
||||
@inlinable
|
||||
public subscript<Column: ColumnExpression>(_ column: Column) -> DatabaseValueConvertible? {
|
||||
get { self[column.name] }
|
||||
set { self[column.name] = newValue }
|
||||
|
||||
@@ -238,7 +238,6 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
|
||||
|
||||
// Helper methods
|
||||
|
||||
@inline(__always)
|
||||
private func decode<T>(
|
||||
_ type: T.Type,
|
||||
fromRow row: Row,
|
||||
@@ -255,7 +254,6 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
|
||||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
private func decode<T>(
|
||||
_ type: T.Type,
|
||||
fromRow row: Row,
|
||||
@@ -404,7 +402,6 @@ private var iso8601Formatter: ISO8601DateFormatter = {
|
||||
}()
|
||||
|
||||
extension DatabaseDateDecodingStrategy {
|
||||
@inline(__always)
|
||||
fileprivate func decodeIfPresent(fromRow row: Row, atUncheckedIndex index: Int) throws -> Date? {
|
||||
if let sqliteStatement = row.sqliteStatement {
|
||||
return try decodeIfPresent(
|
||||
@@ -418,7 +415,6 @@ extension DatabaseDateDecodingStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
fileprivate func decode(fromRow row: Row, atUncheckedIndex index: Int) throws -> Date {
|
||||
if let sqliteStatement = row.sqliteStatement {
|
||||
return try decode(
|
||||
@@ -432,7 +428,6 @@ extension DatabaseDateDecodingStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
fileprivate func decode(
|
||||
fromStatement sqliteStatement: SQLiteStatement,
|
||||
atUncheckedIndex index: Int32,
|
||||
@@ -491,7 +486,6 @@ extension DatabaseDateDecodingStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
fileprivate func decodeIfPresent(
|
||||
fromStatement sqliteStatement: SQLiteStatement,
|
||||
atUncheckedIndex index: Int32,
|
||||
@@ -504,7 +498,6 @@ extension DatabaseDateDecodingStrategy {
|
||||
return try decode(fromStatement: sqliteStatement, atUncheckedIndex: index, context: context())
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
fileprivate func decode(
|
||||
fromDatabaseValue dbValue: DatabaseValue,
|
||||
context: @autoclosure () -> RowDecodingContext)
|
||||
@@ -517,7 +510,6 @@ extension DatabaseDateDecodingStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
fileprivate func decodeIfPresent(
|
||||
fromDatabaseValue dbValue: DatabaseValue,
|
||||
context: @autoclosure () -> RowDecodingContext)
|
||||
@@ -533,7 +525,6 @@ extension DatabaseDateDecodingStrategy {
|
||||
}
|
||||
|
||||
// Returns nil if decoding fails
|
||||
@inline(__always)
|
||||
private func dateFromDatabaseValue(_ dbValue: DatabaseValue) -> Date? {
|
||||
switch self {
|
||||
case .deferredToDate:
|
||||
|
||||
@@ -494,14 +494,14 @@ extension FetchRequest where RowDecoder: FetchableRecord & Hashable {
|
||||
/// let players: RecordCursor<Player> = try Player.fetchCursor(db, sql: "SELECT * FROM player")
|
||||
/// }
|
||||
public final class RecordCursor<Record: FetchableRecord>: Cursor {
|
||||
@usableFromInline enum _State {
|
||||
private enum _State {
|
||||
case idle, busy, done, failed
|
||||
}
|
||||
|
||||
@usableFromInline let _statement: Statement
|
||||
@usableFromInline let _row: Row // Reused for performance
|
||||
@usableFromInline let _sqliteStatement: SQLiteStatement
|
||||
@usableFromInline var _state = _State.idle
|
||||
private let _statement: Statement
|
||||
private let _row: Row // Reused for performance
|
||||
private let _sqliteStatement: SQLiteStatement
|
||||
private var _state = _State.idle
|
||||
|
||||
init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws {
|
||||
_statement = statement
|
||||
@@ -522,7 +522,6 @@ public final class RecordCursor<Record: FetchableRecord>: Cursor {
|
||||
try? _statement.reset()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func next() throws -> Record? {
|
||||
switch _state {
|
||||
case .done:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
extension Database.ConflictResolution {
|
||||
@usableFromInline var invalidatesLastInsertedRowID: Bool {
|
||||
var invalidatesLastInsertedRowID: Bool {
|
||||
switch self {
|
||||
case .abort, .fail, .rollback, .replace:
|
||||
return false
|
||||
@@ -350,7 +350,6 @@ extension MutablePersistableRecord {
|
||||
// MARK: - CRUD Internals
|
||||
|
||||
/// Return a non-nil dictionary if record has a non-null primary key
|
||||
@usableFromInline
|
||||
func primaryKey(_ db: Database) throws -> [String: DatabaseValue]? {
|
||||
let databaseTableName = type(of: self).databaseTableName
|
||||
let primaryKeyInfo = try db.primaryKey(databaseTableName)
|
||||
@@ -371,7 +370,6 @@ extension MutablePersistableRecord {
|
||||
/// that adopt MutablePersistableRecord can invoke performInsert() in their
|
||||
/// implementation of insert(). They should not provide their own
|
||||
/// implementation of performInsert().
|
||||
@inlinable
|
||||
public mutating func performInsert(_ db: Database) throws {
|
||||
let conflictResolutionForInsert = type(of: self).persistenceConflictPolicy.conflictResolutionForInsert
|
||||
let dao = try DAO(db, self)
|
||||
@@ -395,7 +393,6 @@ extension MutablePersistableRecord {
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
/// PersistenceError.recordNotFound is thrown if the primary key does not
|
||||
/// match any row in the database.
|
||||
@inlinable
|
||||
public func performUpdate(_ db: Database, columns: Set<String>) throws {
|
||||
let dao = try DAO(db, self)
|
||||
guard let statement = try dao.updateStatement(
|
||||
@@ -420,7 +417,6 @@ extension MutablePersistableRecord {
|
||||
/// implementation of performSave().
|
||||
///
|
||||
/// This default implementation forwards the job to `update` or `insert`.
|
||||
@inlinable
|
||||
public mutating func performSave(_ db: Database) throws {
|
||||
// Call self.insert and self.update so that we support classes that
|
||||
// override those methods.
|
||||
@@ -442,7 +438,6 @@ extension MutablePersistableRecord {
|
||||
/// that adopt MutablePersistableRecord can invoke performDelete() in
|
||||
/// their implementation of delete(). They should not provide their own
|
||||
/// implementation of performDelete().
|
||||
@inlinable
|
||||
public func performDelete(_ db: Database) throws -> Bool {
|
||||
guard let statement = try DAO(db, self).deleteStatement() else {
|
||||
// Nil primary key
|
||||
@@ -459,7 +454,6 @@ extension MutablePersistableRecord {
|
||||
/// that adopt MutablePersistableRecord can invoke performExists() in
|
||||
/// their implementation of exists(). They should not provide their own
|
||||
/// implementation of performExists().
|
||||
@inlinable
|
||||
public func performExists(_ db: Database) throws -> Bool {
|
||||
guard let statement = try DAO(db, self).existsStatement() else {
|
||||
// Nil primary key
|
||||
@@ -602,7 +596,6 @@ extension PersistableRecord {
|
||||
/// that adopt PersistableRecord can invoke performInsert() in their
|
||||
/// implementation of insert(). They should not provide their own
|
||||
/// implementation of performInsert().
|
||||
@inlinable
|
||||
public func performInsert(_ db: Database) throws {
|
||||
let conflictResolutionForInsert = type(of: self).persistenceConflictPolicy.conflictResolutionForInsert
|
||||
let dao = try DAO(db, self)
|
||||
@@ -622,7 +615,6 @@ extension PersistableRecord {
|
||||
/// implementation of performSave().
|
||||
///
|
||||
/// This default implementation forwards the job to `update` or `insert`.
|
||||
@inlinable
|
||||
public func performSave(_ db: Database) throws {
|
||||
// Call self.insert and self.update so that we support classes that
|
||||
// override those methods.
|
||||
@@ -651,7 +643,6 @@ extension PersistenceContainer {
|
||||
}
|
||||
|
||||
/// DAO takes care of PersistableRecord CRUD
|
||||
@usableFromInline
|
||||
final class DAO<Record: MutablePersistableRecord> {
|
||||
/// The database
|
||||
let db: Database
|
||||
@@ -665,9 +656,8 @@ final class DAO<Record: MutablePersistableRecord> {
|
||||
let databaseTableName: String
|
||||
|
||||
/// The table primary key info
|
||||
@usableFromInline let primaryKey: PrimaryKeyInfo
|
||||
let primaryKey: PrimaryKeyInfo
|
||||
|
||||
@usableFromInline
|
||||
init(_ db: Database, _ record: Record) throws {
|
||||
self.db = db
|
||||
databaseTableName = type(of: record).databaseTableName
|
||||
@@ -676,7 +666,6 @@ final class DAO<Record: MutablePersistableRecord> {
|
||||
GRDBPrecondition(!persistenceContainer.isEmpty, "\(type(of: record)): invalid empty persistence container")
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
func insertStatement(onConflict: Database.ConflictResolution) throws -> Statement {
|
||||
let query = InsertQuery(
|
||||
onConflict: onConflict,
|
||||
@@ -688,7 +677,6 @@ final class DAO<Record: MutablePersistableRecord> {
|
||||
}
|
||||
|
||||
/// Returns nil if and only if primary key is nil
|
||||
@usableFromInline
|
||||
func updateStatement(columns: Set<String>, onConflict: Database.ConflictResolution) throws -> Statement? {
|
||||
// Fail early if primary key does not resolve to a database row.
|
||||
let primaryKeyColumns = primaryKey.columns
|
||||
@@ -738,7 +726,6 @@ final class DAO<Record: MutablePersistableRecord> {
|
||||
}
|
||||
|
||||
/// Returns nil if and only if primary key is nil
|
||||
@usableFromInline
|
||||
func deleteStatement() throws -> Statement? {
|
||||
// Fail early if primary key does not resolve to a database row.
|
||||
let primaryKeyColumns = primaryKey.columns
|
||||
@@ -758,7 +745,6 @@ final class DAO<Record: MutablePersistableRecord> {
|
||||
}
|
||||
|
||||
/// Returns nil if and only if primary key is nil
|
||||
@usableFromInline
|
||||
func existsStatement() throws -> Statement? {
|
||||
// Fail early if primary key does not resolve to a database row.
|
||||
let primaryKeyColumns = primaryKey.columns
|
||||
@@ -778,7 +764,6 @@ final class DAO<Record: MutablePersistableRecord> {
|
||||
}
|
||||
|
||||
/// Throws a PersistenceError.recordNotFound error
|
||||
@usableFromInline
|
||||
func makeRecordNotFoundError() -> Error {
|
||||
let key = Dictionary(uniqueKeysWithValues: primaryKey.columns.map {
|
||||
($0, persistenceContainer[caseInsensitive: $0]?.databaseValue ?? .null)
|
||||
|
||||
@@ -8,10 +8,9 @@
|
||||
/// dict["bar"] // 2
|
||||
/// dict["qux"] // nil
|
||||
/// dict.map { $0.key } // ["foo", "bar"], in this order.
|
||||
@usableFromInline
|
||||
struct OrderedDictionary<Key: Hashable, Value> {
|
||||
@usableFromInline /* private(set) */ var keys: [Key]
|
||||
@usableFromInline /* private(set) */ var dictionary: [Key: Value]
|
||||
private(set) var keys: [Key]
|
||||
private(set) var dictionary: [Key: Value]
|
||||
|
||||
var values: [Value] { keys.map { dictionary[$0]! } }
|
||||
|
||||
@@ -35,7 +34,6 @@ struct OrderedDictionary<Key: Hashable, Value> {
|
||||
}
|
||||
|
||||
/// Returns the value associated with key, or nil.
|
||||
@usableFromInline
|
||||
subscript(_ key: Key) -> Value? {
|
||||
get { dictionary[key] }
|
||||
set {
|
||||
@@ -48,7 +46,6 @@ struct OrderedDictionary<Key: Hashable, Value> {
|
||||
}
|
||||
|
||||
/// Returns the value associated with key, or the default value.
|
||||
@inlinable
|
||||
subscript(_ key: Key, default defaultValue: Value) -> Value {
|
||||
get { dictionary[key] ?? defaultValue }
|
||||
set { self[key] = newValue }
|
||||
@@ -72,7 +69,6 @@ struct OrderedDictionary<Key: Hashable, Value> {
|
||||
/// original value. If the given key is not present in the dictionary, this
|
||||
/// method appends the key-value pair and returns nil.
|
||||
@discardableResult
|
||||
@usableFromInline
|
||||
mutating func updateValue(_ value: Value, forKey key: Key) -> Value? {
|
||||
if let oldValue = dictionary.updateValue(value, forKey: key) {
|
||||
return oldValue
|
||||
@@ -83,7 +79,6 @@ struct OrderedDictionary<Key: Hashable, Value> {
|
||||
|
||||
/// Removes the value associated with key.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
mutating func removeValue(forKey key: Key) -> Value? {
|
||||
guard let value = dictionary.removeValue(forKey: key) else {
|
||||
return nil
|
||||
@@ -173,16 +168,13 @@ struct OrderedDictionary<Key: Hashable, Value> {
|
||||
}
|
||||
|
||||
extension OrderedDictionary: Collection {
|
||||
@usableFromInline
|
||||
typealias Index = Int
|
||||
|
||||
@usableFromInline var startIndex: Int { 0 }
|
||||
@usableFromInline var endIndex: Int { keys.count }
|
||||
var startIndex: Int { 0 }
|
||||
var endIndex: Int { keys.count }
|
||||
|
||||
@usableFromInline
|
||||
func index(after i: Int) -> Int { i + 1 }
|
||||
|
||||
@usableFromInline
|
||||
subscript(position: Int) -> (key: Key, value: Value) {
|
||||
let key = keys[position]
|
||||
return (key: key, value: dictionary[key]!)
|
||||
@@ -190,7 +182,6 @@ extension OrderedDictionary: Collection {
|
||||
}
|
||||
|
||||
extension OrderedDictionary: ExpressibleByDictionaryLiteral {
|
||||
@usableFromInline
|
||||
init(dictionaryLiteral elements: (Key, Value)...) {
|
||||
self.keys = elements.map { $0.0 }
|
||||
self.dictionary = Dictionary(uniqueKeysWithValues: elements)
|
||||
@@ -198,7 +189,6 @@ extension OrderedDictionary: ExpressibleByDictionaryLiteral {
|
||||
}
|
||||
|
||||
extension OrderedDictionary: Equatable where Value: Equatable {
|
||||
@usableFromInline
|
||||
static func == (lhs: OrderedDictionary, rhs: OrderedDictionary) -> Bool {
|
||||
(lhs.keys == rhs.keys) && (lhs.dictionary == rhs.dictionary)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ extension Refinable {
|
||||
/// }
|
||||
/// newPlayer.name // "Arthur"
|
||||
/// newPlayer.score // 100
|
||||
@inline(__always)
|
||||
func with(_ update: (inout Self) throws -> Void) rethrows -> Self {
|
||||
var result = self
|
||||
try update(&result)
|
||||
|
||||
+1
-10
@@ -7,7 +7,7 @@ extension String {
|
||||
/// SQL query.
|
||||
///
|
||||
/// db.execute(sql: "SELECT * FROM \(tableName.quotedDatabaseIdentifier)")
|
||||
@inlinable public var quotedDatabaseIdentifier: String {
|
||||
public var quotedDatabaseIdentifier: String {
|
||||
// See <https://www.sqlite.org/lang_keywords.html>
|
||||
return "\"\(self)\""
|
||||
}
|
||||
@@ -16,7 +16,6 @@ extension String {
|
||||
/// Return as many question marks separated with commas as the *count* argument.
|
||||
///
|
||||
/// databaseQuestionMarks(count: 3) // "?,?,?"
|
||||
@inlinable
|
||||
public func databaseQuestionMarks(count: Int) -> String {
|
||||
repeatElement("?", count: count).joined(separator: ",")
|
||||
}
|
||||
@@ -37,7 +36,6 @@ extension Optional: _OptionalProtocol { }
|
||||
// MARK: - Internal
|
||||
|
||||
/// Reserved for GRDB: do not use.
|
||||
@inlinable
|
||||
func GRDBPrecondition(
|
||||
_ condition: @autoclosure() -> Bool,
|
||||
_ message: @autoclosure() -> String = "",
|
||||
@@ -52,7 +50,6 @@ func GRDBPrecondition(
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable
|
||||
func fatalError<E: Error>(_ error: E) -> Never {
|
||||
try! { throw error }()
|
||||
}
|
||||
@@ -93,7 +90,6 @@ extension DispatchQueue {
|
||||
}
|
||||
|
||||
extension Sequence {
|
||||
@inlinable
|
||||
func countElements(where predicate: (Element) throws -> Bool) rethrows -> Int {
|
||||
var count = 0
|
||||
for e in self where try predicate(e) {
|
||||
@@ -112,7 +108,6 @@ extension Sequence {
|
||||
/// try throwingFirstError(
|
||||
/// execute: work,
|
||||
/// finally: cleanup)
|
||||
@inline(__always)
|
||||
func throwingFirstError<T>(execute: () throws -> T, finally: () throws -> Void) throws -> T {
|
||||
var result: T?
|
||||
var firstError: Error?
|
||||
@@ -171,8 +166,6 @@ func concat<T>(_ rhs: ((T) -> Void)?, _ lhs: ((T) -> Void)?) -> ((T) -> Void)? {
|
||||
}
|
||||
|
||||
extension NSRecursiveLock {
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
func synchronized<T>(
|
||||
_ message: @autoclosure () -> String = #function,
|
||||
_ block: () throws -> T)
|
||||
@@ -199,8 +192,6 @@ extension NSRecursiveLock {
|
||||
|
||||
/// Performs the side effect outside of the synchronized block. This allows
|
||||
/// avoiding deadlocks, when the side effect feedbacks.
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
func synchronized(
|
||||
_ message: @autoclosure () -> String = #function,
|
||||
_ block: (inout (() -> Void)?) -> Void)
|
||||
|
||||
@@ -7900,6 +7900,7 @@ FAQ
|
||||
|
||||
- [How do I monitor the duration of database statements execution?](#how-do-i-monitor-the-duration-of-database-statements-execution)
|
||||
- [What Are Experimental Features?](#what-are-experimental-features)
|
||||
- [Does GRDB support library evolution and ABI stability?](does-grdb-support-library-evolution-and-abi-stability)
|
||||
|
||||
**[FAQ: Associations](#faq-associations)**
|
||||
|
||||
@@ -8028,6 +8029,7 @@ db.trace { event in
|
||||
- :arrow_up: [FAQ]
|
||||
- [How do I monitor the duration of database statements execution?](#how-do-i-monitor-the-duration-of-database-statements-execution)
|
||||
- [What Are Experimental Features?](#what-are-experimental-features)
|
||||
- [Does GRDB support library evolution and ABI stability?](does-grdb-support-library-evolution-and-abi-stability)
|
||||
|
||||
### How do I monitor the duration of database statements execution?
|
||||
|
||||
@@ -8054,6 +8056,11 @@ try dbQueue.read { db in
|
||||
}
|
||||
```
|
||||
|
||||
### Does GRDB support library evolution and ABI stability?
|
||||
|
||||
No, GRDB does not support library evolution and ABI stability. The only promise is API stability according to [semantic versioning](http://semver.org), with an exception for [experimental features](#what-are-experimental-features).
|
||||
|
||||
Yet, GRDB can be built with the "Build Libraries for Distribution" Xcode option (`BUILD_LIBRARY_FOR_DISTRIBUTION`), so that you can build binary frameworks at your convenience.
|
||||
|
||||
## FAQ: Associations
|
||||
|
||||
|
||||
Reference in new issue
Block a user