Closed
Description
Version
1.10.0
What happened?
While working on boiler plate for my CRUD I noticed that one of the tables which I have named product_meta
has a corresponding struct name ProductMetum
.
For references, notice that when I create a SELECT
query generates this code
if you notice the return type, you would see that everything is working as expected except that the struct generated is incorrectly name.
Relevant log output
// model definition
type ProductMetum struct {
ID int64 `json:"id"`
ProductID int64 `json:"product_id"`
Key string `json:"key"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// select query generated extract
const getProductMeta = `-- name: GetProductMeta :one
SELECT id, product_id, ` + "`" + `key` + "`" + `, created_at, updated_at FROM ` + "`" + `product_meta` + "`" + `
WHERE id = ? LIMIT 1
`
func (q *Queries) GetProductMeta(ctx context.Context, id int64) (ProductMetum, error) {
row := q.db.QueryRowContext(ctx, getProductMeta, id)
var i ProductMetum
err := row.Scan(
&i.ID,
&i.ProductID,
&i.Key,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
Database schema
-- product meta table for storing not structural details
CREATE TABLE `product_meta` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`product_id` BIGINT NOT NULL,
`key` VARCHAR(50) NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `idx_meta_product` (`product_id` ASC),
UNIQUE INDEX `idx_product_meta_product` (`product_id` ASC, `key` ASC),
CONSTRAINT `fk_product_meta_product`
FOREIGN KEY (`product_id`)
REFERENCES `product` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION
) ENGINE = InnoDB;
SQL queries
No response
Configuration
version: "1"
packages:
- name: "model"
path: "./external/model"
queries: "./external/model/query/"
schema: "./migrations/sqlc-schema/schema.sql"
engine: "mysql"
emit_json_tags: true
emit_prepared_queries: false
emit_interface: false
emit_exact_table_names: false
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