sqlc-dev / sqlc

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

SQL Pathing is incompatible with Sveltekit Route Params #3229

Open tamsanh opened 7 months ago

tamsanh commented 7 months ago

Version

1.25.0

What happened?

I've got a sveltekit project and I'm using sqlc to generate my sql code.

When I try to generate a query file located under a path that includes square brackets, sqlc does not work because it is not finding the file.

Moving the file to another path without square brackets works.

Seems like it might be an issue with filepath.Glob?

version: "2"
plugins:
  - name: ts
    wasm:
      url: https://downloads.sqlc.dev/plugin/sqlc-gen-typescript_0.1.3.wasm
      sha256: 287df8f6cc06377d67ad5ba02c9e0f00c585509881434d15ea8bd9fc751a9368
sql:

  - schema:
      - db/migrations
    queries:
      - src/routes/[account_id]/queries.sql
    engine: postgresql
    codegen:
      - out: src/routes/[account_id]/generated
        plugin: ts
        options:
          runtime: node
          driver: pg

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

No response

Playground URL

No response

What operating system are you using?

No response

What database engines are you using?

No response

What type of code are you generating?

No response

kyleconroy commented 7 months ago

Can you try escaping the square brackets with \\? I think following should work

version: "2"
plugins:
  - name: ts
    wasm:
      url: https://downloads.sqlc.dev/plugin/sqlc-gen-typescript_0.1.3.wasm
      sha256: 287df8f6cc06377d67ad5ba02c9e0f00c585509881434d15ea8bd9fc751a9368
sql:

  - schema:
      - db/migrations
    queries:
      - "src/routes/\\[account_id\\]/queries.sql"
    engine: postgresql
    codegen:
      - out: src/routes/[account_id]/generated
        plugin: ts
        options:
          runtime: node
          driver: pg