sqlc-dev / sqlc-gen-kotlin Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
When creating a boolean (nullable) column in Postgres.
When generating code from SQL that retrieves this column, it becomes results.getBoolean()
.
Reading ResultSet.java, it states
"Returns: the column value; if the value is SQL NULL, the value returned is false."
Ideally, if the table contains null, I would like it to return null.
I would like to hear the maintainer's opinion on this.
Version
1.12.0
What happened?
Tried to use named parameters with the Kotlin code generator, but ran into an error. I recreated the issue in the unit tests and came to know that Kotlin enforces the use of positional parameters with the Postgres engine.
Is it possible to get some guidance on which specific areas of the Kotlin code generator I should look at to add support for named parameters
Relevant log output
src/main/resources/authors/postgresql/query.sql:1:1: edited query syntax is invalid: syntax error at or near "dentifivation" src/main/resources/authors/postgresql/query.sql:10:1: edited query syntax is invalid: syntax error at or near "ame" src/main/resources/authors/postgresql/query.sql:18:1: edited query syntax is invalid: syntax error at or near "d"Database schema
CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text );SQL queries
-- name: GetAuthor :one SELECT * FROM authors WHERE id = @identifivation LIMIT @lim; -- name: ListAuthors :many SELECT * FROM authors ORDER BY name; -- name: CreateAuthor :one INSERT INTO authors ( name, bio ) VALUES ( @name, @bio ) RETURNING *; -- name: DeleteAuthor :exec DELETE FROM authors WHERE id = @id;Configuration
{ "version": "2", "sql": [ { "schema": "postgresql/schema.sql", "queries": "postgresql/query.sql", "engine": "postgresql", "gen": { "go": { "package": "authors", "out": "postgresql" } } } ] }Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Kotlin
When using the plugin to generate Kotlin output for :execrows queries with MySql return statements are missing and the resulting files wont compile.
If I look at the template code it looks like the generated code should start with return return conn.prepareStatement
however when using the plugin (from the github release or the sqlc release the return statement is not present and the code wont compile.
The source zips for the release do seem to have a return statement.
The following example shows the generated output I'm seeing in QueriesImpl.kt
@Throws(SQLException::class)
override fun updateMyRow(newDesc: String, theKey: String): Int {
conn.prepareStatement(setStateByDdaToken).use { stmt ->
stmt.setString(1, newDesc)
stmt.setString(2, theKey)
stmt.execute()
stmt.updateCount
}
}
When creating a decimal(19, 4) column in PostgreSQL, it generates a data class with a property of type java.math.BigDecimal? .
However, when generating a query for a table with this column, the code results.getjava.math.BigDecimal() is produced. It seems that the correct code should be results.getBigDecimal() .
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.