Skip to content

Commit ecec11c

Browse files
committed
actually test the thing
1 parent b23d40c commit ecec11c

File tree

1 file changed

+21
-29
lines changed
  • Sources/PreparedStatementsPostgresNIOClient

1 file changed

+21
-29
lines changed

Sources/PreparedStatementsPostgresNIOClient/main.swift

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@ import PreparedStatementsPostgresNIO
22
import PostgresNIO
33
import Foundation
44

5-
@Statement("SELECT \("id", UUID.self), \("name", String.self), \("age", Int.self) FROM users WHERE \(bind: "age", Int.self) > age")
6-
struct MyPreparedStatement {}
5+
let logger = Logger(label: "test")
76

8-
struct MyPreparedStatementOldWay: PostgresPreparedStatement {
9-
func decodeRow(_ row: PostgresRow) throws -> Row {
10-
let (v1, v2, v3) = try row.decode((UUID, String, Int).self)
11-
return Row(id: v1, name: v2, age: v3)
12-
}
13-
14-
struct Row {
15-
let id: UUID
16-
let name: String
17-
let age: Int
18-
}
7+
let connection = try await PostgresConnection.connect(
8+
configuration: .init(
9+
host: "127.0.0.1",
10+
username: "timozacherl",
11+
password: nil,
12+
database: "postgres",
13+
tls: .disable
14+
), id: 1, logger: logger
15+
)
1916

20-
static let sql: String = ""
17+
try await connection.query("CREATE TABLE IF NOT EXISTS users (id UUID UNIQUE, name TEXT, age INT)", logger: logger)
2118

22-
let age: Int
19+
@Statement("INSERT INTO users (id, name, age) VALUES (\(bind: "id", UUID.self), \(bind: "name", String.self), \(bind: "age", Int.self))")
20+
struct SeedUser {}
2321

24-
func makeBindings() throws -> PostgresBindings {
25-
var bindings = PostgresBindings(capacity: 1)
26-
bindings.append(age)
27-
return bindings
28-
}
29-
}
22+
@Statement("SELECT \("id", UUID.self), \("name", String.self), \("age", Int.self) FROM users WHERE \(bind: "age", Int.self) < age")
23+
struct GetForAgeRestriction {}
3024

31-
func myThing() {
25+
_ = try? await connection.execute(
26+
SeedUser(id: UUID(uuidString: "A0A2AE7F-C398-4468-A276-6402639806DF")!, name: "Timo", age: 24),
27+
logger: logger
28+
)
3229

30+
for try await row in try await connection.execute(GetForAgeRestriction(age: 18), logger: logger) {
31+
print(row)
3332
}
34-
35-
@Statement("SELECT *")
36-
struct MyOtherPreparedStatement {}
37-
38-
@available(macOS 14.0, *)
39-
@Observable
40-
final class MyObservable {}

0 commit comments

Comments
 (0)