Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename record protocols #314

Merged
merged 6 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,33 @@ Release Notes

### Breaking Changes

- The Record protocols have been renamed: `RowConvertible` to `FetchableRecord`, `Persistable` to `PersistableRecord`, and `TableMapping` to `TableRecord`.
- `Request` and `TypedRequest` protocols have been merged into `FetchRequest` ([311](https://github.com/groue/GRDB.swift/pull/311))
- The `IteratorCursor` type has been removed. Use `AnyCursor` instead.


### API diff

**Record protocols**

```diff
-protocol RowConvertible {
+protocol FetchableRecord {
}

-protocol TableMapping {
+protocol TableRecord {
}

-protocol MutablePersistable: TableMapping {
+protocol MutablePersistableRecord: TableRecord {
}

-protocol Persistable: MutablePersistable {
+protocol PersistableRecord: MutablePersistableRecord {
}
```

**FetchRequest**

```diff
Expand Down Expand Up @@ -60,7 +81,7 @@ Release Notes
+ func fetchOne(_ db: Database) throws -> Row?
+}

+extension FetchRequest where RowDecoder: RowConvertible {
+extension FetchRequest where RowDecoder: FetchableRecord {
+ func fetchCursor(_ db: Database) throws -> RecordCursor<RowDecoder>
+ func fetchAll(_ db: Database) throws -> [RowDecoder]
+ func fetchOne(_ db: Database) throws -> RowDecoder?
Expand Down
18 changes: 9 additions & 9 deletions Documentation/WhyAdoptGRDB.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@ struct Place {
}
```

By adopting the [RowConvertible] protocol, places can be loaded from SQL requests:
By adopting the [FetchableRecord] protocol, places can be loaded from SQL requests:

```swift
extension Place: RowConvertible { ... }
extension Place: FetchableRecord { ... }
let places = try Place.fetchAll(db, "SELECT * FROM places") // [Place]
```

Add the [TableMapping] protocol, and SQL requests are generated for you:
Add the [TableRecord] protocol, and SQL requests are generated for you:

```swift
extension Place: TableMapping { ... }
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 [PersistableRecord] protocol, and places know how to insert, update and delete themselves:

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

Expand Down Expand Up @@ -263,13 +263,13 @@ 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
[PersistableRecord]: https://github.com/groue/GRDB.swift/blob/master/README.md#records
[Realm]: http://realm.io
[RowConvertible]: https://github.com/groue/GRDB.swift/blob/master/README.md#records
[FetchableRecord]: https://github.com/groue/GRDB.swift/blob/master/README.md#records
[RxGRDB]: https://github.com/RxSwiftCommunity/RxGRDB
[RxSwift]: https://github.com/ReactiveX/RxSwift
[SQLite.swift]: http://github.com/stephencelis/SQLite.swift
[StORM]: https://www.perfect.org/docs/StORM.html
[Swift-Kuery]: http://github.com/IBM-Swift/Swift-Kuery
[TableMapping]: https://github.com/groue/GRDB.swift/blob/master/README.md#records
[TableRecord]: https://github.com/groue/GRDB.swift/blob/master/README.md#records
[TransactionObserver]: https://github.com/groue/GRDB.swift/blob/master/README.md#transactionobserver-protocol
248 changes: 124 additions & 124 deletions GRDB.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion GRDB/Core/Database+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ extension Database {
/// 2 score INTEGER 0 NULL 0
///
/// See `Database.columns(in:)` and https://www.sqlite.org/pragma.html#pragma_table_info
public struct ColumnInfo : RowConvertible {
public struct ColumnInfo : FetchableRecord {
let cid: Int

/// The column name
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Core/FetchRequest.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// The protocol for all types that define a way to fetch database content.
///
/// struct Player: RowConvertible { ... }
/// struct Player: FetchableRecord { ... }
/// let request: ... // Some FetchRequest that fetches Player
/// try request.fetchCursor(db) // Cursor of Player
/// try request.fetchAll(db) // [Player]
Expand Down
4 changes: 2 additions & 2 deletions GRDB/Core/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ extension Row {
///
/// See https://github.com/groue/GRDB.swift/blob/master/README.md#joined-queries-support
/// for more information.
public subscript<Record: RowConvertible>(_ scope: String) -> Record {
public subscript<Record: FetchableRecord>(_ scope: String) -> Record {
guard let scopedRow = scoped(on: scope) else {
// Programmer error
fatalError("no such scope: \(scope)")
Expand All @@ -498,7 +498,7 @@ extension Row {
///
/// See https://github.com/groue/GRDB.swift/blob/master/README.md#joined-queries-support
/// for more information.
public subscript<Record: RowConvertible>(_ scope: String) -> Record? {
public subscript<Record: FetchableRecord>(_ scope: String) -> Record? {
guard let scopedRow = scoped(on: scope), scopedRow.containsNonNullValue else {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions GRDB/Legacy/Fixits-0-90-1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension QueryInterfaceRequest {
public func fetch(_ db: Database) -> Any { preconditionFailure() }
}

extension RowConvertible {
extension FetchableRecord {
@available(*, unavailable, renamed:"fetchCursor")
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
@available(*, unavailable, renamed:"fetchCursor")
Expand All @@ -39,7 +39,7 @@ extension RowConvertible {
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
}

extension RowConvertible where Self: TableMapping {
extension FetchableRecord where Self: TableRecord {
@available(*, unavailable, renamed:"fetchCursor")
public static func fetch(_ db: Database) -> Any { preconditionFailure() }
@available(*, unavailable, renamed:"fetchCursor")
Expand Down
11 changes: 11 additions & 0 deletions GRDB/Legacy/Fixits-3.0.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
@available(*, unavailable, renamed:"FetchRequest")
public typealias Request = FetchRequest

@available(*, unavailable, renamed:"FetchableRecord")
public typealias RowConvertible = FetchableRecord

@available(*, unavailable, renamed:"TableRecord")
public typealias TableMapping = TableRecord

@available(*, unavailable, renamed:"MutablePersistableRecord")
public typealias MutablePersistable = MutablePersistableRecord

@available(*, unavailable, renamed:"PersistableRecord")
public typealias Persistable = PersistableRecord
6 changes: 3 additions & 3 deletions GRDB/QueryInterface/FTS3+QueryInterfaceRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension QueryInterfaceRequest {
}
}

extension TableMapping {
extension TableRecord {

// MARK: Full Text Search

Expand All @@ -35,8 +35,8 @@ extension TableMapping {
/// database row.
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func matching(_ pattern: FTS3Pattern?) -> QueryInterfaceRequest<Self> {
return all().matching(pattern)
}
Expand Down
6 changes: 3 additions & 3 deletions GRDB/QueryInterface/FTS5+QueryInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
/// database row.
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func matching(_ pattern: FTS5Pattern?) -> QueryInterfaceRequest<T> {
switch query.source {
case .table(let name, let alias)?:
Expand All @@ -31,7 +31,7 @@
}
}

extension TableMapping {
extension TableRecord {

// MARK: Full Text Search

Expand Down
66 changes: 33 additions & 33 deletions GRDB/QueryInterface/QueryInterfaceRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ extension QueryInterfaceRequest {
}
}

extension QueryInterfaceRequest where T: TableMapping {
extension QueryInterfaceRequest where T: TableRecord {

/// Creates a QueryInterfaceRequest with the provided primary key *predicate*.
///
Expand All @@ -255,8 +255,8 @@ extension QueryInterfaceRequest where T: TableMapping {
/// request = request.filter(key: 1)
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func filter<PrimaryKeyType: DatabaseValueConvertible>(key: PrimaryKeyType?) -> QueryInterfaceRequest<T> {
guard let key = key else {
return T.none()
Expand All @@ -272,8 +272,8 @@ extension QueryInterfaceRequest where T: TableMapping {
/// request = request.filter(keys: [1, 2, 3])
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func filter<Sequence: Swift.Sequence>(keys: Sequence) -> QueryInterfaceRequest<T> where Sequence.Element: DatabaseValueConvertible {
let keys = Array(keys)
let makePredicate: (Column) -> SQLExpression
Expand Down Expand Up @@ -308,8 +308,8 @@ extension QueryInterfaceRequest where T: TableMapping {
/// index on the key columns.
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func filter(key: [String: DatabaseValueConvertible?]?) -> QueryInterfaceRequest<T> {
guard let key = key else {
return T.none()
Expand All @@ -327,8 +327,8 @@ extension QueryInterfaceRequest where T: TableMapping {
/// index on the key columns.
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func filter(keys: [[String: DatabaseValueConvertible?]]) -> QueryInterfaceRequest<T> {
guard !keys.isEmpty else {
return T.none()
Expand Down Expand Up @@ -365,7 +365,7 @@ extension QueryInterfaceRequest where T: TableMapping {
}
}

extension QueryInterfaceRequest where RowDecoder: MutablePersistable {
extension QueryInterfaceRequest where RowDecoder: MutablePersistableRecord {

// MARK: Deleting

Expand All @@ -381,7 +381,7 @@ extension QueryInterfaceRequest where RowDecoder: MutablePersistable {
}
}

extension TableMapping {
extension TableRecord {

// MARK: Request Derivation

Expand All @@ -391,8 +391,8 @@ extension TableMapping {
/// let request = Player.all()
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func all() -> QueryInterfaceRequest<Self> {
let query = QueryInterfaceQuery(
select: databaseSelection,
Expand Down Expand Up @@ -435,8 +435,8 @@ extension TableMapping {
/// let request = Player.filter(Column("email") == "[email protected]")
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func filter(_ predicate: SQLExpressible) -> QueryInterfaceRequest<Self> {
return all().filter(predicate)
}
Expand All @@ -447,8 +447,8 @@ extension TableMapping {
/// let request = Player.filter(key: 1)
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func filter<PrimaryKeyType: DatabaseValueConvertible>(key: PrimaryKeyType?) -> QueryInterfaceRequest<Self> {
return all().filter(key: key)
}
Expand All @@ -459,8 +459,8 @@ extension TableMapping {
/// let request = Player.filter(keys: [1, 2, 3])
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func filter<Sequence: Swift.Sequence>(keys: Sequence) -> QueryInterfaceRequest<Self> where Sequence.Element: DatabaseValueConvertible {
return all().filter(keys: keys)
}
Expand All @@ -474,8 +474,8 @@ extension TableMapping {
/// index on the key columns.
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func filter(key: [String: DatabaseValueConvertible?]?) -> QueryInterfaceRequest<Self> {
return all().filter(key: key)
}
Expand All @@ -489,8 +489,8 @@ extension TableMapping {
/// index on the key columns.
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func filter(keys: [[String: DatabaseValueConvertible?]]) -> QueryInterfaceRequest<Self> {
return all().filter(keys: keys)
}
Expand All @@ -501,8 +501,8 @@ extension TableMapping {
/// let request = Player.filter(sql: "email = ?", arguments: ["[email protected]"])
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func filter(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> {
return all().filter(sql: sql, arguments: arguments)
}
Expand All @@ -514,8 +514,8 @@ extension TableMapping {
/// let request = Player.order(Column("name"))
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func order(_ orderings: SQLOrderingTerm...) -> QueryInterfaceRequest<Self> {
return all().order(orderings)
}
Expand All @@ -527,8 +527,8 @@ extension TableMapping {
/// let request = Player.order([Column("name")])
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func order(_ orderings: [SQLOrderingTerm]) -> QueryInterfaceRequest<Self> {
return all().order(orderings)
}
Expand All @@ -539,8 +539,8 @@ extension TableMapping {
/// let request = Player.order(sql: "name")
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func order(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> {
return all().order(sql: sql, arguments: arguments)
}
Expand All @@ -552,8 +552,8 @@ extension TableMapping {
/// let request = Player.limit(1)
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableMapping.databaseSelection` property, or
/// for individual requests with the `TableMapping.select` method.
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public static func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest<Self> {
return all().limit(limit, offset: offset)
}
Expand Down
Loading