mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
Cleanup
This commit is contained in:
1 parent
7a3321a5ed
commit
ba7cd4f61d
8 files changed
+41
-41
No files matched your search
+2
-2
@@ -29,12 +29,12 @@ Release Notes
|
||||
|
||||
protocol FetchableRecord {
|
||||
+ static var databaseDecodingUserInfo: [CodingUserInfoKey: Any] { get }
|
||||
+ static func makeDatabaseJSONDecoder(for column: String) -> JSONDecoder
|
||||
+ static func databaseJSONDecoder(for column: String) -> JSONDecoder
|
||||
}
|
||||
|
||||
protocol MutablePersistableRecord: TableRecord {
|
||||
+ static var databaseEncodingUserInfo: [CodingUserInfoKey: Any] { get }
|
||||
+ static func makeDatabaseJSONEncoder(for column: String) -> JSONEncoder
|
||||
+ static func databaseJSONEncoder(for column: String) -> JSONEncoder
|
||||
}
|
||||
|
||||
+final class FastDatabaseValueCursor<Value: DatabaseValueConvertible & StatementColumnConvertible> : Cursor { }
|
||||
|
||||
@@ -98,7 +98,7 @@ private struct RowKeyedDecodingContainer<Key: CodingKey>: KeyedDecodingContainer
|
||||
fatalConversionError(to: T.self, from: row[index], conversionContext: ValueConversionContext(row).atColumn(index))
|
||||
}
|
||||
return try decoder
|
||||
.makeJSONDecoder(keyName)
|
||||
.JSONDecoder(keyName)
|
||||
.decode(type.self, from: data)
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ private struct RowKeyedDecodingContainer<Key: CodingKey>: KeyedDecodingContainer
|
||||
row: scopedRow,
|
||||
codingPath: codingPath + [key],
|
||||
userInfo: decoder.userInfo,
|
||||
makeJSONDecoder: decoder.makeJSONDecoder)
|
||||
JSONDecoder: decoder.JSONDecoder)
|
||||
return try T(from: scopedDecoder)
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ private struct RowKeyedDecodingContainer<Key: CodingKey>: KeyedDecodingContainer
|
||||
fatalConversionError(to: T.self, from: row[index], conversionContext: ValueConversionContext(row).atColumn(index))
|
||||
}
|
||||
return try decoder
|
||||
.makeJSONDecoder(keyName)
|
||||
.JSONDecoder(keyName)
|
||||
.decode(type.self, from: data)
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ private struct RowKeyedDecodingContainer<Key: CodingKey>: KeyedDecodingContainer
|
||||
row: scopedRow,
|
||||
codingPath: codingPath + [key],
|
||||
userInfo: decoder.userInfo,
|
||||
makeJSONDecoder: decoder.makeJSONDecoder)
|
||||
JSONDecoder: decoder.JSONDecoder)
|
||||
return try T(from: scopedDecoder)
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,7 @@ private struct RowKeyedDecodingContainer<Key: CodingKey>: KeyedDecodingContainer
|
||||
row: row,
|
||||
codingPath: codingPath + [key],
|
||||
userInfo: decoder.userInfo,
|
||||
makeJSONDecoder: decoder.makeJSONDecoder)
|
||||
JSONDecoder: decoder.JSONDecoder)
|
||||
return try T(from: baseDecoder)
|
||||
}
|
||||
}
|
||||
@@ -302,7 +302,7 @@ private struct RowDecoder: Decoder {
|
||||
var row: Row
|
||||
var codingPath: [CodingKey]
|
||||
var userInfo: [CodingUserInfoKey: Any]
|
||||
var makeJSONDecoder: (String) -> JSONDecoder
|
||||
var JSONDecoder: (String) -> JSONDecoder
|
||||
|
||||
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
|
||||
return KeyedDecodingContainer(RowKeyedDecodingContainer<Key>(decoder: self))
|
||||
@@ -350,7 +350,7 @@ extension FetchableRecord where Self: Decodable {
|
||||
row: row,
|
||||
codingPath: [],
|
||||
userInfo: Self.databaseDecodingUserInfo,
|
||||
makeJSONDecoder: Self.makeDatabaseJSONDecoder)
|
||||
JSONDecoder: Self.databaseJSONDecoder)
|
||||
try! self.init(from: decoder)
|
||||
}
|
||||
}
|
||||
@@ -88,13 +88,13 @@ public protocol FetchableRecord {
|
||||
/// // stored in a JSON column
|
||||
/// var achievements: [Achievement]
|
||||
///
|
||||
/// static func makeDatabaseJSONDecoder(for column: String) -> JSONDecoder {
|
||||
/// static func databaseJSONDecoder(for column: String) -> JSONDecoder {
|
||||
/// let decoder = JSONDecoder()
|
||||
/// decoder.dateDecodingStrategy = .iso8601
|
||||
/// return decoder
|
||||
/// }
|
||||
/// }
|
||||
static func makeDatabaseJSONDecoder(for column: String) -> JSONDecoder
|
||||
static func databaseJSONDecoder(for column: String) -> JSONDecoder
|
||||
}
|
||||
|
||||
extension FetchableRecord {
|
||||
@@ -107,7 +107,7 @@ extension FetchableRecord {
|
||||
/// - dataDecodingStrategy: .base64
|
||||
/// - dateDecodingStrategy: .millisecondsSince1970
|
||||
/// - nonConformingFloatDecodingStrategy: .throw
|
||||
public static func makeDatabaseJSONDecoder(for column: String) -> JSONDecoder {
|
||||
public static func databaseJSONDecoder(for column: String) -> JSONDecoder {
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
decoder.dateDecodingStrategy = .millisecondsSince1970
|
||||
|
||||
@@ -3,16 +3,16 @@ import Foundation
|
||||
private struct PersistableRecordKeyedEncodingContainer<Key: CodingKey> : KeyedEncodingContainerProtocol {
|
||||
let encode: DatabaseValuePersistenceEncoder
|
||||
var userInfo: [CodingUserInfoKey: Any]
|
||||
var makeJSONEncoder: (String) -> JSONEncoder
|
||||
var JSONEncoder: (String) -> JSONEncoder
|
||||
|
||||
init(
|
||||
encode: @escaping DatabaseValuePersistenceEncoder,
|
||||
userInfo: [CodingUserInfoKey: Any],
|
||||
makeJSONEncoder: @escaping (String) -> JSONEncoder)
|
||||
JSONEncoder: @escaping (String) -> JSONEncoder)
|
||||
{
|
||||
self.encode = encode
|
||||
self.userInfo = userInfo
|
||||
self.makeJSONEncoder = makeJSONEncoder
|
||||
self.JSONEncoder = JSONEncoder
|
||||
}
|
||||
|
||||
/// The path of coding keys taken to get to this point in encoding.
|
||||
@@ -59,11 +59,11 @@ private struct PersistableRecordKeyedEncodingContainer<Key: CodingKey> : KeyedEn
|
||||
key: key,
|
||||
encode: encode,
|
||||
userInfo: userInfo,
|
||||
makeJSONEncoder: makeJSONEncoder)
|
||||
JSONEncoder: JSONEncoder)
|
||||
try value.encode(to: encoder)
|
||||
} catch is JSONRequiredError {
|
||||
// Encode to JSON
|
||||
let jsonData = try makeJSONEncoder(key.stringValue).encode(value)
|
||||
let jsonData = try JSONEncoder(key.stringValue).encode(value)
|
||||
|
||||
// Store JSON String in the database for easier debugging and
|
||||
// database inspection. Thanks to SQLite weak typing, we won't
|
||||
@@ -134,18 +134,18 @@ private struct DatabaseValueEncodingContainer : SingleValueEncodingContainer {
|
||||
var key: CodingKey
|
||||
var encode: DatabaseValuePersistenceEncoder
|
||||
var userInfo: [CodingUserInfoKey: Any]
|
||||
var makeJSONEncoder: (String) -> JSONEncoder
|
||||
var JSONEncoder: (String) -> JSONEncoder
|
||||
|
||||
init(
|
||||
key: CodingKey,
|
||||
encode: @escaping DatabaseValuePersistenceEncoder,
|
||||
userInfo: [CodingUserInfoKey: Any],
|
||||
makeJSONEncoder: @escaping (String) -> JSONEncoder)
|
||||
JSONEncoder: @escaping (String) -> JSONEncoder)
|
||||
{
|
||||
self.key = key
|
||||
self.encode = encode
|
||||
self.userInfo = userInfo
|
||||
self.makeJSONEncoder = makeJSONEncoder
|
||||
self.JSONEncoder = JSONEncoder
|
||||
}
|
||||
|
||||
/// Encodes a null value.
|
||||
@@ -194,11 +194,11 @@ private struct DatabaseValueEncodingContainer : SingleValueEncodingContainer {
|
||||
key: key,
|
||||
encode: encode,
|
||||
userInfo: userInfo,
|
||||
makeJSONEncoder: makeJSONEncoder)
|
||||
JSONEncoder: JSONEncoder)
|
||||
try value.encode(to: encoder)
|
||||
} catch is JSONRequiredError {
|
||||
// Encode to JSON
|
||||
let jsonData = try makeJSONEncoder(key.stringValue).encode(value)
|
||||
let jsonData = try JSONEncoder(key.stringValue).encode(value)
|
||||
|
||||
// Store JSON String in the database for easier debugging and
|
||||
// database inspection. Thanks to SQLite weak typing, we won't
|
||||
@@ -217,18 +217,18 @@ private struct DatabaseValueEncoder: Encoder {
|
||||
var key: CodingKey
|
||||
var encode: DatabaseValuePersistenceEncoder
|
||||
var userInfo: [CodingUserInfoKey: Any]
|
||||
var makeJSONEncoder: (String) -> JSONEncoder
|
||||
var JSONEncoder: (String) -> JSONEncoder
|
||||
|
||||
init(
|
||||
key: CodingKey,
|
||||
encode: @escaping DatabaseValuePersistenceEncoder,
|
||||
userInfo: [CodingUserInfoKey: Any],
|
||||
makeJSONEncoder: @escaping (String) -> JSONEncoder)
|
||||
JSONEncoder: @escaping (String) -> JSONEncoder)
|
||||
{
|
||||
self.key = key
|
||||
self.encode = encode
|
||||
self.userInfo = userInfo
|
||||
self.makeJSONEncoder = makeJSONEncoder
|
||||
self.JSONEncoder = JSONEncoder
|
||||
}
|
||||
|
||||
func container<Key>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> where Key : CodingKey {
|
||||
@@ -254,7 +254,7 @@ private struct DatabaseValueEncoder: Encoder {
|
||||
key: key,
|
||||
encode: encode,
|
||||
userInfo: userInfo,
|
||||
makeJSONEncoder: makeJSONEncoder)
|
||||
JSONEncoder: JSONEncoder)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,23 +262,23 @@ private struct PersistableRecordEncoder: Encoder {
|
||||
var codingPath: [CodingKey] = []
|
||||
var encode: DatabaseValuePersistenceEncoder
|
||||
var userInfo: [CodingUserInfoKey: Any]
|
||||
var makeJSONEncoder: (String) -> JSONEncoder
|
||||
var JSONEncoder: (String) -> JSONEncoder
|
||||
|
||||
init(
|
||||
encode: @escaping DatabaseValuePersistenceEncoder,
|
||||
userInfo: [CodingUserInfoKey: Any],
|
||||
makeJSONEncoder: @escaping (String) -> JSONEncoder)
|
||||
JSONEncoder: @escaping (String) -> JSONEncoder)
|
||||
{
|
||||
self.encode = encode
|
||||
self.userInfo = userInfo
|
||||
self.makeJSONEncoder = makeJSONEncoder
|
||||
self.JSONEncoder = JSONEncoder
|
||||
}
|
||||
|
||||
func container<Key>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> {
|
||||
return KeyedEncodingContainer(PersistableRecordKeyedEncodingContainer<Key>(
|
||||
encode: encode,
|
||||
userInfo: userInfo,
|
||||
makeJSONEncoder: makeJSONEncoder))
|
||||
JSONEncoder: JSONEncoder))
|
||||
}
|
||||
|
||||
func unkeyedContainer() -> UnkeyedEncodingContainer {
|
||||
@@ -424,7 +424,7 @@ private typealias DatabaseValuePersistenceEncoder = (_ value: DatabaseValueConve
|
||||
extension MutablePersistableRecord where Self: Encodable {
|
||||
public func encode(to container: inout PersistenceContainer) {
|
||||
let userInfo = Self.databaseEncodingUserInfo
|
||||
let makeJSONEncoder = Self.makeDatabaseJSONEncoder
|
||||
let JSONEncoder = Self.databaseJSONEncoder
|
||||
|
||||
// The inout container parameter won't enter an escaping closure since
|
||||
// SE-0035: https://github.com/apple/swift-evolution/blob/master/proposals/0035-limit-inout-capture.md
|
||||
@@ -435,7 +435,7 @@ extension MutablePersistableRecord where Self: Encodable {
|
||||
let encoder = PersistableRecordEncoder(
|
||||
encode: escapableEncode,
|
||||
userInfo: userInfo,
|
||||
makeJSONEncoder: makeJSONEncoder)
|
||||
JSONEncoder: JSONEncoder)
|
||||
try! self.encode(to: encoder)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,13 +380,13 @@ public protocol MutablePersistableRecord : TableRecord {
|
||||
/// // stored in a JSON column
|
||||
/// var achievements: [Achievement]
|
||||
///
|
||||
/// static func makeDatabaseJSONEncoder(for column: String) -> JSONEncoder {
|
||||
/// static func databaseJSONEncoder(for column: String) -> JSONEncoder {
|
||||
/// let encoder = JSONEncoder()
|
||||
/// encoder.dateEncodingStrategy = .iso8601
|
||||
/// return encoder
|
||||
/// }
|
||||
/// }
|
||||
static func makeDatabaseJSONEncoder(for column: String) -> JSONEncoder
|
||||
static func databaseJSONEncoder(for column: String) -> JSONEncoder
|
||||
}
|
||||
|
||||
extension MutablePersistableRecord {
|
||||
@@ -400,7 +400,7 @@ extension MutablePersistableRecord {
|
||||
/// - dateEncodingStrategy: .millisecondsSince1970
|
||||
/// - nonConformingFloatEncodingStrategy: .throw
|
||||
/// - outputFormatting: .sortedKeys (iOS 11.0+, macOS 10.13+, watchOS 4.0+)
|
||||
public static func makeDatabaseJSONEncoder(for column: String) -> JSONEncoder {
|
||||
public static func databaseJSONEncoder(for column: String) -> JSONEncoder {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.dataEncodingStrategy = .base64
|
||||
encoder.dateEncodingStrategy = .millisecondsSince1970
|
||||
|
||||
@@ -2667,11 +2667,11 @@ You can customize the JSON format by implementing those methods:
|
||||
|
||||
```swift
|
||||
protocol FetchableRecord {
|
||||
static func makeDatabaseJSONDecoder(for column: String) -> JSONDecoder
|
||||
static func databaseJSONDecoder(for column: String) -> JSONDecoder
|
||||
}
|
||||
|
||||
protocol MutablePersistableRecord {
|
||||
static func makeDatabaseJSONEncoder(for column: String) -> JSONEncoder
|
||||
static func databaseJSONEncoder(for column: String) -> JSONEncoder
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2683,13 +2683,13 @@ struct Player: Codable, FetchableRecord, PersistableRecord {
|
||||
var score: Int
|
||||
var achievements: [Achievement] // stored in a JSON column
|
||||
|
||||
static func makeDatabaseJSONDecoder(for column: String) -> JSONDecoder {
|
||||
static func databaseJSONDecoder(for column: String) -> JSONDecoder {
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
return decoder
|
||||
}
|
||||
|
||||
static func makeDatabaseJSONEncoder(for column: String) -> JSONEncoder {
|
||||
static func databaseJSONEncoder(for column: String) -> JSONEncoder {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.dateEncodingStrategy = .iso8601
|
||||
encoder.outputFormatting = .sortedKeys
|
||||
|
||||
@@ -844,7 +844,7 @@ extension FetchableRecordDecodableTests {
|
||||
testKeyRoot: "GRDB root",
|
||||
testKeyNested: "GRDB column or scope"]
|
||||
|
||||
static func makeJSONDecoder(for column: String) -> JSONDecoder {
|
||||
static func databaseJSONDecoder(for column: String) -> JSONDecoder {
|
||||
let decoder = JSONDecoder()
|
||||
decoder.userInfo = [
|
||||
testKeyRoot: "JSON root",
|
||||
|
||||
@@ -570,7 +570,7 @@ extension MutablePersistableRecordEncodableTests {
|
||||
testKeyRoot: "GRDB root",
|
||||
testKeyNested: "GRDB nested"]
|
||||
|
||||
static func makeJSONEncoder(for column: String) -> JSONEncoder {
|
||||
static func databaseJSONEncoder(for column: String) -> JSONEncoder {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = .sortedKeys
|
||||
encoder.userInfo = [
|
||||
|
||||
Reference in new issue
Block a user