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

This commit is contained in:
upstream-mirror
2026-09-16 02:17:34 +05:00
commit 0f4df23290
7340 changed files with 238743 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
import (
"context"
"database/sql"
)
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}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
return &Queries{
db: tx,
}
}

View File

@@ -0,0 +1,9 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
type Bar struct {
ID uint64
}

View File

@@ -0,0 +1,20 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: query.sql
package querytest
import (
"context"
)
const aliasBar = `-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = ?
`
func (q *Queries) AliasBar(ctx context.Context, id uint64) error {
_, err := q.db.ExecContext(ctx, aliasBar, id)
return err
}

View File

@@ -0,0 +1,3 @@
-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = ?;

View File

@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

View File

@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

View File

@@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
import (
"context"
"github.com/jackc/pgconn"
"github.com/jackc/pgx/v4"
)
type DBTX interface {
Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
Query(context.Context, string, ...any) (pgx.Rows, error)
QueryRow(context.Context, string, ...any) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}

View File

@@ -0,0 +1,9 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
type Bar struct {
ID int32
}

View File

@@ -0,0 +1,20 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: query.sql
package querytest
import (
"context"
)
const aliasBar = `-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = $1
`
func (q *Queries) AliasBar(ctx context.Context, id int32) error {
_, err := q.db.Exec(ctx, aliasBar, id)
return err
}

View File

@@ -0,0 +1,3 @@
-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = $1;

View File

@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

View File

@@ -0,0 +1,13 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

View File

@@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type DBTX interface {
Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
Query(context.Context, string, ...any) (pgx.Rows, error)
QueryRow(context.Context, string, ...any) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}

View File

@@ -0,0 +1,9 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
type Bar struct {
ID int32
}

View File

@@ -0,0 +1,20 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: query.sql
package querytest
import (
"context"
)
const aliasBar = `-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = $1
`
func (q *Queries) AliasBar(ctx context.Context, id int32) error {
_, err := q.db.Exec(ctx, aliasBar, id)
return err
}

View File

@@ -0,0 +1,3 @@
-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = $1;

View File

@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

View File

@@ -0,0 +1,13 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

View File

@@ -0,0 +1,31 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
import (
"context"
"database/sql"
)
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}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
return &Queries{
db: tx,
}
}

View File

@@ -0,0 +1,9 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
type Bar struct {
ID int32
}

View File

@@ -0,0 +1,20 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: query.sql
package querytest
import (
"context"
)
const aliasBar = `-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = $1
`
func (q *Queries) AliasBar(ctx context.Context, id int32) error {
_, err := q.db.ExecContext(ctx, aliasBar, id)
return err
}

View File

@@ -0,0 +1,3 @@
-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = $1;

View File

@@ -0,0 +1 @@
CREATE TABLE bar (id serial not null);

View File

@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

View File

@@ -0,0 +1,31 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
import (
"context"
"database/sql"
)
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}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
return &Queries{
db: tx,
}
}

View File

@@ -0,0 +1,9 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package querytest
type Bar struct {
ID int64
}

View File

@@ -0,0 +1,20 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: query.sql
package querytest
import (
"context"
)
const aliasBar = `-- name: AliasBar :exec
DELETE FROM bar AS b
WHERE b.id = ?
`
func (q *Queries) AliasBar(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, aliasBar, id)
return err
}

View File

@@ -0,0 +1,3 @@
-- name: AliasBar :exec
DELETE FROM bar AS b
WHERE b.id = ?;

View File

@@ -0,0 +1,2 @@
CREATE TABLE bar (id integer NOT NULL PRIMARY KEY AUTOINCREMENT);

View File

@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "sqlite",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "postgresql", "--schema", "schema.sql", "--ast", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,2 @@
-- name: GetAuthorName :one
SELECT name FROM authors WHERE id = $1;

View File

@@ -0,0 +1,5 @@
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);

View File

@@ -0,0 +1,136 @@
[
{
"name": "GetAuthorName",
"cmd": ":one",
"columns": [
{
"name": "name",
"type": {
"name": "text"
},
"table": "authors"
}
],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
}
}
],
"ast": {
"tag": "RawStmt",
"stmt": {
"tag": "SelectStmt",
"distinct_clause": {
"tag": "List"
},
"target_list": {
"tag": "List",
"items": [
{
"tag": "ResTarget",
"indirection": {
"tag": "List"
},
"val": {
"tag": "ColumnRef",
"name": "",
"fields": {
"tag": "List",
"items": [
{
"tag": "String",
"str": "name"
}
]
},
"location": 35
},
"location": 35
}
]
},
"from_clause": {
"tag": "List",
"items": [
{
"tag": "RangeVar",
"relname": "authors",
"inh": true,
"relpersistence": 112,
"location": 45
}
]
},
"where_clause": {
"tag": "A_Expr",
"kind": 1,
"name": {
"tag": "List",
"items": [
{
"tag": "String",
"str": "="
}
]
},
"lexpr": {
"tag": "ColumnRef",
"name": "",
"fields": {
"tag": "List",
"items": [
{
"tag": "String",
"str": "id"
}
]
},
"location": 59
},
"rexpr": {
"tag": "ParamRef",
"number": 1,
"location": 64,
"dollar": true
},
"location": 62
},
"group_clause": {
"tag": "List"
},
"having_clause": {
"tag": "TODO"
},
"window_clause": {
"tag": "List"
},
"values_lists": {
"tag": "List"
},
"sort_clause": {
"tag": "List"
},
"limit_offset": {
"tag": "TODO"
},
"limit_count": {
"tag": "TODO"
},
"locking_clause": {
"tag": "List"
},
"op": 0,
"all": false
},
"stmt_location": 0,
"stmt_len": 66
}
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "clickhouse", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1 @@
INSERT INTO events (id, name, tag, amount, created) VALUES (1, 'signup', NULL, 9.5, '2024-01-01 00:00:00');

View File

@@ -0,0 +1,2 @@
-- name: ListEvents :many
SELECT id, name, tag, amount, created FROM events;

View File

@@ -0,0 +1,7 @@
CREATE TABLE events (
id UInt64,
name String,
tag Nullable(String),
amount Float64,
created DateTime
) ENGINE = MergeTree ORDER BY id;

View File

@@ -0,0 +1,45 @@
[
{
"name": "ListEvents",
"cmd": ":many",
"columns": [
{
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
},
{
"name": "name",
"type": {
"name": "string"
},
"table": "events"
},
{
"name": "tag",
"type": {
"name": "string",
"nullable": true
},
"table": "events"
},
{
"name": "amount",
"type": {
"name": "float64"
},
"table": "events"
},
{
"name": "created",
"type": {
"name": "datetime"
},
"table": "events"
}
],
"params": []
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "duckdb", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,2 @@
-- name: ListAuthors :many
SELECT id, name, bio, royalties, created FROM authors;

View File

@@ -0,0 +1,7 @@
CREATE TABLE authors (
id BIGINT PRIMARY KEY,
name TEXT NOT NULL,
bio TEXT,
royalties DECIMAL(10,2) NOT NULL,
created TIMESTAMP NOT NULL
);

View File

@@ -0,0 +1,53 @@
[
{
"name": "ListAuthors",
"cmd": ":many",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
},
{
"name": "name",
"type": {
"name": "varchar"
},
"table": "authors"
},
{
"name": "bio",
"type": {
"name": "varchar",
"nullable": true
},
"table": "authors"
},
{
"name": "royalties",
"type": {
"name": "decimal",
"args": [
{
"int": 10
},
{
"int": 2
}
]
},
"table": "authors"
},
{
"name": "created",
"type": {
"name": "timestamp"
},
"table": "authors"
}
],
"params": []
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "googlesql", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,2 @@
-- name: GetUser :one
SELECT id, name FROM users WHERE id = @id;

View File

@@ -0,0 +1,5 @@
CREATE TABLE users (
id INT64 NOT NULL,
name STRING(MAX) NOT NULL,
bio STRING(MAX),
) PRIMARY KEY (id);

View File

@@ -0,0 +1,39 @@
[
{
"name": "GetUser",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
},
{
"name": "name",
"type": {
"name": "string",
"args": [
{
"ident": "max"
}
]
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "mssql", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,2 @@
-- name: ListAuthors :many
SELECT id, name, bio, royalties, created FROM authors;

View File

@@ -0,0 +1,7 @@
CREATE TABLE authors (
id BIGINT IDENTITY(1,1) PRIMARY KEY,
name NVARCHAR(100) NOT NULL,
bio NVARCHAR(MAX),
royalties DECIMAL(10,2) NOT NULL,
created DATETIME2 NOT NULL
);

View File

@@ -0,0 +1,68 @@
[
{
"name": "ListAuthors",
"cmd": ":many",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
},
{
"name": "name",
"type": {
"name": "nvarchar",
"args": [
{
"int": 100
}
]
},
"table": "authors"
},
{
"name": "bio",
"type": {
"name": "nvarchar",
"nullable": true,
"args": [
{
"ident": "max"
}
]
},
"table": "authors"
},
{
"name": "royalties",
"type": {
"name": "decimal",
"args": [
{
"int": 10
},
{
"int": 2
}
]
},
"table": "authors"
},
{
"name": "created",
"type": {
"name": "datetime2",
"args": [
{
"int": 7
}
]
},
"table": "authors"
}
],
"params": []
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "mysql", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,2 @@
-- name: GetUser :one
SELECT id, name FROM users WHERE id = ?;

View File

@@ -0,0 +1,5 @@
CREATE TABLE users (
id BIGINT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
bio TEXT
);

View File

@@ -0,0 +1,39 @@
[
{
"name": "GetUser",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
},
{
"name": "name",
"type": {
"name": "varchar",
"args": [
{
"int": 255
}
]
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "postgresql", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,2 @@
-- name: GetAuthor :one
SELECT * FROM authors WHERE id = $1;

View File

@@ -0,0 +1,5 @@
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);

View File

@@ -0,0 +1,42 @@
[
{
"name": "GetAuthor",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
},
{
"name": "name",
"type": {
"name": "text"
},
"table": "authors"
},
{
"name": "bio",
"type": {
"name": "text",
"nullable": true
},
"table": "authors"
}
],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "sqlite", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,2 @@
-- name: GetUser :one
SELECT id, name FROM users WHERE id = ?;

View File

@@ -0,0 +1,5 @@
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER
);

View File

@@ -0,0 +1,34 @@
[
{
"name": "GetUser",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "integer"
},
"table": "users"
},
{
"name": "name",
"type": {
"name": "text"
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "integer"
},
"table": "users"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "duckdb", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,13 @@
-- name: CreateAuthor :one
INSERT INTO authors (id, name, bio) VALUES ($1, $2, $3) RETURNING id;
-- name: UpdateAuthor :exec
UPDATE authors SET name = $name, bio = $bio WHERE id = $id;
-- name: DeleteBooksByAuthor :exec
DELETE FROM books USING authors a WHERE books.author_id = a.id AND a.name = $1;
-- name: TitlesFromBooks :many
INSERT INTO books (id, author_id, title)
SELECT id + 1000, author_id, upper(title) FROM books WHERE price > $min_price
RETURNING id, title;

View File

@@ -0,0 +1,12 @@
CREATE TABLE authors (
id BIGINT PRIMARY KEY,
name TEXT NOT NULL,
bio TEXT
);
CREATE TABLE books (
id BIGINT PRIMARY KEY,
author_id BIGINT NOT NULL,
title TEXT NOT NULL,
price DECIMAL(10,2)
);

View File

@@ -0,0 +1,144 @@
[
{
"name": "CreateAuthor",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
}
],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
}
},
{
"number": 2,
"column": {
"name": "name",
"type": {
"name": "varchar"
},
"table": "authors"
}
},
{
"number": 3,
"column": {
"name": "bio",
"type": {
"name": "varchar",
"nullable": true
},
"table": "authors"
}
}
]
},
{
"name": "UpdateAuthor",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "varchar"
},
"table": "authors"
}
},
{
"number": 2,
"column": {
"name": "bio",
"type": {
"name": "varchar",
"nullable": true
},
"table": "authors"
}
},
{
"number": 3,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
}
}
]
},
{
"name": "DeleteBooksByAuthor",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "varchar"
},
"table": "authors"
}
}
]
},
{
"name": "TitlesFromBooks",
"cmd": ":many",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "books"
},
{
"name": "title",
"type": {
"name": "varchar"
},
"table": "books"
}
],
"params": [
{
"number": 1,
"column": {
"name": "price",
"type": {
"name": "decimal",
"nullable": true,
"args": [
{
"int": 10
},
{
"int": 2
}
]
},
"table": "books"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "googlesql", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,17 @@
-- name: CreateUser :exec
INSERT INTO users (id, name, bio) VALUES (@id, @name, @bio);
-- name: CreateUserReturning :one
INSERT INTO users (id, name) VALUES (@id, @name) THEN RETURN id, name;
-- name: UpdateBio :exec
UPDATE users SET bio = @bio WHERE id = @id;
-- name: UpdateNameReturning :one
UPDATE users SET name = @name WHERE id = @id THEN RETURN id, name;
-- name: DeleteUser :exec
DELETE FROM users WHERE id = @id;
-- name: DeleteUserReturning :one
DELETE FROM users WHERE id = @id THEN RETURN id;

View File

@@ -0,0 +1,5 @@
CREATE TABLE users (
id INT64 NOT NULL,
name STRING(MAX) NOT NULL,
bio STRING(MAX),
) PRIMARY KEY (id);

View File

@@ -0,0 +1,229 @@
[
{
"name": "CreateUser",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "name",
"type": {
"name": "string",
"args": [
{
"ident": "max"
}
]
},
"table": "users"
}
},
{
"number": 3,
"column": {
"name": "bio",
"type": {
"name": "string",
"nullable": true,
"args": [
{
"ident": "max"
}
]
},
"table": "users"
}
}
]
},
{
"name": "CreateUserReturning",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
},
{
"name": "name",
"type": {
"name": "string",
"args": [
{
"ident": "max"
}
]
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "name",
"type": {
"name": "string",
"args": [
{
"ident": "max"
}
]
},
"table": "users"
}
}
]
},
{
"name": "UpdateBio",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "bio",
"type": {
"name": "string",
"nullable": true,
"args": [
{
"ident": "max"
}
]
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
}
}
]
},
{
"name": "UpdateNameReturning",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
},
{
"name": "name",
"type": {
"name": "string",
"args": [
{
"ident": "max"
}
]
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "string",
"args": [
{
"ident": "max"
}
]
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
}
}
]
},
{
"name": "DeleteUser",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
}
}
]
},
{
"name": "DeleteUserReturning",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "int64"
},
"table": "users"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "mssql", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,11 @@
-- name: CreateAuthor :one
INSERT INTO authors (name, bio) OUTPUT INSERTED.id VALUES (@name, @bio);
-- name: UpdateAuthorAlias :exec
UPDATE a SET name = @name FROM authors a WHERE a.id = @id;
-- name: UpdateBookPrices :exec
UPDATE b SET price = @price FROM books b JOIN authors a ON b.author_id = a.id WHERE a.name = @author;
-- name: DeleteBooksByAuthor :exec
DELETE b FROM books b INNER JOIN authors a ON b.author_id = a.id WHERE a.name = @name;

View File

@@ -0,0 +1,12 @@
CREATE TABLE authors (
id BIGINT IDENTITY(1,1) PRIMARY KEY,
name NVARCHAR(100) NOT NULL,
bio NVARCHAR(MAX)
);
CREATE TABLE books (
id BIGINT IDENTITY(1,1) PRIMARY KEY,
author_id BIGINT NOT NULL,
title NVARCHAR(200) NOT NULL,
price DECIMAL(10,2)
);

View File

@@ -0,0 +1,143 @@
[
{
"name": "CreateAuthor",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
}
],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "nvarchar",
"args": [
{
"int": 100
}
]
},
"table": "authors"
}
},
{
"number": 2,
"column": {
"name": "bio",
"type": {
"name": "nvarchar",
"nullable": true,
"args": [
{
"ident": "max"
}
]
},
"table": "authors"
}
}
]
},
{
"name": "UpdateAuthorAlias",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "nvarchar",
"args": [
{
"int": 100
}
]
},
"table": "authors"
}
},
{
"number": 2,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "authors"
}
}
]
},
{
"name": "UpdateBookPrices",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "price",
"type": {
"name": "decimal",
"nullable": true,
"args": [
{
"int": 10
},
{
"int": 2
}
]
},
"table": "books"
}
},
{
"number": 2,
"column": {
"name": "name",
"type": {
"name": "nvarchar",
"args": [
{
"int": 100
}
]
},
"table": "authors"
}
}
]
},
{
"name": "DeleteBooksByAuthor",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "nvarchar",
"args": [
{
"int": 100
}
]
},
"table": "authors"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "mysql", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,11 @@
-- name: CreateUser :exec
INSERT INTO users (id, name, bio) VALUES (?, ?, ?);
-- name: UpdateBio :exec
UPDATE users SET bio = ? WHERE id = ?;
-- name: DeleteUser :exec
DELETE FROM users WHERE id = ?;
-- name: DeleteUserPosts :exec
DELETE p FROM posts p JOIN users u ON u.id = p.user_id WHERE u.name = ?;

View File

@@ -0,0 +1,12 @@
CREATE TABLE users (
id BIGINT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
bio TEXT
);
CREATE TABLE posts (
id BIGINT PRIMARY KEY,
user_id BIGINT NOT NULL,
title VARCHAR(255),
created DATETIME NOT NULL
);

View File

@@ -0,0 +1,112 @@
[
{
"name": "CreateUser",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "name",
"type": {
"name": "varchar",
"args": [
{
"int": 255
}
]
},
"table": "users"
}
},
{
"number": 3,
"column": {
"name": "bio",
"type": {
"name": "text",
"nullable": true
},
"table": "users"
}
}
]
},
{
"name": "UpdateBio",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "bio",
"type": {
"name": "text",
"nullable": true
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
}
}
]
},
{
"name": "DeleteUser",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
}
}
]
},
{
"name": "DeleteUserPosts",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "varchar",
"args": [
{
"int": 255
}
]
},
"table": "users"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "postgresql", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,14 @@
-- name: CreateUser :one
INSERT INTO users (name, bio) VALUES ($1, $2) RETURNING *;
-- name: UpdateBio :exec
UPDATE users SET bio = $1 WHERE id = $2;
-- name: UpdateNameReturning :one
UPDATE users SET name = $1 WHERE id = $2 RETURNING id, name;
-- name: DeleteUser :exec
DELETE FROM users WHERE id = $1;
-- name: DeleteUserReturning :one
DELETE FROM users WHERE id = $1 RETURNING id;

View File

@@ -0,0 +1,12 @@
CREATE TABLE users (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);
CREATE TABLE posts (
id BIGSERIAL PRIMARY KEY,
user_id bigint NOT NULL,
title varchar(255),
created timestamptz NOT NULL
);

View File

@@ -0,0 +1,165 @@
[
{
"name": "CreateUser",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
},
{
"name": "name",
"type": {
"name": "text"
},
"table": "users"
},
{
"name": "bio",
"type": {
"name": "text",
"nullable": true
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "text"
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "bio",
"type": {
"name": "text",
"nullable": true
},
"table": "users"
}
}
]
},
{
"name": "UpdateBio",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "bio",
"type": {
"name": "text",
"nullable": true
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
}
}
]
},
{
"name": "UpdateNameReturning",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
},
{
"name": "name",
"type": {
"name": "text"
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "text"
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
}
}
]
},
{
"name": "DeleteUser",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
}
}
]
},
{
"name": "DeleteUserReturning",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "bigint"
},
"table": "users"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "sqlite", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,8 @@
-- name: CreateUser :one
INSERT INTO users (name, bio) VALUES (?, ?) RETURNING *;
-- name: UpdateBio :exec
UPDATE users SET bio = ? WHERE id = ?;
-- name: DeleteUser :exec
DELETE FROM users WHERE id = ?;

View File

@@ -0,0 +1,12 @@
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
bio TEXT
);
CREATE TABLE posts (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
title TEXT,
created TEXT NOT NULL
);

View File

@@ -0,0 +1,98 @@
[
{
"name": "CreateUser",
"cmd": ":one",
"columns": [
{
"name": "id",
"type": {
"name": "integer"
},
"table": "users"
},
{
"name": "name",
"type": {
"name": "text"
},
"table": "users"
},
{
"name": "bio",
"type": {
"name": "text",
"nullable": true
},
"table": "users"
}
],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "text"
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "bio",
"type": {
"name": "text",
"nullable": true
},
"table": "users"
}
}
]
},
{
"name": "UpdateBio",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "bio",
"type": {
"name": "text",
"nullable": true
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "id",
"type": {
"name": "integer"
},
"table": "users"
}
}
]
},
{
"name": "DeleteUser",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "integer"
},
"table": "users"
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "clickhouse", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,2 @@
INSERT INTO events VALUES (1, 'signup', NULL, 9.5), (2, 'login', 'web', 0.5);
INSERT INTO users VALUES (1, 'a@example.com');

View File

@@ -0,0 +1,11 @@
-- name: CreateUser :exec
INSERT INTO users (id, email) VALUES (?, ?);
-- name: CreateEvent :exec
INSERT INTO events VALUES (?, ?, ?, ?);
-- name: CreateEvents :exec
INSERT INTO events (id, name) VALUES (?, ?), (?, ?);
-- name: DropUsers :exec
TRUNCATE TABLE users;

View File

@@ -0,0 +1,11 @@
CREATE TABLE events (
id UInt64,
name String,
tag Nullable(String),
amount Float64
) ENGINE = MergeTree ORDER BY id;
CREATE TABLE users (
id UInt64,
email String
) ENGINE = MergeTree ORDER BY id;

View File

@@ -0,0 +1,130 @@
[
{
"name": "CreateUser",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "uint64"
},
"table": "users"
}
},
{
"number": 2,
"column": {
"name": "email",
"type": {
"name": "string"
},
"table": "users"
}
}
]
},
{
"name": "CreateEvent",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
}
},
{
"number": 2,
"column": {
"name": "name",
"type": {
"name": "string"
},
"table": "events"
}
},
{
"number": 3,
"column": {
"name": "tag",
"type": {
"name": "string",
"nullable": true
},
"table": "events"
}
},
{
"number": 4,
"column": {
"name": "amount",
"type": {
"name": "float64"
},
"table": "events"
}
}
]
},
{
"name": "CreateEvents",
"cmd": ":exec",
"columns": [],
"params": [
{
"number": 1,
"column": {
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
}
},
{
"number": 2,
"column": {
"name": "name",
"type": {
"name": "string"
},
"table": "events"
}
},
{
"number": 3,
"column": {
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
}
},
{
"number": 4,
"column": {
"name": "name",
"type": {
"name": "string"
},
"table": "events"
}
}
]
},
{
"name": "DropUsers",
"cmd": ":exec",
"columns": [],
"params": []
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "clickhouse", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,2 @@
INSERT INTO events VALUES (1, 'signup', NULL, 9.5), (2, 'login', 'web', 0.5);
INSERT INTO users VALUES (1, 'a@example.com');

View File

@@ -0,0 +1,29 @@
-- name: Aggregates :one
SELECT count() AS n, max(amount) AS top, sum(amount), min(tag) AS first_tag, uniq(name)
FROM events;
-- name: Expressions :many
SELECT id + 1 AS next_id, nullIf(name, '') AS maybe, coalesce(tag, 'none') AS tag_or_none,
lower(name), toDate(now()) AS today, id > 1 AS big, if(id = 1, 'one', NULL) AS word
FROM events;
-- name: LeftJoinDefaults :many
SELECT e.id, e.name, u.email
FROM events e
LEFT JOIN users u ON u.id = e.id;
-- name: Positional :many
SELECT id, name FROM events WHERE name = ? AND amount > ? AND tag = ?;
-- name: Named :many
SELECT id, name FROM events
WHERE name = sqlc.arg(name) AND tag = sqlc.narg(tag) AND (amount > sqlc.arg(amount) OR amount < sqlc.arg(amount));
-- name: Functions :many
SELECT id FROM events WHERE lower(name) = ? AND id IN (?) AND toDate(now()) > ?;
-- name: Paging :many
SELECT id FROM events ORDER BY id LIMIT ? OFFSET ?;
-- name: Projected :one
SELECT ? AS echo, 'literal' AS lit;

View File

@@ -0,0 +1,11 @@
CREATE TABLE events (
id UInt64,
name String,
tag Nullable(String),
amount Float64
) ENGINE = MergeTree ORDER BY id;
CREATE TABLE users (
id UInt64,
email String
) ENGINE = MergeTree ORDER BY id;

View File

@@ -0,0 +1,342 @@
[
{
"name": "Aggregates",
"cmd": ":one",
"columns": [
{
"name": "n",
"type": {
"name": "uint64"
}
},
{
"name": "top",
"type": {
"name": "float64"
}
},
{
"name": "sum(amount)",
"type": {
"name": "float64"
}
},
{
"name": "first_tag",
"type": {
"name": "string",
"nullable": true
}
},
{
"name": "uniq(name)",
"type": {
"name": "uint64"
}
}
],
"params": []
},
{
"name": "Expressions",
"cmd": ":many",
"columns": [
{
"name": "next_id",
"type": {
"name": "uint64"
}
},
{
"name": "maybe",
"type": {
"name": "string",
"nullable": true
}
},
{
"name": "tag_or_none",
"type": {
"name": "string"
}
},
{
"name": "lower(name)",
"type": {
"name": "string"
}
},
{
"name": "today",
"type": {
"name": "date"
}
},
{
"name": "big",
"type": {
"name": "uint8"
}
},
{
"name": "word",
"type": {
"name": "string",
"nullable": true
}
}
],
"params": []
},
{
"name": "LeftJoinDefaults",
"cmd": ":many",
"columns": [
{
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
},
{
"name": "name",
"type": {
"name": "string"
},
"table": "events"
},
{
"name": "email",
"type": {
"name": "string"
},
"table": "users"
}
],
"params": []
},
{
"name": "Positional",
"cmd": ":many",
"columns": [
{
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
},
{
"name": "name",
"type": {
"name": "string"
},
"table": "events"
}
],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "string"
},
"table": "events"
}
},
{
"number": 2,
"column": {
"name": "amount",
"type": {
"name": "float64"
},
"table": "events"
}
},
{
"number": 3,
"column": {
"name": "tag",
"type": {
"name": "string",
"nullable": true
},
"table": "events"
}
}
]
},
{
"name": "Named",
"cmd": ":many",
"columns": [
{
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
},
{
"name": "name",
"type": {
"name": "string"
},
"table": "events"
}
],
"params": [
{
"number": 1,
"column": {
"name": "name",
"type": {
"name": "string"
},
"table": "events"
}
},
{
"number": 2,
"column": {
"name": "tag",
"type": {
"name": "string",
"nullable": true
},
"table": "events"
}
},
{
"number": 3,
"column": {
"name": "amount",
"type": {
"name": "float64"
},
"table": "events"
}
},
{
"number": 4,
"column": {
"name": "amount",
"type": {
"name": "float64"
},
"table": "events"
}
}
]
},
{
"name": "Functions",
"cmd": ":many",
"columns": [
{
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
}
],
"params": [
{
"number": 1,
"column": {
"name": "lower",
"type": {
"name": "string"
}
}
},
{
"number": 2,
"column": {
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
}
},
{
"number": 3,
"column": {
"name": "toDate",
"type": {
"name": "date"
}
}
}
]
},
{
"name": "Paging",
"cmd": ":many",
"columns": [
{
"name": "id",
"type": {
"name": "uint64"
},
"table": "events"
}
],
"params": [
{
"number": 1,
"column": {
"name": "",
"type": {
"name": "uint64"
}
}
},
{
"number": 2,
"column": {
"name": "",
"type": {
"name": "uint64"
}
}
}
]
},
{
"name": "Projected",
"cmd": ":one",
"columns": [
{
"name": "echo",
"type": {
"name": "nothing",
"nullable": true
}
},
{
"name": "lit",
"type": {
"name": "string"
}
}
],
"params": [
{
"number": 1,
"column": {
"name": "echo",
"type": {
"name": "nothing",
"nullable": true
}
}
}
]
}
]

View File

@@ -0,0 +1,5 @@
{
"command": "analyze",
"args": ["--dialect", "sqlite", "--schema", "schema.sql", "query.sql"],
"contexts": ["base"]
}

View File

@@ -0,0 +1,4 @@
INSERT INTO users (id, name, bio, score) VALUES (1, 'ann', NULL, 1.5);
INSERT INTO users (id, name, bio, score) VALUES (2, 'bob', 'hello', 2.5);
INSERT INTO posts (id, user_id, title, created) VALUES (1, 1, 'first', '2024-01-01');
INSERT INTO posts (id, user_id, title, created) VALUES (2, 1, NULL, '2024-01-02');

View File

@@ -0,0 +1,23 @@
-- name: PostStats :one
SELECT count(*) AS total, max(id) AS latest, min(created) AS first
FROM posts WHERE user_id = ?;
-- name: UserScores :one
SELECT avg(score) AS mean, sum(score) AS sum, sum(id) AS ids, group_concat(name) AS names
FROM users;
-- name: ListUsers :many
SELECT id, lower(name) AS lname, id + 1 AS next
FROM users WHERE id IN (?, ?);
-- name: ListPosts :many
SELECT id, title FROM posts ORDER BY created LIMIT ? OFFSET ?;
-- name: UserPosts :many
SELECT u.name, p.title, p.created
FROM users u LEFT JOIN posts p ON p.user_id = u.id
WHERE u.name LIKE ? || '%';
-- name: CreatePost :one
INSERT INTO posts (user_id, title, created) VALUES (?, ?, datetime('now'))
RETURNING id, created;

Some files were not shown because too many files have changed in this diff Show More