Reduce inlined code

This commit is contained in:
Gwendal Roué committed 2021-02-26 18:50:47 +01:00
1 parent b7c57dc7f2
commit 7f48e66fdc
3 files changed
+25 -8

No files matched your search

+16 -1
View File
@@ -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
+6 -5
View File
@@ -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
}
+3 -2
View File
@@ -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()