Skip to content

Add all Go types for the code generator of the sqlite engine #1001

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

Merged
merged 2 commits into from
May 4, 2021
Merged

Add all Go types for the code generator of the sqlite engine #1001

merged 2 commits into from
May 4, 2021

Conversation

philippta
Copy link
Contributor

@philippta philippta commented May 4, 2021

Based on the lose typing of SQLite and how the popular driver github.com/mattn/go-sqlite3 handles them, I've extended the sqlite codegen to generate the Go types accordingly.

This is the mapping of SQLite database types to Go types I cound figure out:

                 INT => int64
             INTEGER => int64
             TINYINT => int64
            SMALLINT => int64
           MEDIUMINT => int64
              BIGINT => int64
    UNSIGNED BIG INT => int64
                INT2 => int64
                INT8 => int64
           CHARACTER => string
             VARCHAR => string
   VARYING CHARACTER => string
               NCHAR => string
    NATIVE CHARACTER => string
            NVARCHAR => string
                TEXT => string
                CLOB => string
                BLOB => []uint8
                REAL => float64
              DOUBLE => float64
    DOUBLE PRECISION => float64
               FLOAT => float64
             NUMERIC => int64
             DECIMAL => int64
             BOOLEAN => bool
                DATE => time.Time
            DATETIME => time.Time
           TIMESTAMP => time.Time

Link: List of all supported SQLite types
Link: Type handling in the go-sqlite3 database driver

A small note on the integer type:

  • SQLite does not enforce the size of integers, meaning that whenever a value exceeds the max value of an int32, it will automatically result in an int64.
  • Because of that, github.com/mattn/go-sqlite3 will always use int64s.
  • This is also the reason I've changed the already existing type for integers from int32 to int64.

@kyleconroy kyleconroy merged commit 6a4a825 into sqlc-dev:main May 4, 2021
victoraugustolls pushed a commit to Streppel/sqlc that referenced this pull request May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants