sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Named parameters shortcut not working for mysql

Open meblum opened this issue 1 year ago • 2 comments

Version

1.25.0

What happened?

Trying to use the @ operator as a shortcut to sqlc.arg, but it does not work when engine is mysql. The parameter is incorrectly being parsed as a static value.

relevant feature documentation: https://docs.sqlc.dev/en/stable/howto/named_parameters.html#naming-parameters

Relevant log output

// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: query.sql

package db

import (
	"context"
	"database/sql"
)

const getMyTableValue = `-- name: GetMyTableValue :one
SELECT id FROM my_table
WHERE id = @value_id LIMIT 1
`

func (q *Queries) GetMyTableValue(ctx context.Context) (sql.NullString, error) {
	row := q.db.QueryRowContext(ctx, getMyTableValue)
	var id sql.NullString
	err := row.Scan(&id)
	return id, err
}

Database schema

CREATE TABLE my_table (
  id varchar(255)
);

SQL queries

-- name: GetMyTableValue :one
SELECT * FROM my_table
WHERE id = @value_id LIMIT 1;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "mysql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/9c89fc27cef434eb92e45c7215a562aa26c184cd68649be2716b7ac4016b7133

What operating system are you using?

No response

What database engines are you using?

MySQL

What type of code are you generating?

Go

meblum avatar Feb 05 '24 17:02 meblum

@meblum this is not a bug. The @ operator is not supported as a shortcut for sqlc.arg() in mysql.

jakoguta avatar Feb 11 '24 10:02 jakoguta

Then perhaps it should be documented as so?

meblum avatar Feb 11 '24 17:02 meblum