From 75dfb4e4af53b572ed433588fece3950d2c52c35 Mon Sep 17 00:00:00 2001 From: Atulya Date: Thu, 9 Jun 2022 17:20:20 -0700 Subject: [PATCH 1/8] add decoding for UUID --- Sources/SQLite/Typed/Coding.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/SQLite/Typed/Coding.swift b/Sources/SQLite/Typed/Coding.swift index cea2565a..ca9ca055 100644 --- a/Sources/SQLite/Typed/Coding.swift +++ b/Sources/SQLite/Typed/Coding.swift @@ -387,7 +387,11 @@ private class SQLiteDecoder: Decoder { } else if type == Date.self { let date = try row.get(Expression(key.stringValue)) return date as! T + } else if type == UUID.self { + let uuid = try row.get(Expression(key.stringValue)) + return uuid as! T } + // swiftlint:enable force_cast guard let JSONString = try row.get(Expression(key.stringValue)) else { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, From 84783d370c94b15ac23e4624027d56f0735d7b5b Mon Sep 17 00:00:00 2001 From: Atulya Date: Mon, 13 Jun 2022 18:20:22 -0700 Subject: [PATCH 2/8] remove trailing whitespace for swiftlint --- Sources/SQLite/Typed/Coding.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SQLite/Typed/Coding.swift b/Sources/SQLite/Typed/Coding.swift index ca9ca055..4033365f 100644 --- a/Sources/SQLite/Typed/Coding.swift +++ b/Sources/SQLite/Typed/Coding.swift @@ -391,7 +391,7 @@ private class SQLiteDecoder: Decoder { let uuid = try row.get(Expression(key.stringValue)) return uuid as! T } - + // swiftlint:enable force_cast guard let JSONString = try row.get(Expression(key.stringValue)) else { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, From 7715f7d626261e152c5f718e0770a28d728ba632 Mon Sep 17 00:00:00 2001 From: Atulya Date: Tue, 14 Jun 2022 18:22:44 -0700 Subject: [PATCH 3/8] add tests for codable UUID --- Tests/SQLiteTests/QueryIntegrationTests.swift | 7 +-- Tests/SQLiteTests/QueryTests.swift | 44 +++++++++---------- Tests/SQLiteTests/TestHelpers.swift | 5 ++- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Tests/SQLiteTests/QueryIntegrationTests.swift b/Tests/SQLiteTests/QueryIntegrationTests.swift index 4b9c4bbf..82ee50a3 100644 --- a/Tests/SQLiteTests/QueryIntegrationTests.swift +++ b/Tests/SQLiteTests/QueryIntegrationTests.swift @@ -75,15 +75,15 @@ class QueryIntegrationTests: SQLiteTestCase { builder.column(Expression("float")) builder.column(Expression("double")) builder.column(Expression("date")) + builder.column(Expression("uuid")) builder.column(Expression("optional")) builder.column(Expression("sub")) }) let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) let value = TestCodable(int: 5, string: "6", bool: true, float: 7, double: 8, - date: Date(timeIntervalSince1970: 5000), optional: "optional", sub: value1) - + date: Date(timeIntervalSince1970: 5000), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: "optional", sub: value1) try db.run(table.insert(value)) let rows = try db.prepare(table) @@ -95,6 +95,7 @@ class QueryIntegrationTests: SQLiteTestCase { XCTAssertEqual(values[0].float, 7) XCTAssertEqual(values[0].double, 8) XCTAssertEqual(values[0].date, Date(timeIntervalSince1970: 5000)) + XCTAssertEqual(values[0].uuid, UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!) XCTAssertEqual(values[0].optional, "optional") XCTAssertEqual(values[0].sub?.int, 1) XCTAssertEqual(values[0].sub?.string, "2") diff --git a/Tests/SQLiteTests/QueryTests.swift b/Tests/SQLiteTests/QueryTests.swift index efcbab94..efaf7d15 100644 --- a/Tests/SQLiteTests/QueryTests.swift +++ b/Tests/SQLiteTests/QueryTests.swift @@ -279,12 +279,12 @@ class QueryTests: XCTestCase { func test_insert_encodable() throws { let emails = Table("emails") let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) let insert = try emails.insert(value) assertSQL( """ - INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\") - VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000') + INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\") + VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F') """.replacingOccurrences(of: "\n", with: ""), insert ) @@ -294,16 +294,16 @@ class QueryTests: XCTestCase { func test_insert_encodable_with_nested_encodable() throws { let emails = Table("emails") let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), optional: "optional", sub: value1) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: "optional", sub: value1) let insert = try emails.insert(value) let encodedJSON = try JSONEncoder().encode(value1) let encodedJSONString = String(data: encodedJSON, encoding: .utf8)! assertSQL( """ - INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"optional\", - \"sub\") VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'optional', '\(encodedJSONString)') + INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\", \"optional\", + \"sub\") VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F', 'optional', '\(encodedJSONString)') """.replacingOccurrences(of: "\n", with: ""), insert ) @@ -350,14 +350,14 @@ class QueryTests: XCTestCase { let emails = Table("emails") let string = Expression("string") let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) let insert = try emails.upsert(value, onConflictOf: string) assertSQL( """ - INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\") - VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000') ON CONFLICT (\"string\") + INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\") + VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F') ON CONFLICT (\"string\") DO UPDATE SET \"int\" = \"excluded\".\"int\", \"bool\" = \"excluded\".\"bool\", - \"float\" = \"excluded\".\"float\", \"double\" = \"excluded\".\"double\", \"date\" = \"excluded\".\"date\" + \"float\" = \"excluded\".\"float\", \"double\" = \"excluded\".\"double\", \"date\" = \"excluded\".\"date\", \"uuid\" = \"excluded\".\"uuid\" """.replacingOccurrences(of: "\n", with: ""), insert ) @@ -366,17 +366,17 @@ class QueryTests: XCTestCase { func test_insert_many_encodable() throws { let emails = Table("emails") let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) let value2 = TestCodable(int: 2, string: "3", bool: true, float: 3, double: 5, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) let value3 = TestCodable(int: 3, string: "4", bool: true, float: 3, double: 6, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) let insert = try emails.insertMany([value1, value2, value3]) assertSQL( """ - INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\") - VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000'), (2, '3', 1, 3.0, 5.0, '1970-01-01T00:00:00.000'), - (3, '4', 1, 3.0, 6.0, '1970-01-01T00:00:00.000') + INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\") + VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F'), (2, '3', 1, 3.0, 5.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F'), + (3, '4', 1, 3.0, 6.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F') """.replacingOccurrences(of: "\n", with: ""), insert ) @@ -399,12 +399,12 @@ class QueryTests: XCTestCase { func test_update_encodable() throws { let emails = Table("emails") let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) let update = try emails.update(value) assertSQL( """ UPDATE \"emails\" SET \"int\" = 1, \"string\" = '2', \"bool\" = 1, \"float\" = 3.0, \"double\" = 4.0, - \"date\" = '1970-01-01T00:00:00.000' + \"date\" = '1970-01-01T00:00:00.000', \"uuid\" = 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F' """.replacingOccurrences(of: "\n", with: ""), update ) @@ -413,9 +413,9 @@ class QueryTests: XCTestCase { func test_update_encodable_with_nested_encodable() throws { let emails = Table("emails") let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), optional: nil, sub: value1) + date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: value1) let update = try emails.update(value) // NOTE: As Linux JSON decoding doesn't order keys the same way, we need to check prefix, suffix, @@ -424,7 +424,7 @@ class QueryTests: XCTestCase { let expectedPrefix = """ UPDATE \"emails\" SET \"int\" = 1, \"string\" = '2', \"bool\" = 1, \"float\" = 3.0, \"double\" = 4.0, - \"date\" = '1970-01-01T00:00:00.000', \"sub\" = ' + \"date\" = '1970-01-01T00:00:00.000', \"uuid\" = 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F', \"sub\" = ' """.replacingOccurrences(of: "\n", with: "") let expectedSuffix = "'" diff --git a/Tests/SQLiteTests/TestHelpers.swift b/Tests/SQLiteTests/TestHelpers.swift index a6efa2e7..bc538c5b 100644 --- a/Tests/SQLiteTests/TestHelpers.swift +++ b/Tests/SQLiteTests/TestHelpers.swift @@ -115,16 +115,18 @@ class TestCodable: Codable, Equatable { let float: Float let double: Double let date: Date + let uuid: UUID let optional: String? let sub: TestCodable? - init(int: Int, string: String, bool: Bool, float: Float, double: Double, date: Date, optional: String?, sub: TestCodable?) { + init(int: Int, string: String, bool: Bool, float: Float, double: Double, date: Date, uuid: UUID, optional: String?, sub: TestCodable?) { self.int = int self.string = string self.bool = bool self.float = float self.double = double self.date = date + self.uuid = uuid self.optional = optional self.sub = sub } @@ -136,6 +138,7 @@ class TestCodable: Codable, Equatable { lhs.float == rhs.float && lhs.double == rhs.double && lhs.date == rhs.date && + lhs.uuid == lhs.uuid && lhs.optional == rhs.optional && lhs.sub == rhs.sub } From 8fece72b9be693a41d15ff20d7432bd30964610e Mon Sep 17 00:00:00 2001 From: Atulya Date: Mon, 27 Jun 2022 12:38:57 -0700 Subject: [PATCH 4/8] create a constant for the UUID used in tests --- Tests/SQLiteTests/QueryIntegrationTests.swift | 6 +++--- Tests/SQLiteTests/QueryTests.swift | 20 +++++++++---------- Tests/SQLiteTests/TestHelpers.swift | 2 ++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Tests/SQLiteTests/QueryIntegrationTests.swift b/Tests/SQLiteTests/QueryIntegrationTests.swift index 82ee50a3..b3d9cf96 100644 --- a/Tests/SQLiteTests/QueryIntegrationTests.swift +++ b/Tests/SQLiteTests/QueryIntegrationTests.swift @@ -81,9 +81,9 @@ class QueryIntegrationTests: SQLiteTestCase { }) let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let value = TestCodable(int: 5, string: "6", bool: true, float: 7, double: 8, - date: Date(timeIntervalSince1970: 5000), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: "optional", sub: value1) + date: Date(timeIntervalSince1970: 5000), uuid: testUUIDValue, optional: "optional", sub: value1) try db.run(table.insert(value)) let rows = try db.prepare(table) @@ -95,7 +95,7 @@ class QueryIntegrationTests: SQLiteTestCase { XCTAssertEqual(values[0].float, 7) XCTAssertEqual(values[0].double, 8) XCTAssertEqual(values[0].date, Date(timeIntervalSince1970: 5000)) - XCTAssertEqual(values[0].uuid, UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!) + XCTAssertEqual(values[0].uuid, testUUIDValue) XCTAssertEqual(values[0].optional, "optional") XCTAssertEqual(values[0].sub?.int, 1) XCTAssertEqual(values[0].sub?.string, "2") diff --git a/Tests/SQLiteTests/QueryTests.swift b/Tests/SQLiteTests/QueryTests.swift index efaf7d15..e4353e52 100644 --- a/Tests/SQLiteTests/QueryTests.swift +++ b/Tests/SQLiteTests/QueryTests.swift @@ -279,7 +279,7 @@ class QueryTests: XCTestCase { func test_insert_encodable() throws { let emails = Table("emails") let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let insert = try emails.insert(value) assertSQL( """ @@ -294,9 +294,9 @@ class QueryTests: XCTestCase { func test_insert_encodable_with_nested_encodable() throws { let emails = Table("emails") let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: "optional", sub: value1) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: "optional", sub: value1) let insert = try emails.insert(value) let encodedJSON = try JSONEncoder().encode(value1) let encodedJSONString = String(data: encodedJSON, encoding: .utf8)! @@ -350,7 +350,7 @@ class QueryTests: XCTestCase { let emails = Table("emails") let string = Expression("string") let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let insert = try emails.upsert(value, onConflictOf: string) assertSQL( """ @@ -366,11 +366,11 @@ class QueryTests: XCTestCase { func test_insert_many_encodable() throws { let emails = Table("emails") let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let value2 = TestCodable(int: 2, string: "3", bool: true, float: 3, double: 5, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let value3 = TestCodable(int: 3, string: "4", bool: true, float: 3, double: 6, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let insert = try emails.insertMany([value1, value2, value3]) assertSQL( """ @@ -399,7 +399,7 @@ class QueryTests: XCTestCase { func test_update_encodable() throws { let emails = Table("emails") let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let update = try emails.update(value) assertSQL( """ @@ -413,9 +413,9 @@ class QueryTests: XCTestCase { func test_update_encodable_with_nested_encodable() throws { let emails = Table("emails") let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, - date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: value1) + date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: value1) let update = try emails.update(value) // NOTE: As Linux JSON decoding doesn't order keys the same way, we need to check prefix, suffix, diff --git a/Tests/SQLiteTests/TestHelpers.swift b/Tests/SQLiteTests/TestHelpers.swift index bc538c5b..4a71fd40 100644 --- a/Tests/SQLiteTests/TestHelpers.swift +++ b/Tests/SQLiteTests/TestHelpers.swift @@ -98,6 +98,8 @@ let stringOptional = Expression("stringOptional") let uuid = Expression("uuid") let uuidOptional = Expression("uuidOptional") +let testUUIDValue = UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")! + func assertSQL(_ expression1: @autoclosure () -> String, _ expression2: @autoclosure () -> Expressible, file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(expression1(), expression2().asSQL(), file: file, line: line) From 92760e03cc71643dbb51402eb21c2dbbb59405b3 Mon Sep 17 00:00:00 2001 From: Atulya Date: Mon, 27 Jun 2022 12:51:15 -0700 Subject: [PATCH 5/8] use a switch to accommodate more types --- Sources/SQLite/Typed/Coding.swift | 166 +++++++++++++++--------------- 1 file changed, 84 insertions(+), 82 deletions(-) diff --git a/Sources/SQLite/Typed/Coding.swift b/Sources/SQLite/Typed/Coding.swift index 4033365f..e7f5b7bb 100644 --- a/Sources/SQLite/Typed/Coding.swift +++ b/Sources/SQLite/Typed/Coding.swift @@ -44,7 +44,7 @@ extension QueryType { try encodable.encode(to: encoder) return self.insert(encoder.setters + otherSetters) } - + /// Creates an `INSERT` statement by encoding the given object /// This method converts any custom nested types to JSON data and does not handle any sort /// of object relationships. If you want to support relationships between objects you will @@ -69,7 +69,7 @@ extension QueryType { try encodable.encode(to: encoder) return self.insert(or: onConflict, encoder.setters + otherSetters) } - + /// Creates a batch `INSERT` statement by encoding the array of given objects /// This method converts any custom nested types to JSON data and does not handle any sort /// of object relationships. If you want to support relationships between objects you will @@ -93,7 +93,7 @@ extension QueryType { } return self.insertMany(combinedSetters) } - + /// Creates an `INSERT ON CONFLICT DO UPDATE` statement, aka upsert, by encoding the given object /// This method converts any custom nested types to JSON data and does not handle any sort /// of object relationships. If you want to support relationships between objects you will @@ -116,7 +116,7 @@ extension QueryType { try encodable.encode(to: encoder) return self.upsert(encoder.setters + otherSetters, onConflictOf: conflicting) } - + /// Creates an `UPDATE` statement by encoding the given object /// This method converts any custom nested types to JSON data and does not handle any sort /// of object relationships. If you want to support relationships between objects you will @@ -151,7 +151,7 @@ extension Row { public func decode(userInfo: [CodingUserInfoKey: Any] = [:]) throws -> V { try V(from: decoder(userInfo: userInfo)) } - + public func decoder(userInfo: [CodingUserInfoKey: Any] = [:]) -> Decoder { SQLiteDecoder(row: self, userInfo: userInfo) } @@ -162,130 +162,131 @@ private class SQLiteEncoder: Encoder { class SQLiteKeyedEncodingContainer: KeyedEncodingContainerProtocol { // swiftlint:disable nesting typealias Key = MyKey - + let encoder: SQLiteEncoder let codingPath: [CodingKey] = [] - + init(encoder: SQLiteEncoder) { self.encoder = encoder } - + func superEncoder() -> Swift.Encoder { fatalError("SQLiteEncoding does not support super encoders") } - + func superEncoder(forKey key: Key) -> Swift.Encoder { fatalError("SQLiteEncoding does not support super encoders") } - + func encodeNil(forKey key: SQLiteEncoder.SQLiteKeyedEncodingContainer.Key) throws { encoder.setters.append(Expression(key.stringValue) <- nil) } - + func encode(_ value: Int, forKey key: SQLiteEncoder.SQLiteKeyedEncodingContainer.Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: Bool, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: Float, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- Double(value)) } - + func encode(_ value: Double, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: String, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: T, forKey key: Key) throws where T: Swift.Encodable { - if let data = value as? Data { + switch value { + case let data as Data: encoder.setters.append(Expression(key.stringValue) <- data) - } else if let date = value as? Date { + case let date as Date: encoder.setters.append(Expression(key.stringValue) <- date.datatypeValue) - } else if let uuid = value as? UUID { + case let uuid as UUID: encoder.setters.append(Expression(key.stringValue) <- uuid.datatypeValue) - } else { + default: let encoded = try JSONEncoder().encode(value) let string = String(data: encoded, encoding: .utf8) encoder.setters.append(Expression(key.stringValue) <- string) } } - + func encode(_ value: Int8, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an Int8 is not supported")) } - + func encode(_ value: Int16, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an Int16 is not supported")) } - + func encode(_ value: Int32, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an Int32 is not supported")) } - + func encode(_ value: Int64, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: UInt, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt is not supported")) } - + func encode(_ value: UInt8, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt8 is not supported")) } - + func encode(_ value: UInt16, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt16 is not supported")) } - + func encode(_ value: UInt32, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt32 is not supported")) } - + func encode(_ value: UInt64, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt64 is not supported")) } - + func nestedContainer(keyedBy keyType: NestedKey.Type, forKey key: Key) - -> KeyedEncodingContainer where NestedKey: CodingKey { + -> KeyedEncodingContainer where NestedKey: CodingKey { fatalError("encoding a nested container is not supported") } - + func nestedUnkeyedContainer(forKey key: Key) -> UnkeyedEncodingContainer { fatalError("encoding nested values is not supported") } } - + fileprivate var setters: [Setter] = [] let codingPath: [CodingKey] = [] let userInfo: [CodingUserInfoKey: Any] - + init(userInfo: [CodingUserInfoKey: Any]) { self.userInfo = userInfo } - + func singleValueContainer() -> SingleValueEncodingContainer { fatalError("not supported") } - + func unkeyedContainer() -> UnkeyedEncodingContainer { fatalError("not supported") } - + func container(keyedBy type: Key.Type) -> KeyedEncodingContainer where Key: CodingKey { KeyedEncodingContainer(SQLiteKeyedEncodingContainer(encoder: self)) } @@ -294,156 +295,157 @@ private class SQLiteEncoder: Encoder { private class SQLiteDecoder: Decoder { class SQLiteKeyedDecodingContainer: KeyedDecodingContainerProtocol { typealias Key = MyKey - + let codingPath: [CodingKey] = [] let row: Row - + init(row: Row) { self.row = row } - + var allKeys: [Key] { row.columnNames.keys.compactMap({ Key(stringValue: $0) }) } - + func contains(_ key: Key) -> Bool { row.hasValue(for: key.stringValue) } - + func decodeNil(forKey key: Key) throws -> Bool { !contains(key) } - + func decode(_ type: Bool.Type, forKey key: Key) throws -> Bool { try row.get(Expression(key.stringValue)) } - + func decode(_ type: Int.Type, forKey key: Key) throws -> Int { try row.get(Expression(key.stringValue)) } - + func decode(_ type: Int8.Type, forKey key: Key) throws -> Int8 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an Int8 is not supported")) } - + func decode(_ type: Int16.Type, forKey key: Key) throws -> Int16 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an Int16 is not supported")) } - + func decode(_ type: Int32.Type, forKey key: Key) throws -> Int32 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an Int32 is not supported")) } - + func decode(_ type: Int64.Type, forKey key: Key) throws -> Int64 { try row.get(Expression(key.stringValue)) } - + func decode(_ type: UInt.Type, forKey key: Key) throws -> UInt { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt is not supported")) - + } - + func decode(_ type: UInt8.Type, forKey key: Key) throws -> UInt8 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt8 is not supported")) } - + func decode(_ type: UInt16.Type, forKey key: Key) throws -> UInt16 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt16 is not supported")) } - + func decode(_ type: UInt32.Type, forKey key: Key) throws -> UInt32 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt32 is not supported")) } - + func decode(_ type: UInt64.Type, forKey key: Key) throws -> UInt64 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt64 is not supported")) } - + func decode(_ type: Float.Type, forKey key: Key) throws -> Float { Float(try row.get(Expression(key.stringValue))) } - + func decode(_ type: Double.Type, forKey key: Key) throws -> Double { try row.get(Expression(key.stringValue)) } - + func decode(_ type: String.Type, forKey key: Key) throws -> String { try row.get(Expression(key.stringValue)) } - + func decode(_ type: T.Type, forKey key: Key) throws -> T where T: Swift.Decodable { // swiftlint:disable force_cast - if type == Data.self { + switch type { + case is Data.Type: let data = try row.get(Expression(key.stringValue)) return data as! T - } else if type == Date.self { + case is Date.Type: let date = try row.get(Expression(key.stringValue)) return date as! T - } else if type == UUID.self { + case is UUID.Type: let uuid = try row.get(Expression(key.stringValue)) return uuid as! T + default: + // swiftlint:enable force_cast + guard let JSONString = try row.get(Expression(key.stringValue)) else { + throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, + debugDescription: "an unsupported type was found")) + } + guard let data = JSONString.data(using: .utf8) else { + throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, + debugDescription: "invalid utf8 data found")) + } + return try JSONDecoder().decode(type, from: data) } - - // swiftlint:enable force_cast - guard let JSONString = try row.get(Expression(key.stringValue)) else { - throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, - debugDescription: "an unsupported type was found")) - } - guard let data = JSONString.data(using: .utf8) else { - throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, - debugDescription: "invalid utf8 data found")) - } - return try JSONDecoder().decode(type, from: data) } - + func nestedContainer(keyedBy type: NestedKey.Type, forKey key: Key) throws - -> KeyedDecodingContainer where NestedKey: CodingKey { + -> KeyedDecodingContainer where NestedKey: CodingKey { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding nested containers is not supported")) } - + func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding unkeyed containers is not supported")) } - + func superDecoder() throws -> Swift.Decoder { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding super encoders containers is not supported")) } - + func superDecoder(forKey key: Key) throws -> Swift.Decoder { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding super decoders is not supported")) } } - + let row: Row let codingPath: [CodingKey] = [] let userInfo: [CodingUserInfoKey: Any] - + init(row: Row, userInfo: [CodingUserInfoKey: Any]) { self.row = row self.userInfo = userInfo } - + func container(keyedBy type: Key.Type) throws -> KeyedDecodingContainer where Key: CodingKey { KeyedDecodingContainer(SQLiteKeyedDecodingContainer(row: row)) } - + func unkeyedContainer() throws -> UnkeyedDecodingContainer { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an unkeyed container is not supported")) } - + func singleValueContainer() throws -> SingleValueDecodingContainer { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding a single value container is not supported")) From bc63d3ab1a154d941ac67b8c75216b625cd0efdf Mon Sep 17 00:00:00 2001 From: Atulya Date: Mon, 27 Jun 2022 12:52:36 -0700 Subject: [PATCH 6/8] swiftlint fix --- Sources/SQLite/Typed/Coding.swift | 124 +++++++++++++++--------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/Sources/SQLite/Typed/Coding.swift b/Sources/SQLite/Typed/Coding.swift index e7f5b7bb..ec2e0d6c 100644 --- a/Sources/SQLite/Typed/Coding.swift +++ b/Sources/SQLite/Typed/Coding.swift @@ -44,7 +44,7 @@ extension QueryType { try encodable.encode(to: encoder) return self.insert(encoder.setters + otherSetters) } - + /// Creates an `INSERT` statement by encoding the given object /// This method converts any custom nested types to JSON data and does not handle any sort /// of object relationships. If you want to support relationships between objects you will @@ -69,7 +69,7 @@ extension QueryType { try encodable.encode(to: encoder) return self.insert(or: onConflict, encoder.setters + otherSetters) } - + /// Creates a batch `INSERT` statement by encoding the array of given objects /// This method converts any custom nested types to JSON data and does not handle any sort /// of object relationships. If you want to support relationships between objects you will @@ -93,7 +93,7 @@ extension QueryType { } return self.insertMany(combinedSetters) } - + /// Creates an `INSERT ON CONFLICT DO UPDATE` statement, aka upsert, by encoding the given object /// This method converts any custom nested types to JSON data and does not handle any sort /// of object relationships. If you want to support relationships between objects you will @@ -116,7 +116,7 @@ extension QueryType { try encodable.encode(to: encoder) return self.upsert(encoder.setters + otherSetters, onConflictOf: conflicting) } - + /// Creates an `UPDATE` statement by encoding the given object /// This method converts any custom nested types to JSON data and does not handle any sort /// of object relationships. If you want to support relationships between objects you will @@ -151,7 +151,7 @@ extension Row { public func decode(userInfo: [CodingUserInfoKey: Any] = [:]) throws -> V { try V(from: decoder(userInfo: userInfo)) } - + public func decoder(userInfo: [CodingUserInfoKey: Any] = [:]) -> Decoder { SQLiteDecoder(row: self, userInfo: userInfo) } @@ -162,46 +162,46 @@ private class SQLiteEncoder: Encoder { class SQLiteKeyedEncodingContainer: KeyedEncodingContainerProtocol { // swiftlint:disable nesting typealias Key = MyKey - + let encoder: SQLiteEncoder let codingPath: [CodingKey] = [] - + init(encoder: SQLiteEncoder) { self.encoder = encoder } - + func superEncoder() -> Swift.Encoder { fatalError("SQLiteEncoding does not support super encoders") } - + func superEncoder(forKey key: Key) -> Swift.Encoder { fatalError("SQLiteEncoding does not support super encoders") } - + func encodeNil(forKey key: SQLiteEncoder.SQLiteKeyedEncodingContainer.Key) throws { encoder.setters.append(Expression(key.stringValue) <- nil) } - + func encode(_ value: Int, forKey key: SQLiteEncoder.SQLiteKeyedEncodingContainer.Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: Bool, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: Float, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- Double(value)) } - + func encode(_ value: Double, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: String, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: T, forKey key: Key) throws where T: Swift.Encodable { switch value { case let data as Data: @@ -216,77 +216,77 @@ private class SQLiteEncoder: Encoder { encoder.setters.append(Expression(key.stringValue) <- string) } } - + func encode(_ value: Int8, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an Int8 is not supported")) } - + func encode(_ value: Int16, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an Int16 is not supported")) } - + func encode(_ value: Int32, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an Int32 is not supported")) } - + func encode(_ value: Int64, forKey key: Key) throws { encoder.setters.append(Expression(key.stringValue) <- value) } - + func encode(_ value: UInt, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt is not supported")) } - + func encode(_ value: UInt8, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt8 is not supported")) } - + func encode(_ value: UInt16, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt16 is not supported")) } - + func encode(_ value: UInt32, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt32 is not supported")) } - + func encode(_ value: UInt64, forKey key: Key) throws { throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: "encoding an UInt64 is not supported")) } - + func nestedContainer(keyedBy keyType: NestedKey.Type, forKey key: Key) -> KeyedEncodingContainer where NestedKey: CodingKey { fatalError("encoding a nested container is not supported") } - + func nestedUnkeyedContainer(forKey key: Key) -> UnkeyedEncodingContainer { fatalError("encoding nested values is not supported") } } - + fileprivate var setters: [Setter] = [] let codingPath: [CodingKey] = [] let userInfo: [CodingUserInfoKey: Any] - + init(userInfo: [CodingUserInfoKey: Any]) { self.userInfo = userInfo } - + func singleValueContainer() -> SingleValueEncodingContainer { fatalError("not supported") } - + func unkeyedContainer() -> UnkeyedEncodingContainer { fatalError("not supported") } - + func container(keyedBy type: Key.Type) -> KeyedEncodingContainer where Key: CodingKey { KeyedEncodingContainer(SQLiteKeyedEncodingContainer(encoder: self)) } @@ -295,91 +295,91 @@ private class SQLiteEncoder: Encoder { private class SQLiteDecoder: Decoder { class SQLiteKeyedDecodingContainer: KeyedDecodingContainerProtocol { typealias Key = MyKey - + let codingPath: [CodingKey] = [] let row: Row - + init(row: Row) { self.row = row } - + var allKeys: [Key] { row.columnNames.keys.compactMap({ Key(stringValue: $0) }) } - + func contains(_ key: Key) -> Bool { row.hasValue(for: key.stringValue) } - + func decodeNil(forKey key: Key) throws -> Bool { !contains(key) } - + func decode(_ type: Bool.Type, forKey key: Key) throws -> Bool { try row.get(Expression(key.stringValue)) } - + func decode(_ type: Int.Type, forKey key: Key) throws -> Int { try row.get(Expression(key.stringValue)) } - + func decode(_ type: Int8.Type, forKey key: Key) throws -> Int8 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an Int8 is not supported")) } - + func decode(_ type: Int16.Type, forKey key: Key) throws -> Int16 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an Int16 is not supported")) } - + func decode(_ type: Int32.Type, forKey key: Key) throws -> Int32 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an Int32 is not supported")) } - + func decode(_ type: Int64.Type, forKey key: Key) throws -> Int64 { try row.get(Expression(key.stringValue)) } - + func decode(_ type: UInt.Type, forKey key: Key) throws -> UInt { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt is not supported")) - + } - + func decode(_ type: UInt8.Type, forKey key: Key) throws -> UInt8 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt8 is not supported")) } - + func decode(_ type: UInt16.Type, forKey key: Key) throws -> UInt16 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt16 is not supported")) } - + func decode(_ type: UInt32.Type, forKey key: Key) throws -> UInt32 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt32 is not supported")) } - + func decode(_ type: UInt64.Type, forKey key: Key) throws -> UInt64 { throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an UInt64 is not supported")) } - + func decode(_ type: Float.Type, forKey key: Key) throws -> Float { Float(try row.get(Expression(key.stringValue))) } - + func decode(_ type: Double.Type, forKey key: Key) throws -> Double { try row.get(Expression(key.stringValue)) } - + func decode(_ type: String.Type, forKey key: Key) throws -> String { try row.get(Expression(key.stringValue)) } - + func decode(_ type: T.Type, forKey key: Key) throws -> T where T: Swift.Decodable { // swiftlint:disable force_cast switch type { @@ -405,47 +405,47 @@ private class SQLiteDecoder: Decoder { return try JSONDecoder().decode(type, from: data) } } - + func nestedContainer(keyedBy type: NestedKey.Type, forKey key: Key) throws -> KeyedDecodingContainer where NestedKey: CodingKey { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding nested containers is not supported")) } - + func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding unkeyed containers is not supported")) } - + func superDecoder() throws -> Swift.Decoder { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding super encoders containers is not supported")) } - + func superDecoder(forKey key: Key) throws -> Swift.Decoder { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding super decoders is not supported")) } } - + let row: Row let codingPath: [CodingKey] = [] let userInfo: [CodingUserInfoKey: Any] - + init(row: Row, userInfo: [CodingUserInfoKey: Any]) { self.row = row self.userInfo = userInfo } - + func container(keyedBy type: Key.Type) throws -> KeyedDecodingContainer where Key: CodingKey { KeyedDecodingContainer(SQLiteKeyedDecodingContainer(row: row)) } - + func unkeyedContainer() throws -> UnkeyedDecodingContainer { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding an unkeyed container is not supported")) } - + func singleValueContainer() throws -> SingleValueDecodingContainer { throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "decoding a single value container is not supported")) From 3fac726365dc5813625aed56069c3b9feb446762 Mon Sep 17 00:00:00 2001 From: Atulya Date: Tue, 28 Jun 2022 12:27:52 -0700 Subject: [PATCH 7/8] silence swiftlint line_length for some sql strings --- Tests/SQLiteTests/QueryTests.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/SQLiteTests/QueryTests.swift b/Tests/SQLiteTests/QueryTests.swift index e4353e52..d9cce086 100644 --- a/Tests/SQLiteTests/QueryTests.swift +++ b/Tests/SQLiteTests/QueryTests.swift @@ -300,6 +300,7 @@ class QueryTests: XCTestCase { let insert = try emails.insert(value) let encodedJSON = try JSONEncoder().encode(value1) let encodedJSONString = String(data: encodedJSON, encoding: .utf8)! + // swiftlint:disable line_length assertSQL( """ INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\", \"optional\", @@ -307,6 +308,7 @@ class QueryTests: XCTestCase { """.replacingOccurrences(of: "\n", with: ""), insert ) + // swiftlint:enable line_length } #endif @@ -352,6 +354,7 @@ class QueryTests: XCTestCase { let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let insert = try emails.upsert(value, onConflictOf: string) + // swiftlint:disable line_length assertSQL( """ INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\") @@ -361,6 +364,7 @@ class QueryTests: XCTestCase { """.replacingOccurrences(of: "\n", with: ""), insert ) + // swiftlint:enable line_length } func test_insert_many_encodable() throws { @@ -372,6 +376,7 @@ class QueryTests: XCTestCase { let value3 = TestCodable(int: 3, string: "4", bool: true, float: 3, double: 6, date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let insert = try emails.insertMany([value1, value2, value3]) + // swiftlint:disable line_length assertSQL( """ INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\") @@ -380,6 +385,7 @@ class QueryTests: XCTestCase { """.replacingOccurrences(of: "\n", with: ""), insert ) + // swiftlint:enable line_length } func test_update_compilesUpdateExpression() { From be3a5ced7e790619f225024db1ac93795b01cf81 Mon Sep 17 00:00:00 2001 From: Atulya Date: Wed, 29 Jun 2022 09:34:32 -0700 Subject: [PATCH 8/8] remove swiftlint line_length disables --- Tests/SQLiteTests/QueryTests.swift | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Tests/SQLiteTests/QueryTests.swift b/Tests/SQLiteTests/QueryTests.swift index d9cce086..2201caef 100644 --- a/Tests/SQLiteTests/QueryTests.swift +++ b/Tests/SQLiteTests/QueryTests.swift @@ -300,15 +300,14 @@ class QueryTests: XCTestCase { let insert = try emails.insert(value) let encodedJSON = try JSONEncoder().encode(value1) let encodedJSONString = String(data: encodedJSON, encoding: .utf8)! - // swiftlint:disable line_length assertSQL( """ INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\", \"optional\", - \"sub\") VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F', 'optional', '\(encodedJSONString)') + \"sub\") VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F', + 'optional', '\(encodedJSONString)') """.replacingOccurrences(of: "\n", with: ""), insert ) - // swiftlint:enable line_length } #endif @@ -354,17 +353,16 @@ class QueryTests: XCTestCase { let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4, date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let insert = try emails.upsert(value, onConflictOf: string) - // swiftlint:disable line_length assertSQL( """ INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\") VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F') ON CONFLICT (\"string\") DO UPDATE SET \"int\" = \"excluded\".\"int\", \"bool\" = \"excluded\".\"bool\", - \"float\" = \"excluded\".\"float\", \"double\" = \"excluded\".\"double\", \"date\" = \"excluded\".\"date\", \"uuid\" = \"excluded\".\"uuid\" + \"float\" = \"excluded\".\"float\", \"double\" = \"excluded\".\"double\", \"date\" = \"excluded\".\"date\", + \"uuid\" = \"excluded\".\"uuid\" """.replacingOccurrences(of: "\n", with: ""), insert ) - // swiftlint:enable line_length } func test_insert_many_encodable() throws { @@ -376,16 +374,15 @@ class QueryTests: XCTestCase { let value3 = TestCodable(int: 3, string: "4", bool: true, float: 3, double: 6, date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil) let insert = try emails.insertMany([value1, value2, value3]) - // swiftlint:disable line_length assertSQL( """ INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\") - VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F'), (2, '3', 1, 3.0, 5.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F'), + VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F'), + (2, '3', 1, 3.0, 5.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F'), (3, '4', 1, 3.0, 6.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F') """.replacingOccurrences(of: "\n", with: ""), insert ) - // swiftlint:enable line_length } func test_update_compilesUpdateExpression() {