diff --git a/Sources/SharingGRDBTestSupport/AssertQuery.swift b/Sources/SharingGRDBTestSupport/AssertQuery.swift index 9ec1b2b8..86ca41f7 100644 --- a/Sources/SharingGRDBTestSupport/AssertQuery.swift +++ b/Sources/SharingGRDBTestSupport/AssertQuery.swift @@ -36,12 +36,10 @@ import StructuredQueriesTestSupport /// - Parameters: /// - includeSQL: Whether to snapshot the SQL fragment in addition to the results. /// - query: A statement. -/// - database: The database to read from. A value of `nil` will use +/// - database: The database to use. A value of `nil` will use /// `@Dependency(\.defaultDatabase)`. /// - sql: A snapshot of the SQL produced by the statement. /// - results: A snapshot of the results. -/// to `1` for invoking this helper directly, but if you write a wrapper function that automates -/// the `execute` trailing closure, you should pass `0` instead. /// - fileID: The source `#fileID` associated with the assertion. /// - filePath: The source `#filePath` associated with the assertion. /// - function: The source `#function` associated with the assertion @@ -52,7 +50,7 @@ import StructuredQueriesTestSupport public func assertQuery>( includeSQL: Bool = false, _ query: S, - database: (any DatabaseReader)? = nil, + database: (any DatabaseWriter)? = nil, sql: (() -> String)? = nil, results: (() -> String)? = nil, fileID: StaticString = #fileID, @@ -80,7 +78,7 @@ public func assertQuery( includeSQL: Bool = false, _ query: S, - database: (any DatabaseReader)? = nil, + database: (any DatabaseWriter)? = nil, sql: (() -> String)? = nil, results: (() -> String)? = nil, fileID: StaticString = #fileID, diff --git a/Tests/SharingGRDBTests/AssertQueryTests.swift b/Tests/SharingGRDBTests/AssertQueryTests.swift index a913e27e..bebbb987 100644 --- a/Tests/SharingGRDBTests/AssertQueryTests.swift +++ b/Tests/SharingGRDBTests/AssertQueryTests.swift @@ -41,6 +41,38 @@ struct AssertQueryTests { """ } } + @Test func assertQueryBasicUpdate() throws { + assertQuery( + Record.all + .update { $0.date = Date(timeIntervalSince1970: 45) } + .returning { ($0.id, $0.date) } + ) { + """ + ┌───┬────────────────────────────────┐ + │ 1 │ Date(1970-01-01T00:00:45.000Z) │ + │ 2 │ Date(1970-01-01T00:00:45.000Z) │ + │ 3 │ Date(1970-01-01T00:00:45.000Z) │ + └───┴────────────────────────────────┘ + """ + } + } + @Test func assertQueryRecordUpdate() throws { + assertQuery( + Record + .where { $0.id == 1 } + .update { $0.date = Date(timeIntervalSince1970: 45) } + .returning(\.self) + ) { + """ + ┌────────────────────────────────────────┐ + │ Record( │ + │ id: 1, │ + │ date: Date(1970-01-01T00:00:45.000Z) │ + │ ) │ + └────────────────────────────────────────┘ + """ + } + } #if DEBUG @Test func assertQueryBasicIncludeSQL() throws { assertQuery(