Skip to content

Commit 7549b3b

Browse files
committed
integrate kotlin with config v2
1 parent 62bb7c8 commit 7549b3b

File tree

14 files changed

+350
-120
lines changed

14 files changed

+350
-120
lines changed

examples/kotlin/sqlc.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"version": "2",
3+
"sql": [
4+
{
5+
"schema": "src/main/resources/authors/schema.sql",
6+
"queries": "src/main/resources/authors/query.sql",
7+
"engine": "postgresql",
8+
"gen": {
9+
"kotlin": {
10+
"out": "src/main/kotlin/com/example/authors",
11+
"package": "com.example.authors"
12+
}
13+
}
14+
},
15+
{
16+
"schema": "src/main/resources/ondeck/schema",
17+
"queries": "src/main/resources/ondeck/query",
18+
"engine": "postgresql",
19+
"gen": {
20+
"kotlin": {
21+
"out": "src/main/kotlin/com/example/ondeck",
22+
"package": "com.example.ondeck"
23+
}
24+
}
25+
},
26+
{
27+
"schema": "src/main/resources/jets/schema.sql",
28+
"queries": "src/main/resources/jets/query-building.sql",
29+
"engine": "postgresql",
30+
"gen": {
31+
"kotlin": {
32+
"out": "src/main/kotlin/com/example/jets",
33+
"package": "com.example.jets"
34+
}
35+
}
36+
},
37+
{
38+
"schema": "src/main/resources/booktest/postgresql/schema.sql",
39+
"queries": "src/main/resources/booktest/postgresql/query.sql",
40+
"engine": "postgresql",
41+
"gen": {
42+
"kotlin": {
43+
"out": "src/main/kotlin/com/example/booktest/postgresql",
44+
"package": "com.example.booktest.postgresql"
45+
}
46+
}
47+
}
48+
]
49+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Code generated by sqlc. DO NOT EDIT.
2+
3+
package com.example.authors
4+
5+
import java.sql.Connection
6+
import java.sql.SQLException
7+
8+
interface Queries {
9+
@Throws(SQLException::class)
10+
fun createAuthor(name: String, bio: String?): Author
11+
12+
@Throws(SQLException::class)
13+
fun deleteAuthor(id: Long)
14+
15+
@Throws(SQLException::class)
16+
fun getAuthor(id: Long): Author
17+
18+
@Throws(SQLException::class)
19+
fun listAuthors(): List<Author>
20+
21+
}
22+

examples/kotlin/src/main/kotlin/com/example/authors/QueriesImpl.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ SELECT id, name, bio FROM authors
2929
ORDER BY name
3030
"""
3131

32-
class QueriesImpl(private val conn: Connection) {
32+
class QueriesImpl(private val conn: Connection) : Queries {
3333

3434
@Throws(SQLException::class)
35-
fun createAuthor(name: String, bio: String?): Author {
35+
override fun createAuthor(name: String, bio: String?): Author {
3636
return conn.prepareStatement(createAuthor).use { stmt ->
3737
stmt.setString(1, name)
3838
stmt.setString(2, bio)
@@ -54,7 +54,7 @@ class QueriesImpl(private val conn: Connection) {
5454
}
5555

5656
@Throws(SQLException::class)
57-
fun deleteAuthor(id: Long) {
57+
override fun deleteAuthor(id: Long) {
5858
conn.prepareStatement(deleteAuthor).use { stmt ->
5959
stmt.setLong(1, id)
6060

@@ -63,7 +63,7 @@ class QueriesImpl(private val conn: Connection) {
6363
}
6464

6565
@Throws(SQLException::class)
66-
fun getAuthor(id: Long): Author {
66+
override fun getAuthor(id: Long): Author {
6767
return conn.prepareStatement(getAuthor).use { stmt ->
6868
stmt.setLong(1, id)
6969

@@ -84,7 +84,7 @@ class QueriesImpl(private val conn: Connection) {
8484
}
8585

8686
@Throws(SQLException::class)
87-
fun listAuthors(): List<Author> {
87+
override fun listAuthors(): List<Author> {
8888
return conn.prepareStatement(listAuthors).use { stmt ->
8989

9090
val results = stmt.executeQuery()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Code generated by sqlc. DO NOT EDIT.
2+
3+
package com.example.booktest.postgresql
4+
5+
import java.sql.Connection
6+
import java.sql.SQLException
7+
import java.sql.Types
8+
import java.time.OffsetDateTime
9+
10+
interface Queries {
11+
@Throws(SQLException::class)
12+
fun booksByTags(dollar1: List<String>): List<BooksByTagsRow>
13+
14+
@Throws(SQLException::class)
15+
fun booksByTitleYear(title: String, year: Int): List<Book>
16+
17+
@Throws(SQLException::class)
18+
fun createAuthor(name: String): Author
19+
20+
@Throws(SQLException::class)
21+
fun createBook(
22+
authorId: Int,
23+
isbn: String,
24+
booktype: BookType,
25+
title: String,
26+
year: Int,
27+
available: OffsetDateTime,
28+
tags: List<String>): Book
29+
30+
@Throws(SQLException::class)
31+
fun deleteBook(bookId: Int)
32+
33+
@Throws(SQLException::class)
34+
fun getAuthor(authorId: Int): Author
35+
36+
@Throws(SQLException::class)
37+
fun getBook(bookId: Int): Book
38+
39+
@Throws(SQLException::class)
40+
fun updateBook(
41+
title: String,
42+
tags: List<String>,
43+
bookId: Int)
44+
45+
@Throws(SQLException::class)
46+
fun updateBookISBN(
47+
title: String,
48+
tags: List<String>,
49+
isbn: String,
50+
bookId: Int)
51+
52+
}
53+

examples/kotlin/src/main/kotlin/com/example/booktest/postgresql/QueriesImpl.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ SET title = ?, tags = ?, isbn = ?
8585
WHERE book_id = ?
8686
"""
8787

88-
class QueriesImpl(private val conn: Connection) {
88+
class QueriesImpl(private val conn: Connection) : Queries {
8989

9090
@Throws(SQLException::class)
91-
fun booksByTags(dollar1: List<String>): List<BooksByTagsRow> {
91+
override fun booksByTags(dollar1: List<String>): List<BooksByTagsRow> {
9292
return conn.prepareStatement(booksByTags).use { stmt ->
9393
stmt.setArray(1, conn.createArrayOf("pg_catalog.varchar", dollar1.toTypedArray()))
9494

@@ -108,7 +108,7 @@ class QueriesImpl(private val conn: Connection) {
108108
}
109109

110110
@Throws(SQLException::class)
111-
fun booksByTitleYear(title: String, year: Int): List<Book> {
111+
override fun booksByTitleYear(title: String, year: Int): List<Book> {
112112
return conn.prepareStatement(booksByTitleYear).use { stmt ->
113113
stmt.setString(1, title)
114114
stmt.setInt(2, year)
@@ -132,7 +132,7 @@ class QueriesImpl(private val conn: Connection) {
132132
}
133133

134134
@Throws(SQLException::class)
135-
fun createAuthor(name: String): Author {
135+
override fun createAuthor(name: String): Author {
136136
return conn.prepareStatement(createAuthor).use { stmt ->
137137
stmt.setString(1, name)
138138

@@ -152,7 +152,7 @@ class QueriesImpl(private val conn: Connection) {
152152
}
153153

154154
@Throws(SQLException::class)
155-
fun createBook(
155+
override fun createBook(
156156
authorId: Int,
157157
isbn: String,
158158
booktype: BookType,
@@ -191,7 +191,7 @@ class QueriesImpl(private val conn: Connection) {
191191
}
192192

193193
@Throws(SQLException::class)
194-
fun deleteBook(bookId: Int) {
194+
override fun deleteBook(bookId: Int) {
195195
conn.prepareStatement(deleteBook).use { stmt ->
196196
stmt.setInt(1, bookId)
197197

@@ -200,7 +200,7 @@ class QueriesImpl(private val conn: Connection) {
200200
}
201201

202202
@Throws(SQLException::class)
203-
fun getAuthor(authorId: Int): Author {
203+
override fun getAuthor(authorId: Int): Author {
204204
return conn.prepareStatement(getAuthor).use { stmt ->
205205
stmt.setInt(1, authorId)
206206

@@ -220,7 +220,7 @@ class QueriesImpl(private val conn: Connection) {
220220
}
221221

222222
@Throws(SQLException::class)
223-
fun getBook(bookId: Int): Book {
223+
override fun getBook(bookId: Int): Book {
224224
return conn.prepareStatement(getBook).use { stmt ->
225225
stmt.setInt(1, bookId)
226226

@@ -246,7 +246,7 @@ class QueriesImpl(private val conn: Connection) {
246246
}
247247

248248
@Throws(SQLException::class)
249-
fun updateBook(
249+
override fun updateBook(
250250
title: String,
251251
tags: List<String>,
252252
bookId: Int) {
@@ -260,7 +260,7 @@ class QueriesImpl(private val conn: Connection) {
260260
}
261261

262262
@Throws(SQLException::class)
263-
fun updateBookISBN(
263+
override fun updateBookISBN(
264264
title: String,
265265
tags: List<String>,
266266
isbn: String,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Code generated by sqlc. DO NOT EDIT.
2+
3+
package com.example.jets
4+
5+
import java.sql.Connection
6+
import java.sql.SQLException
7+
8+
interface Queries {
9+
@Throws(SQLException::class)
10+
fun countPilots(): Long
11+
12+
@Throws(SQLException::class)
13+
fun deletePilot(id: Int)
14+
15+
@Throws(SQLException::class)
16+
fun listPilots(): List<Pilot>
17+
18+
}
19+

examples/kotlin/src/main/kotlin/com/example/jets/QueriesImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const val listPilots = """-- name: listPilots :many
1717
SELECT id, name FROM pilots LIMIT 5
1818
"""
1919

20-
class QueriesImpl(private val conn: Connection) {
20+
class QueriesImpl(private val conn: Connection) : Queries {
2121

2222
@Throws(SQLException::class)
23-
fun countPilots(): Long {
23+
override fun countPilots(): Long {
2424
return conn.prepareStatement(countPilots).use { stmt ->
2525

2626
val results = stmt.executeQuery()
@@ -36,7 +36,7 @@ class QueriesImpl(private val conn: Connection) {
3636
}
3737

3838
@Throws(SQLException::class)
39-
fun deletePilot(id: Int) {
39+
override fun deletePilot(id: Int) {
4040
conn.prepareStatement(deletePilot).use { stmt ->
4141
stmt.setInt(1, id)
4242

@@ -45,7 +45,7 @@ class QueriesImpl(private val conn: Connection) {
4545
}
4646

4747
@Throws(SQLException::class)
48-
fun listPilots(): List<Pilot> {
48+
override fun listPilots(): List<Pilot> {
4949
return conn.prepareStatement(listPilots).use { stmt ->
5050

5151
val results = stmt.executeQuery()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- name: CountPilots :one
2+
SELECT COUNT(*) FROM pilots;
3+
4+
-- name: ListPilots :many
5+
SELECT * FROM pilots LIMIT 5;
6+
7+
-- name: DeletePilot :exec
8+
DELETE FROM pilots WHERE id = $1;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
CREATE TABLE pilots (
2+
id integer NOT NULL,
3+
name text NOT NULL
4+
);
5+
6+
ALTER TABLE pilots ADD CONSTRAINT pilot_pkey PRIMARY KEY (id);
7+
8+
CREATE TABLE jets (
9+
id integer NOT NULL,
10+
pilot_id integer NOT NULL,
11+
age integer NOT NULL,
12+
name text NOT NULL,
13+
color text NOT NULL
14+
);
15+
16+
ALTER TABLE jets ADD CONSTRAINT jet_pkey PRIMARY KEY (id);
17+
ALTER TABLE jets ADD CONSTRAINT jet_pilots_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id);
18+
19+
CREATE TABLE languages (
20+
id integer NOT NULL,
21+
language text NOT NULL
22+
);
23+
24+
ALTER TABLE languages ADD CONSTRAINT language_pkey PRIMARY KEY (id);
25+
26+
-- Join table
27+
CREATE TABLE pilot_languages (
28+
pilot_id integer NOT NULL,
29+
language_id integer NOT NULL
30+
);
31+
32+
-- Composite primary key
33+
ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_pkey PRIMARY KEY (pilot_id, language_id);
34+
ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_pilots_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id);
35+
ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_languages_fkey FOREIGN KEY (language_id) REFERENCES languages(id);

examples/sqlc.json

Whitespace-only changes.

0 commit comments

Comments
 (0)