From bffe4d32f5464a4469ef7636aedb00b09e292e3e Mon Sep 17 00:00:00 2001 From: Matt Tancock Date: Fri, 17 Apr 2020 16:16:34 +0100 Subject: [PATCH 1/6] Add Codable support to DatabaseDateComponents --- .../Foundation/DatabaseDateComponents.swift | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift index 0057f4a6f..965f67411 100644 --- a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift +++ b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift @@ -8,10 +8,10 @@ import SQLite3 #endif /// DatabaseDateComponents reads and stores DateComponents in the database. -public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnConvertible { +public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnConvertible, Codable { /// The available formats for reading and storing date components. - public enum Format: String { + public enum Format: String, Codable { /// The format "yyyy-MM-dd". case YMD = "yyyy-MM-dd" @@ -159,4 +159,31 @@ public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnC return SQLiteDateParser().components(from: string) } + + // MARK: - Codable adoption + + /// CodingKeys for codable conformance. + enum CodingKeys: String, CodingKey { + case dateComponents, format + } + + /// Creates a new instance by decoding from the given decoder. + /// + /// - parameters: + /// - decoder: The decoder to read data from. + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + dateComponents = try container.decode(DateComponents.self, forKey: .dateComponents) + format = try container.decode(Format.self, forKey: .format) + } + + /// Encodes this value into the given encoder. + /// + /// - parameters: + /// - encoder: The encoder to write data to. + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(dateComponents, forKey: .dateComponents) + try container.encode(format, forKey: .format) + } } From 18154f29bedc846dc6c1dae5ccc5494f2f3749d7 Mon Sep 17 00:00:00 2001 From: Matt Tancock Date: Mon, 20 Apr 2020 13:36:23 +0100 Subject: [PATCH 2/6] Simplify encoding format and add tests --- .../Foundation/DatabaseDateComponents.swift | 9 ++++---- .../FoundationDateComponentsTests.swift | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift index 965f67411..1963dbb1f 100644 --- a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift +++ b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift @@ -164,7 +164,7 @@ public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnC /// CodingKeys for codable conformance. enum CodingKeys: String, CodingKey { - case dateComponents, format + case date } /// Creates a new instance by decoding from the given decoder. @@ -173,8 +173,8 @@ public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnC /// - decoder: The decoder to read data from. public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - dateComponents = try container.decode(DateComponents.self, forKey: .dateComponents) - format = try container.decode(Format.self, forKey: .format) + let stringValue = try container.decode(String.self, forKey: .date) + self = DatabaseDateComponents.fromDatabaseValue(stringValue.databaseValue)! } /// Encodes this value into the given encoder. @@ -183,7 +183,6 @@ public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnC /// - encoder: The encoder to write data to. public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(dateComponents, forKey: .dateComponents) - try container.encode(format, forKey: .format) + try container.encode(String.fromDatabaseValue(databaseValue)!, forKey: .date) } } diff --git a/Tests/GRDBTests/FoundationDateComponentsTests.swift b/Tests/GRDBTests/FoundationDateComponentsTests.swift index e49b05389..aec1f882e 100644 --- a/Tests/GRDBTests/FoundationDateComponentsTests.swift +++ b/Tests/GRDBTests/FoundationDateComponentsTests.swift @@ -506,4 +506,27 @@ class FoundationDateComponentsTests : GRDBTestCase { let databaseDateComponents = DatabaseDateComponents.fromDatabaseValue("foo".databaseValue) XCTAssertTrue(databaseDateComponents == nil) } + + func testJSONEncodingOfDatabaseDateComponents() { + let year = 2018 + let month = 12 + let day = 31 + let dbDateComponents = DatabaseDateComponents( + DateComponents(year: year, month: month, day: day, hour: nil, minute: nil, second: nil, nanosecond: nil), + format: .YMD) + let encoded = try! JSONEncoder().encode(dbDateComponents) + XCTAssertEqual(String(data: encoded, encoding: .utf8)!, "{\"date\":\"\(year)-\(month)-\(day)\"}") + } + + func testJSONDecodingOfDatabaseDateComponents() { + let year = 2018 + let month = 12 + let day = 31 + let dbDateComponents = DatabaseDateComponents( + DateComponents(year: year, month: month, day: day, hour: nil, minute: nil, second: nil, nanosecond: nil), + format: .YMD) + let json = "{\"date\":\"\(year)-\(month)-\(day)\"}".data(using: .utf8)! + let decodedDatabaseDateComponents = try! JSONDecoder().decode(DatabaseDateComponents.self, from: json) + XCTAssertEqual(decodedDatabaseDateComponents.dateComponents, dbDateComponents.dateComponents) + } } From 62c6187ad41d076092404277209e49ab59bc1c33 Mon Sep 17 00:00:00 2001 From: Matt Tancock Date: Mon, 20 Apr 2020 14:42:02 +0100 Subject: [PATCH 3/6] Remove Format's Codable conformance. Use a singleValueContainer --- .../Foundation/DatabaseDateComponents.swift | 20 +++++++++---------- .../FoundationDateComponentsTests.swift | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift index 1963dbb1f..ccdcf4032 100644 --- a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift +++ b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift @@ -11,7 +11,7 @@ import SQLite3 public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnConvertible, Codable { /// The available formats for reading and storing date components. - public enum Format: String, Codable { + public enum Format: String { /// The format "yyyy-MM-dd". case YMD = "yyyy-MM-dd" @@ -162,19 +162,19 @@ public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnC // MARK: - Codable adoption - /// CodingKeys for codable conformance. - enum CodingKeys: String, CodingKey { - case date - } /// Creates a new instance by decoding from the given decoder. /// /// - parameters: /// - decoder: The decoder to read data from. public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - let stringValue = try container.decode(String.self, forKey: .date) - self = DatabaseDateComponents.fromDatabaseValue(stringValue.databaseValue)! + let container = try decoder.singleValueContainer() + let stringValue = try container.decode(String.self) + guard let decodedValue = DatabaseDateComponents.fromDatabaseValue(stringValue.databaseValue) else { + throw DecodingError.dataCorruptedError(in: container, + debugDescription: "Unable to initialise databaseDateComponent") + } + self = decodedValue } /// Encodes this value into the given encoder. @@ -182,7 +182,7 @@ public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnC /// - parameters: /// - encoder: The encoder to write data to. public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(String.fromDatabaseValue(databaseValue)!, forKey: .date) + var container = encoder.singleValueContainer() + try container.encode(String.fromDatabaseValue(databaseValue)!) } } diff --git a/Tests/GRDBTests/FoundationDateComponentsTests.swift b/Tests/GRDBTests/FoundationDateComponentsTests.swift index aec1f882e..696412109 100644 --- a/Tests/GRDBTests/FoundationDateComponentsTests.swift +++ b/Tests/GRDBTests/FoundationDateComponentsTests.swift @@ -515,7 +515,7 @@ class FoundationDateComponentsTests : GRDBTestCase { DateComponents(year: year, month: month, day: day, hour: nil, minute: nil, second: nil, nanosecond: nil), format: .YMD) let encoded = try! JSONEncoder().encode(dbDateComponents) - XCTAssertEqual(String(data: encoded, encoding: .utf8)!, "{\"date\":\"\(year)-\(month)-\(day)\"}") + XCTAssertEqual(String(data: encoded, encoding: .utf8)!, "\"\(year)-\(month)-\(day)\"") } func testJSONDecodingOfDatabaseDateComponents() { @@ -525,7 +525,7 @@ class FoundationDateComponentsTests : GRDBTestCase { let dbDateComponents = DatabaseDateComponents( DateComponents(year: year, month: month, day: day, hour: nil, minute: nil, second: nil, nanosecond: nil), format: .YMD) - let json = "{\"date\":\"\(year)-\(month)-\(day)\"}".data(using: .utf8)! + let json = "\"\(year)-\(month)-\(day)\"".data(using: .utf8)! let decodedDatabaseDateComponents = try! JSONDecoder().decode(DatabaseDateComponents.self, from: json) XCTAssertEqual(decodedDatabaseDateComponents.dateComponents, dbDateComponents.dateComponents) } From 1d760ff9ce8fd7071d4bd4867e939fd8700d3f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 22 Apr 2020 18:45:34 +0200 Subject: [PATCH 4/6] Extend congrats list --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 91e5408e3..bdcca81cd 100644 --- a/README.md +++ b/README.md @@ -8196,7 +8196,7 @@ Sample Code **Thanks** - [Pierlis](http://pierlis.com), where we write great software. -- [@alextrob](https://github.com/alextrob), [@bellebethcooper](https://github.com/bellebethcooper), [@bfad](https://github.com/bfad), [@cfilipov](https://github.com/cfilipov), [@charlesmchen-signal](https://github.com/charlesmchen-signal), [@Chiliec](https://github.com/Chiliec), [@chrisballinger](https://github.com/chrisballinger), [@darrenclark](https://github.com/darrenclark), [@davidkraus](https://github.com/davidkraus), [@fpillet](http://github.com/fpillet), [@gjeck](https://github.com/gjeck), [@gusrota](https://github.com/gusrota), [@haikusw](https://github.com/haikusw), [@hartbit](https://github.com/hartbit), [@kdubb](https://github.com/kdubb), [@kluufger](https://github.com/kluufger), [@KyleLeneau](https://github.com/KyleLeneau), [@Marus](https://github.com/Marus), [@MaxDesiatov](https://github.com/MaxDesiatov), [@michaelkirk-signal](https://github.com/michaelkirk-signal), [@pakko972](https://github.com/pakko972), [@peter-ss](https://github.com/peter-ss), [@pierlo](https://github.com/pierlo), [@pocketpixels](https://github.com/pocketpixels), [@robcas3](https://github.com/robcas3), [@runhum](https://github.com/runhum), [@schveiguy](https://github.com/schveiguy), [@SD10](https://github.com/SD10), [@sobri909](https://github.com/sobri909), [@sroddy](https://github.com/sroddy), [@swiftlyfalling](https://github.com/swiftlyfalling), [@Timac](https://github.com/Timac), [@valexa](https://github.com/valexa), and [@zmeyc](https://github.com/zmeyc) for their contributions, help, and feedback on GRDB. +- [@alextrob](https://github.com/alextrob), [@bellebethcooper](https://github.com/bellebethcooper), [@bfad](https://github.com/bfad), [@cfilipov](https://github.com/cfilipov), [@charlesmchen-signal](https://github.com/charlesmchen-signal), [@Chiliec](https://github.com/Chiliec), [@chrisballinger](https://github.com/chrisballinger), [@darrenclark](https://github.com/darrenclark), [@davidkraus](https://github.com/davidkraus), [@fpillet](http://github.com/fpillet), [@gjeck](https://github.com/gjeck), [@gusrota](https://github.com/gusrota), [@haikusw](https://github.com/haikusw), [@hartbit](https://github.com/hartbit), [@kdubb](https://github.com/kdubb), [@kluufger](https://github.com/kluufger), [@KyleLeneau](https://github.com/KyleLeneau), [@Marus](https://github.com/Marus), [@MaxDesiatov](https://github.com/MaxDesiatov), [@michaelkirk-signal](https://github.com/michaelkirk-signal), [@mtancock](https://github.com/mtancock), [@pakko972](https://github.com/pakko972), [@peter-ss](https://github.com/peter-ss), [@pierlo](https://github.com/pierlo), [@pocketpixels](https://github.com/pocketpixels), [@robcas3](https://github.com/robcas3), [@runhum](https://github.com/runhum), [@schveiguy](https://github.com/schveiguy), [@SD10](https://github.com/SD10), [@sobri909](https://github.com/sobri909), [@sroddy](https://github.com/sroddy), [@swiftlyfalling](https://github.com/swiftlyfalling), [@Timac](https://github.com/Timac), [@valexa](https://github.com/valexa), and [@zmeyc](https://github.com/zmeyc) for their contributions, help, and feedback on GRDB. - [@aymerick](https://github.com/aymerick) and [@kali](https://github.com/kali) because SQL. - [ccgus/fmdb](https://github.com/ccgus/fmdb) for its excellency. From 132d01f9f721b26ad109ae7f32388aa81c9abe89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 22 Apr 2020 19:33:31 +0200 Subject: [PATCH 5/6] Complete #766: use json objects in DatabaseDateComponents tests --- .../FoundationDateComponentsTests.swift | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Tests/GRDBTests/FoundationDateComponentsTests.swift b/Tests/GRDBTests/FoundationDateComponentsTests.swift index 696412109..f9a077316 100644 --- a/Tests/GRDBTests/FoundationDateComponentsTests.swift +++ b/Tests/GRDBTests/FoundationDateComponentsTests.swift @@ -507,26 +507,29 @@ class FoundationDateComponentsTests : GRDBTestCase { XCTAssertTrue(databaseDateComponents == nil) } - func testJSONEncodingOfDatabaseDateComponents() { - let year = 2018 - let month = 12 - let day = 31 - let dbDateComponents = DatabaseDateComponents( - DateComponents(year: year, month: month, day: day, hour: nil, minute: nil, second: nil, nanosecond: nil), - format: .YMD) - let encoded = try! JSONEncoder().encode(dbDateComponents) - XCTAssertEqual(String(data: encoded, encoding: .utf8)!, "\"\(year)-\(month)-\(day)\"") + func testJSONEncodingOfDatabaseDateComponents() throws { + // Encoding root string is not suppported by all system version: use an object + struct Record: Encodable { + var date: DatabaseDateComponents + } + let record = Record(date: DatabaseDateComponents(DateComponents(year: 2018, month: 12, day: 31), format: .YMD)) + let jsonData = try JSONEncoder().encode(record) + let json = String(data: jsonData, encoding: .utf8)! + XCTAssertEqual(json, """ + {"date":"2018-12-31"} + """) } - func testJSONDecodingOfDatabaseDateComponents() { - let year = 2018 - let month = 12 - let day = 31 - let dbDateComponents = DatabaseDateComponents( - DateComponents(year: year, month: month, day: day, hour: nil, minute: nil, second: nil, nanosecond: nil), - format: .YMD) - let json = "\"\(year)-\(month)-\(day)\"".data(using: .utf8)! - let decodedDatabaseDateComponents = try! JSONDecoder().decode(DatabaseDateComponents.self, from: json) - XCTAssertEqual(decodedDatabaseDateComponents.dateComponents, dbDateComponents.dateComponents) + func testJSONDecodingOfDatabaseDateComponents() throws { + // Decoding root string is not suppported by all system version: use an object + struct Record: Decodable { + var date: DatabaseDateComponents + } + let json = """ + {"date":"2018-12-31"} + """ + let record = try JSONDecoder().decode(Record.self, from: json.data(using: .utf8)!) + XCTAssertEqual(record.date.format, .YMD) + XCTAssertEqual(record.date.dateComponents, DateComponents(year: 2018, month: 12, day: 31)) } } From 5652a0136656e8527838f24baba223ad23d52bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 23 Apr 2020 08:55:38 +0200 Subject: [PATCH 6/6] v4.14.0 --- CHANGELOG.md | 10 ++++++++++ GRDB.swift.podspec | 2 +- Makefile | 6 +++--- README.md | 42 +++++++++++++++++++++--------------------- Support/Info.plist | 2 +- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8d821657..518c41b5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: #### 4.x Releases +- `4.14.x` Releases - [4.13.0](#4140) - `4.13.x` Releases - [4.13.0](#4130) - `4.12.x` Releases - [4.12.0](#4120) | [4.12.1](#4121) | [4.12.2](#4122) - `4.11.x` Releases - [4.11.0](#4110) @@ -70,6 +71,15 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: ## Next Release --> +## 4.14.0 + +Released April 23, 2020 • [diff](https://github.com/groue/GRDB.swift/compare/v4.13.0...v4.14.0) + +**New** + +- [#766](https://github.com/groue/GRDB.swift/pull/766) by [@mtancock](https://github.com/mtancock): Add Codable support to DatabaseDateComponents + + ## 4.13.0 Released April 15, 2020 • [diff](https://github.com/groue/GRDB.swift/compare/v4.12.2...v4.13.0) diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index f7934f5ec..c5ba90eef 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '4.13.0' + s.version = '4.14.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/Makefile b/Makefile index 96044008a..39f3d99f3 100644 --- a/Makefile +++ b/Makefile @@ -466,10 +466,10 @@ ifdef JAZZY --author 'Gwendal Roué' \ --author_url https://github.com/groue \ --github_url https://github.com/groue/GRDB.swift \ - --github-file-prefix https://github.com/groue/GRDB.swift/tree/v4.13.0 \ - --module-version 4.13.0 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v4.14.0 \ + --module-version 4.14.0 \ --module GRDB \ - --root-url http://groue.github.io/GRDB.swift/docs/4.13/ \ + --root-url http://groue.github.io/GRDB.swift/docs/4.14/ \ --output Documentation/Reference \ --xcodebuild-arguments -project,GRDB.xcodeproj,-scheme,GRDBiOS else diff --git a/README.md b/README.md index bdcca81cd..3cf877ceb 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,14 @@ --- -**Latest release**: April 15, 2020 • version 4.13.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 3 to GRDB 4](Documentation/GRDB3MigrationGuide.md) +**Latest release**: April 23, 2020 • version 4.14.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 3 to GRDB 4](Documentation/GRDB3MigrationGuide.md) **Requirements**: iOS 9.0+ / macOS 10.9+ / tvOS 9.0+ / watchOS 2.0+ • Swift 4.2+ / Xcode 10.0+ | Swift version | GRDB version | | ------------- | ----------------------------------------------------------- | -| **Swift 5** | **v4.13.0** | -| **Swift 4.2** | **v4.13.0** | +| **Swift 5** | **v4.14.0** | +| **Swift 4.2** | **v4.14.0** | | Swift 4.1 | [v3.7.0](https://github.com/groue/GRDB.swift/tree/v3.7.0) | | Swift 4 | [v2.10.0](https://github.com/groue/GRDB.swift/tree/v2.10.0) | | Swift 3.2 | [v1.3.0](https://github.com/groue/GRDB.swift/tree/v1.3.0) | @@ -263,7 +263,7 @@ Documentation #### Reference -- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/4.13/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) +- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/4.14/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) #### Getting Started @@ -478,7 +478,7 @@ let dbQueue = try DatabaseQueue( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/4.13/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/4.14/Structs/Configuration.html) for more details. ## Database Pools @@ -559,7 +559,7 @@ let dbPool = try DatabasePool( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/4.13/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/4.14/Structs/Configuration.html) for more details. Database pools are more memory-hungry than database queues. See [Memory Management](#memory-management) for more information. @@ -619,7 +619,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.14/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. In Swift 5, you can embed query arguments right into your SQL queries, with the `literal` argument label, as in the example below. See [SQL Interpolation] for more details. @@ -820,7 +820,7 @@ Both arrays and cursors can iterate over database results. How do you choose one - **Cursors are granted with direct access to SQLite,** unlike arrays that have to take the time to copy database values. If you look after extra performance, you may prefer cursors over arrays. -- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/4.13/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: +- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/4.14/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: ```swift // Prints all Github links @@ -902,7 +902,7 @@ let rows = try Row.fetchAll(db, arguments: ["name": "Arthur"]) ``` -See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.14/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. Unlike row arrays that contain copies of the database rows, row cursors are close to the SQLite metal, and require a little care: @@ -1185,7 +1185,7 @@ GRDB ships with built-in support for the following value types: - Generally speaking, all types that adopt the [DatabaseValueConvertible](#custom-value-types) protocol. -Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html): +Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/4.14/Structs/StatementArguments.html): ```swift let url: URL = ... @@ -1592,7 +1592,7 @@ try dbQueue.inDatabase { db in // or dbPool.writeWithoutTransaction } ``` -Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/4.13/Structs/Configuration.html) configuration flag: +Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/4.14/Structs/Configuration.html) configuration flag: ```swift // fatal error: A transaction has been left opened at the end of a database access @@ -1706,7 +1706,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). +The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.14/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). ```swift updateStatement.arguments = ["name": "Arthur", "score": 1000] @@ -1965,7 +1965,7 @@ row["consumed"] // "Hello" row["produced"] // nil ``` -Row adapters are values that adopt the [RowAdapter](http://groue.github.io/GRDB.swift/docs/4.13/Protocols/RowAdapter.html) protocol. You can implement your own custom adapters ([**:fire: EXPERIMENTAL**](#what-are-experimental-features)), or use one of the four built-in adapters, described below. +Row adapters are values that adopt the [RowAdapter](http://groue.github.io/GRDB.swift/docs/4.14/Protocols/RowAdapter.html) protocol. You can implement your own custom adapters ([**:fire: EXPERIMENTAL**](#what-are-experimental-features)), or use one of the four built-in adapters, described below. To see how row adapters can be used, see [Joined Queries Support](#joined-queries-support). @@ -2427,7 +2427,7 @@ try Place.fetchAll(db, sql: "SELECT ...", arguments:...) // [Place] try Place.fetchOne(db, sql: "SELECT ...", arguments:...) // Place? ``` -See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html) for more information about the query arguments. +See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.14/Structs/StatementArguments.html) for more information about the query arguments. > :point_up: **Note**: for performance reasons, the same row argument to `init(row:)` is reused during the iteration of a fetch query. If you want to keep the row for later use, make sure to store a copy: `self.row = row.copy()`. @@ -2808,7 +2808,7 @@ protocol EncodableRecord { } ``` -See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/4.13/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.13/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.13/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/4.14/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.14/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.14/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. > :point_up: **Note**: there is no customization of uuid decoding, because UUID can already decode all its encoded variants (16-bytes blobs, and uuid strings). @@ -4197,7 +4197,7 @@ Player // SELECT * FROM player ``` -Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html): +Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/4.14/Structs/StatementArguments.html): ```swift // SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate) @@ -4815,7 +4815,7 @@ let request = Player.all() **To build custom requests**, you can use one of the built-in requests, derive requests from other requests, or create your own request type that adopts the [FetchRequest](#fetchrequest-protocol) protocol. -- [SQLRequest](http://groue.github.io/GRDB.swift/docs/4.13/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: +- [SQLRequest](http://groue.github.io/GRDB.swift/docs/4.14/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: ```swift extension Player { @@ -4859,7 +4859,7 @@ let request = Player.all() - The `adapted(_:)` method eases the consumption of complex rows with [row adapters](#row-adapters). See [Joined Queries Support](#joined-queries-support) for some sample code that uses this method. -- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/4.13/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request. +- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/4.14/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request. ### Fetching From Custom Requests @@ -6404,7 +6404,7 @@ After `stopObservingDatabaseChangesUntilNextTransaction()`, the `databaseDidChan ### DatabaseRegion -**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/4.13/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. +**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/4.14/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. A request knows which database modifications can impact its results. It can communicate this information to [transaction observers](#transactionobserver-protocol) by the way of a DatabaseRegion. @@ -6414,7 +6414,7 @@ DatabaseRegion fuels, for example, [ValueObservation and DatabaseRegionObservati For example, if you observe the region of `Player.select(max(Column("score")))`, then you'll get be notified of all changes performed on the `score` column of the `player` table (updates, insertions and deletions), even if they do not modify the value of the maximum score. However, you will not get any notification for changes performed on other database tables, or updates to other columns of the player table. -For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/4.13/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). +For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/4.14/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). #### The DatabaseRegionConvertible Protocol @@ -7512,7 +7512,7 @@ try snapshot2.read { db in ### DatabaseWriter and DatabaseReader Protocols -Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/4.13/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/4.13/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. +Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/4.14/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/4.14/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. These protocols provide a unified API that let you write generic code that targets all concurrency modes. They fuel, for example: diff --git a/Support/Info.plist b/Support/Info.plist index b8315a49b..9e1700b71 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.13.0 + 4.14.0 CFBundleSignature ???? CFBundleVersion