Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions docs/howto/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ type Queries struct {
db DBTX
}

const deleteAuthor = `-- name: DeleteAuthor :exec
const deleteAuthorSQL = `-- name: DeleteAuthor :exec
DELETE FROM authors WHERE id = $1
`

func (q *Queries) DeleteAuthor(ctx context.Context, id int) error {
_, err := q.db.ExecContext(ctx, deleteAuthor, id)
_, err := q.db.ExecContext(ctx, deleteAuthorSQL, id)
return err
}
```
12 changes: 6 additions & 6 deletions docs/howto/insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ type Queries struct {
db DBTX
}

const createAuthor = `-- name: CreateAuthor :exec
const createAuthorSQL = `-- name: CreateAuthor :exec
INSERT INTO authors (bio) VALUES ($1)
`

func (q *Queries) CreateAuthor(ctx context.Context, bio string) error {
_, err := q.db.ExecContext(ctx, createAuthor, bio)
_, err := q.db.ExecContext(ctx, createAuthorSQL, bio)
return err
}
```
Expand Down Expand Up @@ -112,7 +112,7 @@ import (
"database/sql"
)

const createAuthor = `-- name: CreateAuthor :one
const createAuthorSQL = `-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
Expand All @@ -127,13 +127,13 @@ type CreateAuthorParams struct {
}

func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) {
row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio)
row := q.db.QueryRowContext(ctx, createAuthorSQL, arg.Name, arg.Bio)
var i Author
err := row.Scan(&i.ID, &i.Name, &i.Bio)
return i, err
}

const createAuthorAndReturnId = `-- name: CreateAuthorAndReturnId :one
const createAuthorAndReturnIdSQL = `-- name: CreateAuthorAndReturnId :one
INSERT INTO authors (
name, bio
) VALUES (
Expand All @@ -148,7 +148,7 @@ type CreateAuthorAndReturnIdParams struct {
}

func (q *Queries) CreateAuthorAndReturnId(ctx context.Context, arg CreateAuthorAndReturnIdParams) (int64, error) {
row := q.db.QueryRowContext(ctx, createAuthorAndReturnId, arg.Name, arg.Bio)
row := q.db.QueryRowContext(ctx, createAuthorAndReturnIdSQL, arg.Name, arg.Bio)
var id int64
err := row.Scan(&id)
return id, err
Expand Down
6 changes: 3 additions & 3 deletions docs/howto/prepared_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func New(db DBTX) *Queries {
func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
q := Queries{db: db}
var err error
if q.getRecordStmt, err = db.PrepareContext(ctx, getRecord); err != nil {
if q.getRecordStmt, err = db.PrepareContext(ctx, getRecordSQL); err != nil {
return nil, fmt.Errorf("error preparing query GetRecord: %w", err)
}
return &q, nil
Expand Down Expand Up @@ -76,13 +76,13 @@ func (q *Queries) WithTx(tx *sql.Tx) *Queries {
}
}

const getRecord = `-- name: GetRecord :one
const getRecordSQL = `-- name: GetRecord :one
SELECT id FROM records
WHERE id = $1
`

func (q *Queries) GetRecord(ctx context.Context, id int32) (int32, error) {
row := q.queryRow(ctx, q.getRecordStmt, getRecord, id)
row := q.queryRow(ctx, q.getRecordStmt, getRecordSQL, id)
err := row.Scan(&id)
return id, err
}
Expand Down
8 changes: 4 additions & 4 deletions docs/howto/query_count.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ type Queries struct {
db DBTX
}

const countAuthors = `-- name: CountAuthors :one
const countAuthorsSQL = `-- name: CountAuthors :one
SELECT count(*) FROM authors
`

func (q *Queries) CountAuthors(ctx context.Context) (int, error) {
row := q.db.QueryRowContext(ctx, countAuthors)
row := q.db.QueryRowContext(ctx, countAuthorsSQL)
var i int
err := row.Scan(&i)
return i, err
}

const countAuthorsByTown = `-- name: CountAuthorsByTown :many
const countAuthorsByTownSQL = `-- name: CountAuthorsByTown :many
SELECT hometown, count(*) FROM authors
GROUP BY 1
ORDER BY 1
Expand All @@ -59,7 +59,7 @@ type CountAuthorsByTownRow struct {
}

func (q *Queries) CountAuthorsByTown(ctx context.Context) ([]CountAuthorsByTownRow, error) {
rows, err := q.db.QueryContext(ctx, countAuthorsByTown)
rows, err := q.db.QueryContext(ctx, countAuthorsByTownSQL)
if err != nil {
return nil, err
}
Expand Down
24 changes: 12 additions & 12 deletions docs/howto/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,25 @@ type Queries struct {
db DBTX
}

const getAuthor = `-- name: GetAuthor :one
const getAuthorSQL = `-- name: GetAuthor :one
SELECT id, bio, birth_year FROM authors
WHERE id = $1
`

func (q *Queries) GetAuthor(ctx context.Context, id int) (Author, error) {
row := q.db.QueryRowContext(ctx, getAuthor, id)
row := q.db.QueryRowContext(ctx, getAuthorSQL, id)
var i Author
err := row.Scan(&i.ID, &i.Bio, &i.BirthYear)
return i, err
}

const listAuthors = `-- name: ListAuthors :many
const listAuthorsSQL = `-- name: ListAuthors :many
SELECT id, bio, birth_year FROM authors
ORDER BY id
`

func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) {
rows, err := q.db.QueryContext(ctx, listAuthors)
rows, err := q.db.QueryContext(ctx, listAuthorsSQL)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -172,19 +172,19 @@ type Queries struct {
db DBTX
}

const getBioForAuthor = `-- name: GetBioForAuthor :one
const getBioForAuthorSQL = `-- name: GetBioForAuthor :one
SELECT bio FROM authors
WHERE id = $1
`

func (q *Queries) GetBioForAuthor(ctx context.Context, id int) (string, error) {
row := q.db.QueryRowContext(ctx, getBioForAuthor, id)
row := q.db.QueryRowContext(ctx, getBioForAuthorSQL, id)
var i string
err := row.Scan(&i)
return i, err
}

const getInfoForAuthor = `-- name: GetInfoForAuthor :one
const getInfoForAuthorSQL = `-- name: GetInfoForAuthor :one
SELECT bio, birth_year FROM authors
WHERE id = $1
`
Expand All @@ -195,7 +195,7 @@ type GetInfoForAuthorRow struct {
}

func (q *Queries) GetInfoForAuthor(ctx context.Context, id int) (GetInfoForAuthorRow, error) {
row := q.db.QueryRowContext(ctx, getInfoForAuthor, id)
row := q.db.QueryRowContext(ctx, getInfoForAuthorSQL, id)
var i GetInfoForAuthorRow
err := row.Scan(&i.Bio, &i.BirthYear)
return i, err
Expand Down Expand Up @@ -255,13 +255,13 @@ type Queries struct {
db DBTX
}

const listAuthors = `-- name: ListAuthorsByIDs :many
const listAuthorsSQL = `-- name: ListAuthorsByIDs :many
SELECT id, bio, birth_year FROM authors
WHERE id = ANY($1::int[])
`

func (q *Queries) ListAuthorsByIDs(ctx context.Context, ids []int) ([]Author, error) {
rows, err := q.db.QueryContext(ctx, listAuthors, pq.Array(ids))
rows, err := q.db.QueryContext(ctx, listAuthorsSQL, pq.Array(ids))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -354,13 +354,13 @@ func (q *Queries) WithTx(tx *sql.Tx) *Queries {
}
}

const listAuthorsByIDs = `-- name: ListAuthorsByIDs :many
const listAuthorsByIDsSQL = `-- name: ListAuthorsByIDs :many
SELECT id, bio, birth_year FROM authors
WHERE id IN (/*SLICE:ids*/?)
`

func (q *Queries) ListAuthorsByIDs(ctx context.Context, ids []int64) ([]Author, error) {
sql := listAuthorsByIDs
sql := listAuthorsByIDsSQL
var queryParams []any
if len(ids) == 0 {
return nil, fmt.Errorf("slice ids must have at least one element")
Expand Down
8 changes: 4 additions & 4 deletions docs/howto/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ type Queries struct {
db DBTX
}

const updateAuthorBios = `-- name: UpdateAuthorBios :exec
const updateAuthorBiosSQL = `-- name: UpdateAuthorBios :exec
UPDATE authors SET bio = $1
`

func (q *Queries) UpdateAuthorBios(ctx context.Context, bio string) error {
_, err := q.db.ExecContext(ctx, updateAuthorBios, bio)
_, err := q.db.ExecContext(ctx, updateAuthorBiosSQL, bio)
return err
}
```
Expand Down Expand Up @@ -97,7 +97,7 @@ type Queries struct {
db DBTX
}

const updateAuthor = `-- name: UpdateAuthor :exec
const updateAuthorSQL = `-- name: UpdateAuthor :exec
UPDATE authors SET bio = $2
WHERE id = $1
`
Expand All @@ -108,7 +108,7 @@ type UpdateAuthorParams struct {
}

func (q *Queries) UpdateAuthor(ctx context.Context, arg UpdateAuthorParams) error {
_, err := q.db.ExecContext(ctx, updateAuthor, arg.ID, arg.Bio)
_, err := q.db.ExecContext(ctx, updateAuthorSQL, arg.ID, arg.Bio)
return err
}
```
Expand Down
16 changes: 8 additions & 8 deletions examples/authors/clickhouse/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions examples/authors/duckdb/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading