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

Struct with Meta suffix gets changed to Metum #1217

Closed
tjgurwara99 opened this issue Sep 26, 2021 · 1 comment · Fixed by #1228
Closed

Struct with Meta suffix gets changed to Metum #1217

tjgurwara99 opened this issue Sep 26, 2021 · 1 comment · Fixed by #1228
Labels
bug Something isn't working upstream Issue is caused by a dependency 🔧 golang
Milestone

Comments

@tjgurwara99
Copy link

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

@tjgurwara99 tjgurwara99 added bug Something isn't working triage New issues that hasn't been reviewed labels Sep 26, 2021
@kyleconroy kyleconroy added 🔧 golang 📚 postgresql wontfix This will not be worked on future In the year 3000... bug Something isn't working upstream Issue is caused by a dependency and removed bug Something isn't working triage New issues that hasn't been reviewed wontfix This will not be worked on 📚 postgresql future In the year 3000... labels Oct 9, 2021
@kyleconroy
Copy link
Collaborator

I've reported this as an upstream issue, but will add a fix for it in sqlc as well.

jinzhu/inflection#21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream Issue is caused by a dependency 🔧 golang
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants