question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get Statement from Query

See original GitHub issue

Description

I would like to get the raw sql statement defined in a .sq file and validated/generated with the compiler.

Usecase 1: Having a class with more than 256 attributes. Instead defining the raw query in Kotlin code and validate the query at runtime (eg wrong typed names), it would be nice to validate it with SQLDelight. Then you can use SqlDriver.executeQuery with a custom binders block. Usecase 2: Using other APIs, which requires a SQL statement, eg Postgres CopyManager. Same reason, the validation can be done by the compiler.

// sq file
filter:
SELECT * FROM foo WHERE name = ?;

// kt file
val rawStatement = queries.filter().statement // SELECT * FROM foo WHERE name = ?;
driver.executeQuery(null, rawStatement, ...)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hfhbdcommented, Jun 11, 2022

The new QueryResult async api is nice, without it it was impossible to return R in executeQuery, now I can use:

override fun <R> executeQuery(
        identifier: Int?,
        sql: String,
        mapper: (SqlCursor) -> R,
        parameters: Int,
        binders: (SqlPreparedStatement.() -> Unit)?
    ): QueryResult<R> {
        lastStatement = sql
        return QueryResult.AsyncValue { 
            error("Not supported")
        }
    }
1reaction
AlecStrongcommented, Jan 4, 2022

once you have an instance of Query it isn’t, so that proposed API would work:

selectWithArgs:
SELECT *
FROM test
WHERE args IN ?;
val myQuery = myQueries.selectWithArgs("foo", "bar")
myQuery.rawSql
Read more comments on GitHub >

github_iconTop Results From Across the Web

Get query from java.sql.PreparedStatement [duplicate]
In my code I am using java.sql.PreparedStatement . I then execute the setString() method to populate the wildcards of the prepared statement. Is ......
Read more >
SQL example statements for retrieving data from a table - IU KB
An SQL SELECT statement retrieves records from a database table according to clauses (for example, FROM and WHERE ) that specify criteria. The ......
Read more >
SQL SELECT Statement - W3Schools
The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set....
Read more >
How to query data using a SELECT statement in SQL Server
This article describes how to query data using a SELECT statement in SQL Server effortlessly.
Read more >
SQL examples for beginners: SQL SELECT statement usage
The above query template specifies a very basic SQL SELECT statement. As you can see, column names are placed after the SELECT clause...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found