Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cmd/sqlc: Support for changing the CWD #4017

Open
@otaxhu

Description

@otaxhu

What do you want to change?

I'm currently having a problem with sqlc-gen-from-template plugin in which I'm passing the path of a template as following:

sqlc.yml:

version: "2"
plugins:
- name: sqlc-gen-from-template
  process:
    cmd: sqlc-gen-from-template # https://github.com/fdietze/sqlc-gen-from-template
sql:
  - engine: "sqlite"
    queries: "src/persistence/queries.sql"
    schema: "src/persistence/schema.sql"
    codegen:
    - out: src/persistence/gen/
      plugin: sqlc-gen-from-template
      options:
        template: "src/persistence/rust_rusqlite.go.tmpl"
        formatter_cmd: "cargo fmt"

I'm using a meson script like the following to call sqlc generate:

src/meson.build:

run_command(
  sqlc, 'generate', '-f', meson.project_source_root() / 'sqlc.yml',
  env: [
    'PATH=' + fs.parent(find_program('sqlc-gen-from-template').full_path())
  ],
  check: true,
)

But I'm getting this error:

--- stderr ---
# package sqlc-gen-from-template
error generating code: process: error running command 2025/07/12 22:17:50 Error parsing template file: open src/persistence/rust_rusqlite.go.tmpl: no such file or directory

This error is produced because the sqlc command is being run with src/ as the CWD due to the meson script being there, so it is searching for src/src/persistence/rust_rusqlite.go.tmpl, which doesn't exists.

So this is the feature request:

Add support for sqlc command to change the CWD

Acceptance criteria:

  • It must also work with plugins, that is, the CWD option should be inherited to the plugin's spawn process. I don't how it should work with WebAssembly (I guess it should be a noop since it doesn't have access to the filesystem)

What database engines need to be changed?

No response

What programming language backends need to be changed?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions