Skip to content
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

SQLite: interface{} instead of time.Time for json extracted queries #3383

Open
jeromewir opened this issue May 16, 2024 · 0 comments
Open

SQLite: interface{} instead of time.Time for json extracted queries #3383

jeromewir opened this issue May 16, 2024 · 0 comments
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@jeromewir
Copy link

Version

1.26.0

What happened?

When generating some queries for some extracted JSON data on SQLite, the generated query row model uses interface{} instead of time.Time.

I reproduced with the following query:
SELECT id, DATETIME(data ->> createdAt) as created_at FROM authors;
Which produces:

type GetAuthorRow struct {
	ID        string
	CreatedAt interface{}
}

I've tried casting the output but SQLite only supports basic casting: https://www.sqlite.org/lang_expr.html#castexpr
Using DATETIME with CAST(DATETIME(data ->> createdAt) AS DATETIME)` results in the correct type being generated on go side with SQLC, but the data is not correctly extracted from the SQLite database.

I also tried to use the overrides with no sucess as I'm not dealing with existing SQLite columns but "generating" them with the queries.

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id    text PRIMARY KEY,
  data  text
);

SQL queries

SELECT id, DATETIME(data ->> createdAt) as created_at FROM authors;

Configuration

- engine: "sqlite"
    queries:
      - "queries.sql"
    schema: "./sql/sqlite/migrations/"
    gen:
      go:
        package: "queries"
        out: "internal/services/sqlite/queries"
        emit_interface: true
        emit_empty_slices: true
        emit_all_enum_values: true

Playground URL

https://play.sqlc.dev/p/596c5ead0510249c37a5f0aefda2441ce806c9ed7827e361b6568b0e1f18fe93

What operating system are you using?

Linux, macOS

What database engines are you using?

SQLite

What type of code are you generating?

Go

@jeromewir jeromewir added bug Something isn't working triage New issues that hasn't been reviewed labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
Development

No branches or pull requests

1 participant