mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Inline documentation
This commit is contained in:
1 parent
a8ec0530b1
commit
fdc191bbb4
2 files changed
+72
-4
No files matched your search
@@ -36,7 +36,7 @@ public protocol FetchableRecord {
|
||||
// MARK: - Decodable Support
|
||||
|
||||
/// When the FetchableRecord type also adopts the standard Decodable
|
||||
/// protocol, you can use this dictionnary to customize the decoding process
|
||||
/// protocol, you can use this dictionary to customize the decoding process
|
||||
/// from database rows.
|
||||
///
|
||||
/// For example:
|
||||
@@ -66,15 +66,15 @@ public protocol FetchableRecord {
|
||||
static var decodingUserInfo: [CodingUserInfoKey: Any] { get }
|
||||
|
||||
/// When the FetchableRecord type also adopts the standard Decodable
|
||||
/// protocol, you can use this dictionnary to customize the decoding process
|
||||
/// of nested properties stored as JSON in database columns.
|
||||
/// protocol, you can use this dictionary to customize the decoding process
|
||||
/// of nested properties from JSON database columns.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// // A key that holds a decoder's name
|
||||
/// let decoderName = CodingUserInfoKey(rawValue: "decoderName")!
|
||||
///
|
||||
/// // A Decodable record
|
||||
/// // A Decodable type
|
||||
/// struct Achievement: Decodable {
|
||||
/// init(from decoder: Decoder) throws {
|
||||
/// // Print the decoder name
|
||||
|
||||
@@ -323,7 +323,75 @@ public protocol MutablePersistableRecord : TableRecord {
|
||||
|
||||
// MARK: - Encodable Support
|
||||
|
||||
/// When the PersistableRecord type also adopts the standard Encodable
|
||||
/// protocol, you can use this dictionary to customize the encoding process
|
||||
/// to database rows.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// // A key that holds a encoder's name
|
||||
/// let encoderName = CodingUserInfoKey(rawValue: "encoderName")!
|
||||
///
|
||||
/// // A PersistableRecord + Encodable record
|
||||
/// struct Player: PersistableRecord, Encodable {
|
||||
/// // Customize the encoder name when dedoding a database row
|
||||
/// static let encodingUserInfo: [CodingUserInfoKey: Any] = [encoderName: "GRDB"]
|
||||
///
|
||||
/// func encode(to encoder: Encoder) throws {
|
||||
/// // Print the encoder name
|
||||
/// print(encoder.userInfo[encoderName])
|
||||
/// ...
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// let player = Player(...)
|
||||
///
|
||||
/// // prints "GRDB"
|
||||
/// try player.insert(db)
|
||||
///
|
||||
/// // prints "JSON"
|
||||
/// let encoder = JSONEncoder()
|
||||
/// encoder.userInfo = [encoderName: "JSON"]
|
||||
/// let data = try encoder.encode(player)
|
||||
static var encodingUserInfo: [CodingUserInfoKey: Any] { get }
|
||||
|
||||
/// When the PersistableRecord type also adopts the standard Encodable
|
||||
/// protocol, you can use this dictionary to customize the encoding process
|
||||
/// of nested properties to JSON database columns.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// // A key that holds a encoder's name
|
||||
/// let encoderName = CodingUserInfoKey(rawValue: "encoderName")!
|
||||
///
|
||||
/// // An Encodable type
|
||||
/// struct Achievement: Decodable {
|
||||
/// func encode(to encoder: Encoder) throws {
|
||||
/// // Print the encoder name
|
||||
/// print(encoder.userInfo[decoderName])
|
||||
/// ...
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// // A PersistableRecord + Encodable record
|
||||
/// struct Player: PersistableRecord, Encodable {
|
||||
/// // Achievement is stored as JSON in the "achievement" database column
|
||||
/// var achievement: Achievement
|
||||
///
|
||||
/// // Customize the decoder name when dedoding a JSON column
|
||||
/// static let JSONEncodingUserInfo: [CodingUserInfoKey: Any] = [decoderName: "JSON database column"]
|
||||
/// }
|
||||
///
|
||||
/// let achievement = Achievement(...)
|
||||
/// let player = Player(achievement: achievement)
|
||||
///
|
||||
/// // prints "JSON database column"
|
||||
/// try player.insert(db)
|
||||
///
|
||||
/// // prints "Raw JSON"
|
||||
/// let encoder = JSONEncoder()
|
||||
/// encoder.userInfo = [encoderName: "Raw JSON"]
|
||||
/// let achievementData = try encoder.encode(achievement)
|
||||
static var JSONEncodingUserInfo: [CodingUserInfoKey: Any] { get }
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user