snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
This commit is contained in:
88
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/go/db.go
vendored
Normal file
88
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/go/db.go
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package querytest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
ExecContext(context.Context, string, ...any) (sql.Result, error)
|
||||
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
|
||||
QueryRowContext(context.Context, string, ...any) *sql.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
|
||||
q := Queries{db: db}
|
||||
var err error
|
||||
if q.funcParamIdentStmt, err = db.PrepareContext(ctx, funcParamIdent); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query FuncParamIdent: %w", err)
|
||||
}
|
||||
return &q, nil
|
||||
}
|
||||
|
||||
func (q *Queries) Close() error {
|
||||
var err error
|
||||
if q.funcParamIdentStmt != nil {
|
||||
if cerr := q.funcParamIdentStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing funcParamIdentStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...any) (sql.Result, error) {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.ExecContext(ctx, args...)
|
||||
default:
|
||||
return q.db.ExecContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...any) (*sql.Rows, error) {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.QueryContext(ctx, args...)
|
||||
default:
|
||||
return q.db.QueryContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...any) *sql.Row {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.QueryRowContext(ctx, args...)
|
||||
default:
|
||||
return q.db.QueryRowContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
tx *sql.Tx
|
||||
funcParamIdentStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
tx: tx,
|
||||
funcParamIdentStmt: q.funcParamIdentStmt,
|
||||
}
|
||||
}
|
||||
15
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/go/models.go
vendored
Normal file
15
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/go/models.go
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package querytest
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Foo struct {
|
||||
ID int64
|
||||
Name string
|
||||
Bar sql.NullString
|
||||
}
|
||||
56
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/go/query.sql.go
vendored
Normal file
56
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/go/query.sql.go
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: query.sql
|
||||
|
||||
package querytest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const funcParamIdent = `-- name: FuncParamIdent :many
|
||||
SELECT name FROM foo
|
||||
WHERE name = ?1
|
||||
AND id IN (/*SLICE:favourites*/?)
|
||||
`
|
||||
|
||||
type FuncParamIdentParams struct {
|
||||
Slug string
|
||||
Favourites []int64
|
||||
}
|
||||
|
||||
func (q *Queries) FuncParamIdent(ctx context.Context, arg FuncParamIdentParams) ([]string, error) {
|
||||
query := funcParamIdent
|
||||
var queryParams []any
|
||||
queryParams = append(queryParams, arg.Slug)
|
||||
if len(arg.Favourites) > 0 {
|
||||
for _, v := range arg.Favourites {
|
||||
queryParams = append(queryParams, v)
|
||||
}
|
||||
query = strings.Replace(query, "/*SLICE:favourites*/?", strings.Repeat(",?", len(arg.Favourites))[1:], 1)
|
||||
} else {
|
||||
query = strings.Replace(query, "/*SLICE:favourites*/?", "NULL", 1)
|
||||
}
|
||||
rows, err := q.query(ctx, nil, query, queryParams...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var name string
|
||||
if err := rows.Scan(&name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, name)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
4
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/query.sql
vendored
Normal file
4
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/query.sql
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/* name: FuncParamIdent :many */
|
||||
SELECT name FROM foo
|
||||
WHERE name = sqlc.arg(slug)
|
||||
AND id IN (sqlc.slice(favourites));
|
||||
2
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/schema.sql
vendored
Normal file
2
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/schema.sql
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
CREATE TABLE foo (id int not null, name text not null, bar text);
|
||||
|
||||
13
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/sqlc.json
vendored
Normal file
13
internal/endtoend/testdata/sqlc_slice_prepared/sqlite/sqlc.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "1",
|
||||
"packages": [
|
||||
{
|
||||
"engine": "sqlite",
|
||||
"path": "go",
|
||||
"name": "querytest",
|
||||
"schema": "schema.sql",
|
||||
"queries": "query.sql",
|
||||
"emit_prepared_queries": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user