Skip to content

Commit

Permalink
Rename MutablePersistable to EncodableRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Feb 27, 2018
1 parent 639de6c commit 08a08cd
Show file tree
Hide file tree
Showing 31 changed files with 491 additions and 498 deletions.
6 changes: 3 additions & 3 deletions Documentation/WhyAdoptGRDB.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ extension Place: TableRecord { ... }
let place = try Place.fetchOne(db, key: 1) // Place?
```

Add the [Persistable] protocol, and places know how to insert, update and delete themselves:
Add the [EncodableRecord] protocol, and places know how to insert, update and delete themselves:

```swift
extension Place: Persistable { ... }
extension Place: EncodableRecord { ... }
try place.delete(db)
```

Expand Down Expand Up @@ -263,7 +263,7 @@ Happy GRDB! :gift:
[FMDB]: http://github.com/ccgus/fmdb
[GRDB]: http://github.com/groue/GRDB.swift
[GRDBObjc]: http://github.com/groue/GRDBObjc
[Persistable]: https://github.com/groue/GRDB.swift/blob/master/README.md#records
[EncodableRecord]: https://github.com/groue/GRDB.swift/blob/master/README.md#records
[Realm]: http://realm.io
[DecodableRecord]: https://github.com/groue/GRDB.swift/blob/master/README.md#records
[RxGRDB]: https://github.com/RxSwiftCommunity/RxGRDB
Expand Down
112 changes: 56 additions & 56 deletions GRDB.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion GRDB/QueryInterface/QueryInterfaceRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ extension QueryInterfaceRequest where T: TableRecord {
}
}

extension QueryInterfaceRequest where RowDecoder: MutablePersistable {
extension QueryInterfaceRequest where RowDecoder: MutableEncodableRecord {

// MARK: Deleting

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
private struct PersistableKeyedEncodingContainer<Key: CodingKey> : KeyedEncodingContainerProtocol {
private struct EncodableRecordKeyedEncodingContainer<Key: CodingKey> : KeyedEncodingContainerProtocol {
let encode: (_ value: DatabaseValueConvertible?, _ key: String) -> Void

init(encode: @escaping (_ value: DatabaseValueConvertible?, _ key: String) -> Void) {
Expand Down Expand Up @@ -40,7 +40,7 @@ private struct PersistableKeyedEncodingContainer<Key: CodingKey> : KeyedEncoding
// This allows us to encode Date as String, for example.
encode((value as! DatabaseValueConvertible), key.stringValue)
} else {
try value.encode(to: PersistableEncoder(codingPath: [key], encode: encode))
try value.encode(to: EncodableRecordEncoder(codingPath: [key], encode: encode))
}
}

Expand Down Expand Up @@ -140,12 +140,12 @@ private struct DatabaseValueEncodingContainer : SingleValueEncodingContainer {
// This allows us to encode Date as String, for example.
encode(dbValueConvertible.databaseValue, key.stringValue)
} else {
try value.encode(to: PersistableEncoder(codingPath: [key], encode: encode))
try value.encode(to: EncodableRecordEncoder(codingPath: [key], encode: encode))
}
}
}

private struct PersistableEncoder : Encoder {
private struct EncodableRecordEncoder : Encoder {
/// The path of coding keys taken to get to this point in encoding.
/// A `nil` value indicates an unkeyed container.
var codingPath: [CodingKey]
Expand All @@ -171,7 +171,7 @@ private struct PersistableEncoder : Encoder {
guard codingPath.isEmpty else {
fatalError("unkeyed encoding is not supported")
}
return KeyedEncodingContainer(PersistableKeyedEncodingContainer<Key>(encode: encode))
return KeyedEncodingContainer(EncodableRecordKeyedEncodingContainer<Key>(encode: encode))
}

/// Returns an encoding container appropriate for holding multiple unkeyed values.
Expand All @@ -194,15 +194,15 @@ private struct PersistableEncoder : Encoder {
}
}

extension MutablePersistable where Self: Encodable {
extension MutableEncodableRecord where Self: Encodable {
public func encode(to container: inout PersistenceContainer) {
// 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
//
// So let's use it in a non-escaping closure:
func encode(_ encode: (_ value: DatabaseValueConvertible?, _ key: String) -> Void) {
withoutActuallyEscaping(encode) { escapableEncode in
let encoder = PersistableEncoder(codingPath: [], encode: escapableEncode)
let encoder = EncodableRecordEncoder(codingPath: [], encode: escapableEncode)
try! self.encode(to: encoder)
}
}
Expand Down
Loading

0 comments on commit 08a08cd

Please sign in to comment.