Skip to content

Commit af3e4b1

Browse files
committed
updated tests
1 parent 6bf1caa commit af3e4b1

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

Sources/Compiler/Gen/SwiftLanguage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public struct SwiftLanguage: Language2 {
109109
) throws -> DeclSyntax {
110110
let inputTypeName = inputTypeName(for: query)
111111
let outputTypeName = outputTypeName(for: query)
112-
let queryTypeName = "DatabaseQuery<\(inputTypeName), \(outputTypeName)>"
112+
let queryTypeName = "any DatabaseQuery<\(inputTypeName), \(outputTypeName)>"
113113

114114
let query = try VariableDeclSyntax("var \(raw: query.name): \(raw: queryTypeName)") {
115115
FunctionCallExprSyntax(

Sources/Feather/Queryable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public struct DatabaseQueryImpl<Input, Output>: DatabaseQuery
4444
public let execute: @Sendable (Input, borrowing Transaction) throws -> Output
4545

4646
public init(
47+
_ transactionKind: TransactionKind,
4748
database: any Database,
48-
tx: TransactionKind,
4949
execute: @escaping @Sendable (Input, borrowing Transaction) throws -> Output
5050
) {
5151
self.database = database
52-
self.transactionKind = tx
52+
self.transactionKind = transactionKind
5353
self.execute = execute
5454
}
5555

Tests/FeatherTests/QueryTests.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ import Testing
1313
struct QueryTests {
1414
@Test func testQuery() async throws {
1515
let pool = try createDatabase()
16+
let insert = insertQuery(database: pool)
1617

1718
let foo1 = Foo(bar: 1, baz: "bar1")
1819
let foo2 = Foo(bar: 2, baz: "bar2")
1920
let foo3 = Foo(bar: 3, baz: "bar3")
2021

21-
try await insert.execute(with: foo1, in: pool)
22-
try await insert.execute(with: foo2, in: pool)
23-
try await insert.execute(with: foo3, in: pool)
22+
try await insert.execute(with: foo1)
23+
try await insert.execute(with: foo2)
24+
try await insert.execute(with: foo3)
2425

25-
let foos = try await selectAllFoo.execute(in: pool)
26+
let foos = try await selectAllFooQuery(database: pool).execute()
2627

2728
#expect(foos.count == 3)
2829
}
@@ -53,22 +54,26 @@ struct QueryTests {
5354
}
5455
}
5556

56-
private var selectAllFoo: FetchManyQuery<(), [Foo]> {
57-
return FetchManyQuery<(), [Foo]>(.read) { input, transaction in
58-
try Statement(in: transaction) {
57+
private func selectAllFooQuery(database: any Database) -> any DatabaseQuery<(), [Foo]> {
58+
return DatabaseQueryImpl<(), [Foo]>(.read, database: database) { input, transaction in
59+
let statement = try Statement(in: transaction) {
5960
"SELECT * FROM foo;"
6061
}
62+
63+
return try statement.fetchAll(of: Foo.self)
6164
}
6265
}
6366

64-
private var insert: VoidQuery<Foo> {
65-
return VoidQuery<Foo>(.write) { input, transaction in
66-
try Statement(in: transaction) {
67+
private func insertQuery(database: any Database) -> any DatabaseQuery<Foo, ()> {
68+
return DatabaseQueryImpl<Foo, ()>(.write, database: database) { input, transaction in
69+
let statement = try Statement(in: transaction) {
6770
"INSERT INTO foo (bar, baz) VALUES (?, ?)"
6871
} bind: { statement in
6972
try statement.bind(value: input.bar, to: 1)
7073
try statement.bind(value: input.baz, to: 2)
7174
}
75+
76+
_ = try statement.step()
7277
}
7378
}
7479

0 commit comments

Comments
 (0)