sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Error generating code for mysql table with "-" in the table name

Open zhengyangfeng00 opened this issue 3 years ago • 0 comments

Version

1.15.0

What happened?

Running sqlc to generate go code results in an error: error generating code: source error: 22:9: expected type, found '-' (and 10 more errors)

I believe the reason is that the table name contains "-" and sqlc tries to generate the struct with "-" in it, which is an illegal golang struct name.

Example ddl:

CREATE TABLE IF NOT EXISTS `x-info` (
  `date` DATE NULL DEFAULT NULL,
  `meta` VARCHAR(50) NULL DEFAULT NULL,
  `count` INT(11) NULL DEFAULT NULL)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;

Relevant log output

error generating code: source error: 22:9: expected type, found '-' (and 10 more errors)

Database schema

CREATE TABLE IF NOT EXISTS `x-info` (
  `date` DATE NULL DEFAULT NULL,
  `meta` VARCHAR(50) NULL DEFAULT NULL,
  `count` INT(11) NULL DEFAULT NULL)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;

SQL queries

-- name: Query :many
SELECT * FROM `x-info`
WHERE meta = ?
;

Configuration

- path: "go/gen/sqlc/xmetricssqlc"
    name: "xmetricssqlc"
    engine: "mysql"
    schema: "ddl.sql"
    queries: "queries.sql"

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

zhengyangfeng00 avatar Sep 14 '22 11:09 zhengyangfeng00