mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Reduce inlined code
This commit is contained in:
1 parent
b7c57dc7f2
commit
7f48e66fdc
3 files changed
+25
-8
No files matched your search
@@ -58,7 +58,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,
|
||||
context: RowDecodingContext,
|
||||
@@ -72,6 +71,22 @@ 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,
|
||||
sqliteStatement: SQLiteStatement,
|
||||
index: Int32,
|
||||
context: RowDecodingContext)
|
||||
-> Self
|
||||
{
|
||||
valueMismatch(
|
||||
type,
|
||||
context: context,
|
||||
databaseValue: DatabaseValue(sqliteStatement: sqliteStatement, index: index))
|
||||
}
|
||||
|
||||
/// Convenience method that builds the
|
||||
/// `could not decode <Type> from database value <value>` error message.
|
||||
@usableFromInline
|
||||
|
||||
@@ -57,8 +57,9 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
else {
|
||||
throw RowDecodingError.valueMismatch(
|
||||
Self.self,
|
||||
context: context(),
|
||||
databaseValue: DatabaseValue(sqliteStatement: sqliteStatement, index: index))
|
||||
sqliteStatement: sqliteStatement,
|
||||
index: index,
|
||||
context: context())
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -90,11 +91,11 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
return nil
|
||||
}
|
||||
guard let value = self.init(sqliteStatement: sqliteStatement, index: index) else {
|
||||
#warning("TODO: don't put the DatabaseValue in the inlined code")
|
||||
throw RowDecodingError.valueMismatch(
|
||||
Self.self,
|
||||
context: context(),
|
||||
databaseValue: DatabaseValue(sqliteStatement: sqliteStatement, index: index))
|
||||
sqliteStatement: sqliteStatement,
|
||||
index: index,
|
||||
context: context())
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -46,8 +46,9 @@ extension Data {
|
||||
guard sqlite3_column_type(sqliteStatement, Int32(index)) != SQLITE_NULL else {
|
||||
throw RowDecodingError.valueMismatch(
|
||||
Data.self,
|
||||
context: context(),
|
||||
databaseValue: DatabaseValue(sqliteStatement: sqliteStatement, index: index))
|
||||
sqliteStatement: sqliteStatement,
|
||||
index: index,
|
||||
context: context())
|
||||
}
|
||||
guard let bytes = sqlite3_column_blob(sqliteStatement, Int32(index)) else {
|
||||
return Data()
|
||||
|
||||
Reference in new issue
Block a user