sqlc
sqlc copied to clipboard
Code generation error : outputted Go package name with '/' not supported
trafficstars
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
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 ...
The package field is the name of the package and the out field is the directory to generate the files.