-
Notifications
You must be signed in to change notification settings - Fork 886
Kotlin mysql #775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Kotlin mysql #775
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...main/kotlin/com/example/authors/Models.kt → ...otlin/com/example/authors/mysql/Models.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...ain/kotlin/com/example/authors/Queries.kt → ...tlin/com/example/authors/mysql/Queries.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
examples/kotlin/src/main/kotlin/com/example/authors/mysql/QueriesImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Code generated by sqlc. DO NOT EDIT. | ||
|
||
package com.example.authors.mysql | ||
|
||
import java.sql.Connection | ||
import java.sql.SQLException | ||
import java.sql.Statement | ||
|
||
const val createAuthor = """-- name: createAuthor :execresult | ||
INSERT INTO authors ( | ||
name, bio | ||
) VALUES ( | ||
?, ? | ||
) | ||
""" | ||
|
||
const val deleteAuthor = """-- name: deleteAuthor :exec | ||
DELETE FROM authors | ||
WHERE id = ? | ||
""" | ||
|
||
const val getAuthor = """-- name: getAuthor :one | ||
SELECT id, name, bio FROM authors | ||
WHERE id = ? LIMIT 1 | ||
""" | ||
|
||
const val listAuthors = """-- name: listAuthors :many | ||
SELECT id, name, bio FROM authors | ||
ORDER BY name | ||
""" | ||
|
||
class QueriesImpl(private val conn: Connection) : Queries { | ||
|
||
@Throws(SQLException::class) | ||
override fun createAuthor(name: String, bio: String?): Long { | ||
return conn.prepareStatement(createAuthor, Statement.RETURN_GENERATED_KEYS).use { stmt -> | ||
stmt.setString(1, name) | ||
stmt.setString(2, bio) | ||
|
||
stmt.execute() | ||
|
||
val results = stmt.generatedKeys | ||
if (!results.next()) { | ||
throw SQLException("no generated key returned") | ||
} | ||
results.getLong(1) | ||
} | ||
} | ||
|
||
@Throws(SQLException::class) | ||
override fun deleteAuthor(id: Long) { | ||
conn.prepareStatement(deleteAuthor).use { stmt -> | ||
stmt.setLong(1, id) | ||
|
||
stmt.execute() | ||
} | ||
} | ||
|
||
@Throws(SQLException::class) | ||
override fun getAuthor(id: Long): Author? { | ||
return conn.prepareStatement(getAuthor).use { stmt -> | ||
stmt.setLong(1, id) | ||
|
||
val results = stmt.executeQuery() | ||
if (!results.next()) { | ||
return null | ||
} | ||
val ret = Author( | ||
results.getLong(1), | ||
results.getString(2), | ||
results.getString(3) | ||
) | ||
if (results.next()) { | ||
throw SQLException("expected one row in result set, but got many") | ||
} | ||
ret | ||
} | ||
} | ||
|
||
@Throws(SQLException::class) | ||
override fun listAuthors(): List<Author> { | ||
return conn.prepareStatement(listAuthors).use { stmt -> | ||
|
||
val results = stmt.executeQuery() | ||
val ret = mutableListOf<Author>() | ||
while (results.next()) { | ||
ret.add(Author( | ||
results.getLong(1), | ||
results.getString(2), | ||
results.getString(3) | ||
)) | ||
} | ||
ret | ||
} | ||
} | ||
|
||
} | ||
|
10 changes: 10 additions & 0 deletions
10
examples/kotlin/src/main/kotlin/com/example/authors/postgresql/Models.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Code generated by sqlc. DO NOT EDIT. | ||
|
||
package com.example.authors.postgresql | ||
|
||
data class Author ( | ||
val id: Long, | ||
val name: String, | ||
val bio: String? | ||
) | ||
|
23 changes: 23 additions & 0 deletions
23
examples/kotlin/src/main/kotlin/com/example/authors/postgresql/Queries.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Code generated by sqlc. DO NOT EDIT. | ||
|
||
package com.example.authors.postgresql | ||
|
||
import java.sql.Connection | ||
import java.sql.SQLException | ||
import java.sql.Statement | ||
|
||
interface Queries { | ||
@Throws(SQLException::class) | ||
fun createAuthor(name: String, bio: String?): Author? | ||
|
||
@Throws(SQLException::class) | ||
fun deleteAuthor(id: Long) | ||
|
||
@Throws(SQLException::class) | ||
fun getAuthor(id: Long): Author? | ||
|
||
@Throws(SQLException::class) | ||
fun listAuthors(): List<Author> | ||
|
||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
examples/kotlin/src/main/kotlin/com/example/booktest/mysql/Models.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Code generated by sqlc. DO NOT EDIT. | ||
|
||
package com.example.booktest.mysql | ||
|
||
import java.time.LocalDateTime | ||
|
||
enum class BooksBookType(val value: String) { | ||
FICTION("FICTION"), | ||
NONFICTION("NONFICTION"); | ||
|
||
companion object { | ||
private val map = BooksBookType.values().associateBy(BooksBookType::value) | ||
fun lookup(value: String) = map[value] | ||
} | ||
} | ||
|
||
data class Author ( | ||
val authorId: Int, | ||
val name: String | ||
) | ||
|
||
data class Book ( | ||
val bookId: Int, | ||
val authorId: Int, | ||
val isbn: String, | ||
val bookType: BooksBookType, | ||
val title: String, | ||
val yr: Int, | ||
val available: LocalDateTime, | ||
val tags: String | ||
) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably never worked? It probably interpolated into the empty string, and the tests used the default port which is 3306