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

Column overrides have no effect when using SQLite engine #1985

Closed
gregoryjjb opened this issue Dec 4, 2022 · 2 comments · Fixed by #1986
Closed

Column overrides have no effect when using SQLite engine #1985

gregoryjjb opened this issue Dec 4, 2022 · 2 comments · Fixed by #1986

Comments

@gregoryjjb
Copy link

gregoryjjb commented Dec 4, 2022

Version

1.15.0

What happened?

Type overrides specified by column name have no effect when using SQLite as the engine. The same config works with MySQL.

Check out the UUID column in the following playgrounds (snippets pasted below as well):

SQLite playground showing bugged result

MySQL playground showing desired result

The resulting struct with SQLite (no type override applied, it uses the default sql.NullString):

type Author struct {
	ID   int64
	Name string
	Uuid sql.NullString
}

And with MySQL (it used UUID this time correctly):

type Author struct {
	ID   int32
	Name string
	Uuid uuid.UUID
}

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  uuid TEXT
);

SQL queries

No response

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "sqlite",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ],
  "overrides": [
    {
      "column": "authors.uuid",
      "go_type": "github.com/gofrs/uuid.UUID",
      "nullable": true
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/2c63b17ce6f6fe25e987ef9af4175641d1c9d3607be33cf4a86188b08a09f4dd

What operating system are you using?

Windows

What database engines are you using?

No response

What type of code are you generating?

Go

@gregoryjjb gregoryjjb added bug Something isn't working triage New issues that hasn't been reviewed labels Dec 4, 2022
mcdoker18 added a commit to mcdoker18/sqlc that referenced this issue Dec 5, 2022
We should not assume that a table has a default schema name in the override config.
Because different sql databases can have different default schemas.

Fixes: sqlc-dev#1985
@Edholm
Copy link

Edholm commented Mar 9, 2023

For those of you that want a "workaround", you need to explicitly specify the schema in the column override:

        overrides:
          - column: "main.mytable.mycolumn"
            go_type: "github.com/gofrs/uuid.UUID"

This worked for me on sqlc v1.17.0.

danderson pushed a commit to danderson/sqlc that referenced this issue May 7, 2023
We should not assume that a table has a default schema name in the override config.
Because different sql databases can have different default schemas.

Fixes: sqlc-dev#1985
Signed-off-by: David Anderson <[email protected]>
@andrewmbenton andrewmbenton added 🔧 golang 💻 windows 📚 sqlite and removed triage New issues that hasn't been reviewed labels Jun 6, 2023
@andrewmbenton
Copy link
Collaborator

This is still an issue in v1.18.0: https://play.sqlc.dev/p/37eff07be350564fde55c4916c4c00df23e4dc524d09a06d5abe77e9ef087851

It looks like we should probably merge #1986 to resolve this

andrewmbenton pushed a commit that referenced this issue Jun 7, 2023
We should not assume that a table has a default schema name in the override config.
Because different sql databases can have different default schemas.

Fixes: #1985
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