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:
128
internal/endtoend/testdata/prepared_queries/mysql/go/db.go
vendored
Normal file
128
internal/endtoend/testdata/prepared_queries/mysql/go/db.go
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
// 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.deleteUsersByNameStmt, err = db.PrepareContext(ctx, deleteUsersByName); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query DeleteUsersByName: %w", err)
|
||||
}
|
||||
if q.getUserByIDStmt, err = db.PrepareContext(ctx, getUserByID); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query GetUserByID: %w", err)
|
||||
}
|
||||
if q.insertNewUserStmt, err = db.PrepareContext(ctx, insertNewUser); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query InsertNewUser: %w", err)
|
||||
}
|
||||
if q.insertNewUserWithResultStmt, err = db.PrepareContext(ctx, insertNewUserWithResult); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query InsertNewUserWithResult: %w", err)
|
||||
}
|
||||
if q.listUsersStmt, err = db.PrepareContext(ctx, listUsers); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListUsers: %w", err)
|
||||
}
|
||||
return &q, nil
|
||||
}
|
||||
|
||||
func (q *Queries) Close() error {
|
||||
var err error
|
||||
if q.deleteUsersByNameStmt != nil {
|
||||
if cerr := q.deleteUsersByNameStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing deleteUsersByNameStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.getUserByIDStmt != nil {
|
||||
if cerr := q.getUserByIDStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing getUserByIDStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.insertNewUserStmt != nil {
|
||||
if cerr := q.insertNewUserStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing insertNewUserStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.insertNewUserWithResultStmt != nil {
|
||||
if cerr := q.insertNewUserWithResultStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing insertNewUserWithResultStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.listUsersStmt != nil {
|
||||
if cerr := q.listUsersStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing listUsersStmt: %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
|
||||
deleteUsersByNameStmt *sql.Stmt
|
||||
getUserByIDStmt *sql.Stmt
|
||||
insertNewUserStmt *sql.Stmt
|
||||
insertNewUserWithResultStmt *sql.Stmt
|
||||
listUsersStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
tx: tx,
|
||||
deleteUsersByNameStmt: q.deleteUsersByNameStmt,
|
||||
getUserByIDStmt: q.getUserByIDStmt,
|
||||
insertNewUserStmt: q.insertNewUserStmt,
|
||||
insertNewUserWithResultStmt: q.insertNewUserWithResultStmt,
|
||||
listUsersStmt: q.listUsersStmt,
|
||||
}
|
||||
}
|
||||
15
internal/endtoend/testdata/prepared_queries/mysql/go/models.go
vendored
Normal file
15
internal/endtoend/testdata/prepared_queries/mysql/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 User struct {
|
||||
ID uint64
|
||||
FirstName string
|
||||
LastName sql.NullString
|
||||
}
|
||||
104
internal/endtoend/testdata/prepared_queries/mysql/go/query.sql.go
vendored
Normal file
104
internal/endtoend/testdata/prepared_queries/mysql/go/query.sql.go
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: query.sql
|
||||
|
||||
package querytest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const deleteUsersByName = `-- name: DeleteUsersByName :execrows
|
||||
DELETE FROM users WHERE first_name = ? AND last_name = ?
|
||||
`
|
||||
|
||||
type DeleteUsersByNameParams struct {
|
||||
FirstName string
|
||||
LastName sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteUsersByName(ctx context.Context, arg DeleteUsersByNameParams) (int64, error) {
|
||||
result, err := q.exec(ctx, q.deleteUsersByNameStmt, deleteUsersByName, arg.FirstName, arg.LastName)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT first_name, id, last_name FROM users WHERE id = ?
|
||||
`
|
||||
|
||||
type GetUserByIDRow struct {
|
||||
FirstName string
|
||||
ID uint64
|
||||
LastName sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, targetID uint64) (GetUserByIDRow, error) {
|
||||
row := q.queryRow(ctx, q.getUserByIDStmt, getUserByID, targetID)
|
||||
var i GetUserByIDRow
|
||||
err := row.Scan(&i.FirstName, &i.ID, &i.LastName)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertNewUser = `-- name: InsertNewUser :exec
|
||||
INSERT INTO users (first_name, last_name) VALUES (?, ?)
|
||||
`
|
||||
|
||||
type InsertNewUserParams struct {
|
||||
FirstName string
|
||||
LastName sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) InsertNewUser(ctx context.Context, arg InsertNewUserParams) error {
|
||||
_, err := q.exec(ctx, q.insertNewUserStmt, insertNewUser, arg.FirstName, arg.LastName)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertNewUserWithResult = `-- name: InsertNewUserWithResult :execresult
|
||||
INSERT INTO users (first_name, last_name) VALUES (?, ?)
|
||||
`
|
||||
|
||||
type InsertNewUserWithResultParams struct {
|
||||
FirstName string
|
||||
LastName sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) InsertNewUserWithResult(ctx context.Context, arg InsertNewUserWithResultParams) (sql.Result, error) {
|
||||
return q.exec(ctx, q.insertNewUserWithResultStmt, insertNewUserWithResult, arg.FirstName, arg.LastName)
|
||||
}
|
||||
|
||||
const listUsers = `-- name: ListUsers :many
|
||||
SELECT first_name, last_name FROM users
|
||||
`
|
||||
|
||||
type ListUsersRow struct {
|
||||
FirstName string
|
||||
LastName sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) ListUsers(ctx context.Context) ([]ListUsersRow, error) {
|
||||
rows, err := q.query(ctx, q.listUsersStmt, listUsers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListUsersRow
|
||||
for rows.Next() {
|
||||
var i ListUsersRow
|
||||
if err := rows.Scan(&i.FirstName, &i.LastName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
Reference in New Issue
Block a user