You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I saw there's Typescript support in the works (is there a tracking issue?). It'd be neat if it could support Kotlin too. There's something similar for Kotlin called SQLDelight, but it only supports sqlite and was built for Android. JVM support for Java/Kotlin would be really cool.
I might be able to contribute if you are open to this.
Agreed! Do you have some example code that you'd hope sqlc would generate for you?
Java/Kotlin support is far off. We're still working through supporting both MySQL and PostgreSQL for Go. Have you looked at jOOQ? It may fit your need.
jOOQ generates Java code from your database and lets you build type safe SQL queries through its fluent API
I'm going to go ahead and close this for now. Once we're ready to add Java/Kotlin, we'll re-open it.
Yes we use jOOQ. Its code generation is pretty limited, only going as far as introspecting the DB to generate the models. The fluent API makes it similar to squirrel, but with more type safety. But it's the SQL => Function code generation that really makes sqlc powerful imo.
I think the code (for Kotlin at least), looks quite similar to Go. Here's what I think createAuthor() could look like.
packagecom.example.testmoduleimportjava.sql.Connectionimportjava.sql.SQLExceptiondata classAuthor(valid:Int, valname:String, valbio:String?);
data classCreateAuthorParams(valname:String, valbio:String?)
constval createAuthor ="""-- name: CreateAuthor :oneINSERT INTO authors ( name, bio) VALUES ( \$1, \$2)RETURNING id, name, bio"""classQueries(privatevalconn:Connection) {
@Throws(SQLException::class)
funcreateAuthor(arg:CreateAuthorParams): Author {
val stmt = conn.prepareStatement(createAuthor)
stmt.setString(1, arg.name)
stmt.setString(2, arg.bio)
val rs = stmt.executeQuery()
rs.next()
val author =Author(rs.getInt(1), rs.getString(2), rs.getString(3))
if (rs.next()) {
throwSQLException("expected one row, but got many")
}
return author
}
}
SQLDelight has a much fancier take on it, though I'm not sure if sqlc needs to do the same
Generated code -- the generated queries are in testmodule/TestDatabaseImpl.
I understand not wanting to take on too much for such a young project. But maybe naively I don't think Kotlin support would be all that more complex than Typescript support. I spend a lot of time in Go and Kotlin, and they are similar in certain aspects. And Kotlin <=> Java is completely interoperable.
Again, if I might be able to convince you this is worthwhile to do soon, I would definitely love to contribute!
Activity
kyleconroy commentedon Jan 24, 2020
There wasn't, but I just created #296
Agreed! Do you have some example code that you'd hope sqlc would generate for you?
Java/Kotlin support is far off. We're still working through supporting both MySQL and PostgreSQL for Go. Have you looked at jOOQ? It may fit your need.
I'm going to go ahead and close this for now. Once we're ready to add Java/Kotlin, we'll re-open it.
mightyguava commentedon Jan 24, 2020
Yes we use jOOQ. Its code generation is pretty limited, only going as far as introspecting the DB to generate the models. The fluent API makes it similar to squirrel, but with more type safety. But it's the SQL => Function code generation that really makes
sqlcpowerful imo.I think the code (for Kotlin at least), looks quite similar to Go. Here's what I think createAuthor() could look like.
SQLDelight has a much fancier take on it, though I'm not sure if sqlc needs to do the same
testmodule/TestDatabaseImpl.I understand not wanting to take on too much for such a young project. But maybe naively I don't think Kotlin support would be all that more complex than Typescript support. I spend a lot of time in Go and Kotlin, and they are similar in certain aspects. And Kotlin <=> Java is completely interoperable.
Again, if I might be able to convince you this is worthwhile to do soon, I would definitely love to contribute!
mightyguava commentedon Jan 24, 2020
Spent some time building a more complete example: https://gist.github.com/mightyguava/f2b7b0c3d1385df8eac509cc93f8d4f2
[-]Kotlin support[/-][+]Add a Kotlin language backend[/+]kyleconroy commentedon Feb 12, 2020
The first version of this has now landed! I'm going to mark this as complete. I've added a new
kotlinlabel for future issues.