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

sqlc.embed does not seem to work with SQLite #2391

Closed
christeredvartsen opened this issue Jun 29, 2023 · 3 comments · Fixed by #2488
Closed

sqlc.embed does not seem to work with SQLite #2391

christeredvartsen opened this issue Jun 29, 2023 · 3 comments · Fixed by #2488

Comments

@christeredvartsen
Copy link

Version

1.18.0

What happened?

When using sqlite as engine the sqlc.embed() functionality can not be used in queries.

Simple working example with PostgreSQL: https://play.sqlc.dev/p/4fa9fa04a1130b86c9fa6e0ad50557c0025c0f91a2e15f8d9d3672b9889fe4de

Same example using SQLite with error message:
https://play.sqlc.dev/p/0bc9baf87b614118eaab84414eb50ab299b12aa7584b5b6baca48afe6b70973a

Relevant log output

line 18:17 no viable alternative at input ';\n\n-- name: GetSessionByKey :one\nSELECT sqlc.embed('
line 18:17 extraneous input '(' expecting {<EOF>, ';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}
line 19:53 extraneous input '<EOF>' expecting {';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}
# package db
query.sql:1:1: extraneous input '<EOF>' expecting {';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}

Database schema

CREATE TABLE sessions
(
    key TEXT UNIQUE,
    expiry TEXT,
    device_id INTEGER NOT NULL
);

CREATE TABLE devices
(
    id INTEGER PRIMARY KEY,
    username TEXT,
    serial TEXT,
    UNIQUE (serial, platform)
);

SQL queries

-- name: GetSessionByKey :one
SELECT sqlc.embed(s), sqlc.embed(d) FROM sessions s
JOIN devices d ON d.id = s.device_id WHERE s.key = ?;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "sqlite",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL, SQLite

What type of code are you generating?

Go

@christeredvartsen christeredvartsen added bug Something isn't working triage New issues that hasn't been reviewed labels Jun 29, 2023
@kyleconroy kyleconroy added 🔧 golang 💻 darwin 📚 sqlite and removed triage New issues that hasn't been reviewed labels Jul 6, 2023
@orisano
Copy link
Contributor

orisano commented Jul 7, 2023

@christeredvartsen please use v1.19.0

@christeredvartsen
Copy link
Author

It seems to be working as expected in the playground with v1.19.0, but locally I get a few unknown SQLite type: errors, which is probably caused by some other dependency not being updated. I will debug more locally, but I guess the issue can be closed since it's working in the playground.

@christeredvartsen
Copy link
Author

It seems that this is where the log line is produced (which is not an error as I specified above):

https://github.com/kyleconroy/sqlc/blob/b6436420ecde3d5c1ffe70aae82a7931e4d233c9/internal/codegen/golang/sqlite_type.go#L71

A similar log line in the postgres implementation is only active during debug it seems:

https://github.com/kyleconroy/sqlc/blob/b6436420ecde3d5c1ffe70aae82a7931e4d233c9/internal/codegen/golang/postgresql_type.go#L571-L573

I guess the sqlite implementation is just missing the if debug.Active part.

mcdoker18 added a commit to mcdoker18/sqlc that referenced this issue Jul 21, 2023
andrewmbenton pushed a commit that referenced this issue Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants