Skip to content

Commit 8020662

Browse files
committed
kotlin: support mysql types
and adds MySQL tests for all existing examples
1 parent d8a81fa commit 8020662

File tree

22 files changed

+1137
-117
lines changed

22 files changed

+1137
-117
lines changed

examples/kotlin/sqlc.json

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"engine": "postgresql",
88
"gen": {
99
"kotlin": {
10-
"out": "src/main/kotlin/com/example/authors",
11-
"package": "com.example.authors"
10+
"out": "src/main/kotlin/com/example/authors/postgresql",
11+
"package": "com.example.authors.postgresql"
1212
}
1313
}
1414
},
@@ -55,6 +55,28 @@
5555
"package": "com.example.authors.mysql"
5656
}
5757
}
58+
},
59+
{
60+
"schema": "src/main/resources/booktest/mysql/schema.sql",
61+
"queries": "src/main/resources/booktest/mysql/query.sql",
62+
"engine": "mysql:beta",
63+
"gen": {
64+
"kotlin": {
65+
"out": "src/main/kotlin/com/example/booktest/mysql",
66+
"package": "com.example.booktest.mysql"
67+
}
68+
}
69+
},
70+
{
71+
"schema": "src/main/resources/ondeck/mysql/schema",
72+
"queries": "src/main/resources/ondeck/mysql/query",
73+
"engine": "mysql:beta",
74+
"gen": {
75+
"kotlin": {
76+
"out": "src/main/kotlin/com/example/ondeck/mysql",
77+
"package": "com.example.ondeck.mysql"
78+
}
79+
}
5880
}
5981
]
6082
}

examples/kotlin/src/main/kotlin/com/example/authors/Models.kt renamed to examples/kotlin/src/main/kotlin/com/example/authors/postgresql/Models.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Code generated by sqlc. DO NOT EDIT.
22

3-
package com.example.authors
3+
package com.example.authors.postgresql
44

55
data class Author (
66
val id: Long,

examples/kotlin/src/main/kotlin/com/example/authors/Queries.kt renamed to examples/kotlin/src/main/kotlin/com/example/authors/postgresql/Queries.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Code generated by sqlc. DO NOT EDIT.
22

3-
package com.example.authors
3+
package com.example.authors.postgresql
44

55
import java.sql.Connection
66
import java.sql.SQLException

examples/kotlin/src/main/kotlin/com/example/authors/QueriesImpl.kt renamed to examples/kotlin/src/main/kotlin/com/example/authors/postgresql/QueriesImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Code generated by sqlc. DO NOT EDIT.
22

3-
package com.example.authors
3+
package com.example.authors.postgresql
44

55
import java.sql.Connection
66
import java.sql.SQLException
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Code generated by sqlc. DO NOT EDIT.
2+
3+
package com.example.booktest.mysql
4+
5+
import java.time.LocalDateTime
6+
7+
enum class BooksBookType(val value: String) {
8+
FICTION("FICTION"),
9+
NONFICTION("NONFICTION");
10+
11+
companion object {
12+
private val map = BooksBookType.values().associateBy(BooksBookType::value)
13+
fun lookup(value: String) = map[value]
14+
}
15+
}
16+
17+
data class Author (
18+
val authorId: Int,
19+
val name: String
20+
)
21+
22+
data class Book (
23+
val bookId: Int,
24+
val authorId: Int,
25+
val isbn: String,
26+
val bookType: BooksBookType,
27+
val title: String,
28+
val yr: Int,
29+
val available: LocalDateTime,
30+
val tags: String
31+
)
32+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Code generated by sqlc. DO NOT EDIT.
2+
3+
package com.example.booktest.mysql
4+
5+
import java.sql.Connection
6+
import java.sql.SQLException
7+
import java.sql.Statement
8+
import java.time.LocalDateTime
9+
10+
interface Queries {
11+
@Throws(SQLException::class)
12+
fun booksByTags(tags: String): List<BooksByTagsRow>
13+
14+
@Throws(SQLException::class)
15+
fun booksByTitleYear(title: String, yr: Int): List<Book>
16+
17+
@Throws(SQLException::class)
18+
fun createAuthor(name: String): Long
19+
20+
@Throws(SQLException::class)
21+
fun createBook(
22+
authorId: Int,
23+
isbn: String,
24+
bookType: BooksBookType,
25+
title: String,
26+
yr: Int,
27+
available: LocalDateTime,
28+
tags: String): Long
29+
30+
@Throws(SQLException::class)
31+
fun deleteAuthorBeforeYear(yr: Int, authorId: Int)
32+
33+
@Throws(SQLException::class)
34+
fun deleteBook(bookId: Int)
35+
36+
@Throws(SQLException::class)
37+
fun getAuthor(authorId: Int): Author
38+
39+
@Throws(SQLException::class)
40+
fun getBook(bookId: Int): Book
41+
42+
@Throws(SQLException::class)
43+
fun updateBook(
44+
title: String,
45+
tags: String,
46+
bookId: Int)
47+
48+
@Throws(SQLException::class)
49+
fun updateBookISBN(
50+
title: String,
51+
tags: String,
52+
isbn: String,
53+
bookId: Int)
54+
55+
}
56+

0 commit comments

Comments
 (0)