-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathQueriesImpl.kt
More file actions
67 lines (53 loc) · 1.45 KB
/
QueriesImpl.kt
File metadata and controls
67 lines (53 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
package com.example.jets
import java.sql.Connection
import java.sql.SQLException
import java.sql.Statement
const val countPilots = """-- name: countPilots :one
SELECT COUNT(*) FROM pilots
"""
const val deletePilot = """-- name: deletePilot :exec
DELETE FROM pilots WHERE id = ?
"""
const val listPilots = """-- name: listPilots :many
SELECT id, name FROM pilots LIMIT 5
"""
class QueriesImpl(private val conn: Connection) : Queries {
@Throws(SQLException::class)
override fun countPilots(): Long? {
return conn.prepareStatement(countPilots).use { stmt ->
val results = stmt.executeQuery()
if (!results.next()) {
return null
}
val ret = results.getLong(1)
if (results.next()) {
throw SQLException("expected one row in result set, but got many")
}
ret
}
}
@Throws(SQLException::class)
override fun deletePilot(id: Int) {
conn.prepareStatement(deletePilot).use { stmt ->
stmt.setInt(1, id)
stmt.execute()
}
}
@Throws(SQLException::class)
override fun listPilots(): List<Pilot> {
return conn.prepareStatement(listPilots).use { stmt ->
val results = stmt.executeQuery()
val ret = mutableListOf<Pilot>()
while (results.next()) {
ret.add(Pilot(
results.getInt(1),
results.getString(2)
))
}
ret
}
}
}