diff --git a/CHANGELOG.md b/CHANGELOG.md index db6ec11c6..6e7febb62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ Release Notes - `Record.updateChanges(_:)` now returns whether the record had unsaved changes, or not. - `Database.columns(in:)` returns information about the columns of a table. +- Improved support for joined queries: check the new [Joined Queries Support](https://github.com/groue/GRDB.swift/blob/master/README.md#joined-queries-support) documentation chapter. +- `Request.adapted(_:)` is no longer experimental. ### API diff @@ -24,12 +26,33 @@ Release Notes func columnCount(in tableName: String) throws -> Int + func columns(in tableName: String) throws -> [ColumnInfo] } - + class Record { - final func updateChanges(_ db: Database) throws + @discardableResult + final func updateChanges(_ db: Database) throws -> Bool } + + class Row { ++ var unscoped: Row ++ var containsNonNullValue: Bool ++ func hasNull(atIndex index: Int) -> Bool ++ subscript(_ scope: String) -> Record ++ subscript(_ scope: String) -> Record? + } + + extension TableMapping { ++ static func selectionSQL(alias: String? = nil) -> String ++ static func numberOfSelectedColumns(_ db: Database) throws -> Int + } + ++struct EmptyRowAdapter: RowAdapter { } + + struct ScopeAdapter { ++ init(base: RowAdapter, scopes: [String: RowAdapter]) + } + ++func splittingRowAdapters(columnCounts: [Int]) -> [RowAdapter] ``` diff --git a/GRDB/Core/Request.swift b/GRDB/Core/Request.swift index 86650ea85..4e67887fa 100644 --- a/GRDB/Core/Request.swift +++ b/GRDB/Core/Request.swift @@ -83,8 +83,6 @@ extension Request { return AnyTypedRequest(self) } - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// /// Returns an adapted request. public func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedRequest { return AdaptedRequest(self, adapter) diff --git a/README.md b/README.md index 7a19213c8..d3ce5b7c1 100644 --- a/README.md +++ b/README.md @@ -1698,6 +1698,19 @@ let adapter = RangeRowAdapter(1..<2) let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! ``` +### EmptyRowAdapter + +`EmptyRowAdapter` hides all rows. + +```swift +let adapter = EmptyRowAdapter() +let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! +row.isEmpty // true +``` + +This limit adapter may turn out useful in some narrow use cases. You'll be happy to find it when you need it. + + ### ScopeAdapter `ScopeAdapter` defines *row scopes*: @@ -1709,7 +1722,7 @@ let adapter = ScopeAdapter([ let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! ``` -ScopeAdapter does not change the columns and values of the fetched row. Instead, it defines *scopes*, which you access with the `scoped(on:)` method. It returns an optional Row, which is nil if the scope is missing. +ScopeAdapter does not change the columns and values of the fetched row. Instead, it defines *scopes*, which you access with the `Row.scoped(on:)` method. This method returns an optional Row, which is nil if the scope is missing. ```swift row // @@ -1743,8 +1756,9 @@ rightRow.scoped(on: "right") // Any adapter can be extended with scopes: ```swift -let adapter = RangeRowAdapter(0..<2) - .addingScopes(["remainder": SuffixRowAdapter(fromIndex: 2)]) +let baseAdapter = RangeRowAdapter(0..<2) +let adapter = ScopeAdapter(base: baseAdapter, scopes: [ + "remainder": SuffixRowAdapter(fromIndex: 2)]) let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! row //