sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.44k stars 803 forks source link

emoji in queries generate broken queries #3478

Open josharian opened 4 months ago

josharian commented 4 months ago

Version

1.26.0

What happened?

In query.sql:

-- name: EmojiOops :exec
SELECT
    '🤷' AS emoji
limit
    1;

Generated in query.sql.go:

const emojiOops = `-- name: EmojiOops :exec
SELECT
    '🤷' AS emoji
limit
`

Observe the missing 1; at the end. Looks like somebody is counting bytes instead of runes?

Yes, this happened in real code. It was pretty confusing to debug.

Appears to be happen with some dbs and not others? Didn't dig much.

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

---
version: 2
sql:
  - engine: sqlite
    schema: schema.sql
    queries: query.sql
    gen:
      go:
        package: [redacted]
        out: .
        emit_exact_table_names: true
        emit_result_struct_pointers: true
        emit_params_struct_pointers: true
        query_parameter_limit: 3
        output_db_file_name: sqlc.go

Playground URL

https://play.sqlc.dev/p/984f440606d6a2084f363f711e283a31b031901ea70d613a250636784d5cad33

What operating system are you using?

Linux, macOS

What database engines are you using?

SQLite

What type of code are you generating?

Go

1AbdulKareem commented 4 months ago

I don't think that you can have a such a field in a struct !

type Table Struct { 🤷 string , ... }

I don't know what framework frontend technology your are using , but json/xml common unMarshalers won't parse your field correctly . I know this won't help.

But if it is a must , I suggest you to create custom go code to adapt the SQLC model structs => your response structs/json/xml/whatever_format .

josharian commented 4 months ago

I don't think that you can have a such a field in a struct !

AS emoji in the query changes the name to Emoji.