diff --git a/.github/workflows/ci-typescript.yml b/.github/workflows/ci-typescript.yml index 04a1b7b277..f4b94e6c10 100644 --- a/.github/workflows/ci-typescript.yml +++ b/.github/workflows/ci-typescript.yml @@ -19,5 +19,7 @@ jobs: with: repository: sqlc-dev/sqlc-gen-typescript path: typescript + # v0.1.3 + ref: daaf539092421adc15f6c3164279a3470716b560 - run: sqlc diff working-directory: typescript/examples diff --git a/internal/endtoend/testdata/sqlite_skip_todo/db/db.go b/internal/endtoend/testdata/sqlite_skip_todo/db/db.go new file mode 100644 index 0000000000..bdb151c184 --- /dev/null +++ b/internal/endtoend/testdata/sqlite_skip_todo/db/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.25.0 + +package 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, + } +} diff --git a/internal/endtoend/testdata/sqlite_skip_todo/db/models.go b/internal/endtoend/testdata/sqlite_skip_todo/db/models.go new file mode 100644 index 0000000000..a1065e0b7e --- /dev/null +++ b/internal/endtoend/testdata/sqlite_skip_todo/db/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.25.0 + +package db + +import ( + "database/sql" +) + +type Foo struct { + Bar sql.NullString +} diff --git a/internal/endtoend/testdata/sqlite_skip_todo/db/query.sql.go b/internal/endtoend/testdata/sqlite_skip_todo/db/query.sql.go new file mode 100644 index 0000000000..de32605668 --- /dev/null +++ b/internal/endtoend/testdata/sqlite_skip_todo/db/query.sql.go @@ -0,0 +1,66 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.25.0 +// source: query.sql + +package db + +import ( + "context" + "database/sql" +) + +const getFoo = `-- name: GetFoo :many +SELECT bar FROM foo +WHERE bar = ? +` + +func (q *Queries) GetFoo(ctx context.Context, bar sql.NullString) ([]sql.NullString, error) { + rows, err := q.db.QueryContext(ctx, getFoo, bar) + if err != nil { + return nil, err + } + defer rows.Close() + var items []sql.NullString + for rows.Next() { + var bar sql.NullString + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listFoo = `-- name: ListFoo :many +SELECT bar FROM foo +` + +func (q *Queries) ListFoo(ctx context.Context) ([]sql.NullString, error) { + rows, err := q.db.QueryContext(ctx, listFoo) + if err != nil { + return nil, err + } + defer rows.Close() + var items []sql.NullString + for rows.Next() { + var bar sql.NullString + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/internal/endtoend/testdata/sqlite_skip_todo/query.sql b/internal/endtoend/testdata/sqlite_skip_todo/query.sql new file mode 100644 index 0000000000..e51c45c8c1 --- /dev/null +++ b/internal/endtoend/testdata/sqlite_skip_todo/query.sql @@ -0,0 +1,16 @@ +-- name: PragmaForeignKeysEnable :exec +PRAGMA foreign_keys = 1; + +-- name: ListFoo :many +SELECT * FROM foo; + +-- name: PragmaForeignKeysDisable :exec +PRAGMA foreign_keys = 0; + +-- name: PragmaForeignKeysGet :one +PRAGMA foreign_keys; + +-- name: GetFoo :many +SELECT * FROM foo +WHERE bar = ?; + diff --git a/internal/endtoend/testdata/sqlite_skip_todo/schema.sql b/internal/endtoend/testdata/sqlite_skip_todo/schema.sql new file mode 100644 index 0000000000..010d09e16f --- /dev/null +++ b/internal/endtoend/testdata/sqlite_skip_todo/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE foo ( + bar text +); diff --git a/internal/endtoend/testdata/sqlite_skip_todo/sqlc.json b/internal/endtoend/testdata/sqlite_skip_todo/sqlc.json new file mode 100644 index 0000000000..cbd787d930 --- /dev/null +++ b/internal/endtoend/testdata/sqlite_skip_todo/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "2", + "sql": [ + { + "engine": "sqlite", + "queries": "query.sql", + "schema": "schema.sql", + "gen": { + "go": { + "package": "db", + "out": "db" + } + } + } + ] +} diff --git a/internal/engine/sqlite/parse.go b/internal/engine/sqlite/parse.go index 6da7b87112..13425b156e 100644 --- a/internal/engine/sqlite/parse.go +++ b/internal/engine/sqlite/parse.go @@ -69,6 +69,7 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { converter := &cc{} out := converter.convert(stmt) if _, ok := out.(*ast.TODO); ok { + loc = stmt.GetStop().GetStop() + 2 continue } len := (stmt.GetStop().GetStop() + 1) - loc