Skip to content

Code generation error : outputted Go package name with '/' not supported #3937

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

Open
bemoche opened this issue Apr 19, 2025 · 1 comment
Open

Comments

@bemoche
Copy link

bemoche commented Apr 19, 2025

Version

1.29.0

What happened?

Code generation with SQLite errors out when the output package name has '/' in it.

Relevant log output

// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0

package internal/db

import (
	"context"
	"database/sql"
)

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

func New(db DBTX) *Queries {
	return &Queries{db: db}
}

type Queries struct {
	db DBTX
}

func (q *Queries) WithTx(tx *sql.Tx) *Queries {
	return &Queries{
		db: tx,
	}
}

# package internal/db
error generating code: source error: 7:17: expected ';', found '/'

Database schema

-- +goose Up
CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    email VARCHAR(255) NOT NULL,
    password VARCHAR(255) NOT NULL,
    first_name VARCHAR(255),
    last_name VARCHAR(255),
    created_at TIMESTAMP NOT NULL DEFAULT (NOW()),
    updated_at TIMESTAMP NOT NULL DEFAULT (NOW()),
    deleted_at TIMESTAMP,
    deleted BOOLEAN NOT NULL DEFAULT FALSE
);

-- +goose Down
DROP TABLE users;

SQL queries

-- name: CreateUser :one
INSERT INTO users (email, password, first_name, last_name)
VALUES (?, ?, ?, ?)
RETURNING *;

Configuration

version: "2"
sql:
  - engine: "sqlite"
    queries: "internal/db/sql/queries"
    schema: "internal/db/sql/schema"
    database:
      uri: "http://localhost:9000"
    gen:
      go:
        package: "internal/db"
        out: "internal/db/sqlc"

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

SQLite

What type of code are you generating?

Go

@bemoche bemoche added the bug Something isn't working label Apr 19, 2025
@bemoche bemoche changed the title Code generation error : Go package name with '/' not supported Code generation error : outputted Go package name with '/' not supported Apr 19, 2025
@rbarbey
Copy link

rbarbey commented May 2, 2025

I just ran into this issue myself. I want to have a db package inside internal directory so one dir less than what you do. I have

package: "db"
out: "internal/db"

So I guess you need to do something like

package: "db"
out: "internal/db/sqlc"

although I'm not 100% sure whether Go allows to have package name and dir name deviate ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants