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:
3
examples/jets/README.md
Normal file
3
examples/jets/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
This database schema and query selection is taken from the
|
||||
[SQLBoiler](https://github.com/volatiletech/sqlboiler#features--examples)
|
||||
README.
|
||||
32
examples/jets/postgresql/db.go
Normal file
32
examples/jets/postgresql/db.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package jets
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
28
examples/jets/postgresql/models.go
Normal file
28
examples/jets/postgresql/models.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package jets
|
||||
|
||||
type Jet struct {
|
||||
ID int32
|
||||
PilotID int32
|
||||
Age int32
|
||||
Name string
|
||||
Color string
|
||||
}
|
||||
|
||||
type Language struct {
|
||||
ID int32
|
||||
Language string
|
||||
}
|
||||
|
||||
type Pilot struct {
|
||||
ID int32
|
||||
Name string
|
||||
}
|
||||
|
||||
type PilotLanguage struct {
|
||||
PilotID int32
|
||||
LanguageID int32
|
||||
}
|
||||
8
examples/jets/postgresql/query-building.sql
Normal file
8
examples/jets/postgresql/query-building.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
-- name: CountPilots :one
|
||||
SELECT COUNT(*) FROM pilots;
|
||||
|
||||
-- name: ListPilots :many
|
||||
SELECT * FROM pilots LIMIT 5;
|
||||
|
||||
-- name: DeletePilot :exec
|
||||
DELETE FROM pilots WHERE id = $1;
|
||||
54
examples/jets/postgresql/query-building.sql.go
Normal file
54
examples/jets/postgresql/query-building.sql.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: query-building.sql
|
||||
|
||||
package jets
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const countPilots = `-- name: CountPilots :one
|
||||
SELECT COUNT(*) FROM pilots
|
||||
`
|
||||
|
||||
func (q *Queries) CountPilots(ctx context.Context) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countPilots)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const deletePilot = `-- name: DeletePilot :exec
|
||||
DELETE FROM pilots WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeletePilot(ctx context.Context, id int32) error {
|
||||
_, err := q.db.Exec(ctx, deletePilot, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const listPilots = `-- name: ListPilots :many
|
||||
SELECT id, name FROM pilots LIMIT 5
|
||||
`
|
||||
|
||||
func (q *Queries) ListPilots(ctx context.Context) ([]Pilot, error) {
|
||||
rows, err := q.db.Query(ctx, listPilots)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Pilot
|
||||
for rows.Next() {
|
||||
var i Pilot
|
||||
if err := rows.Scan(&i.ID, &i.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
35
examples/jets/postgresql/schema.sql
Normal file
35
examples/jets/postgresql/schema.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
CREATE TABLE pilots (
|
||||
id integer NOT NULL,
|
||||
name text NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE pilots ADD CONSTRAINT pilot_pkey PRIMARY KEY (id);
|
||||
|
||||
CREATE TABLE jets (
|
||||
id integer NOT NULL,
|
||||
pilot_id integer NOT NULL,
|
||||
age integer NOT NULL,
|
||||
name text NOT NULL,
|
||||
color text NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE jets ADD CONSTRAINT jet_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE jets ADD CONSTRAINT jet_pilots_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id);
|
||||
|
||||
CREATE TABLE languages (
|
||||
id integer NOT NULL,
|
||||
language text NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE languages ADD CONSTRAINT language_pkey PRIMARY KEY (id);
|
||||
|
||||
-- Join table
|
||||
CREATE TABLE pilot_languages (
|
||||
pilot_id integer NOT NULL,
|
||||
language_id integer NOT NULL
|
||||
);
|
||||
|
||||
-- Composite primary key
|
||||
ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_pkey PRIMARY KEY (pilot_id, language_id);
|
||||
ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_pilots_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id);
|
||||
ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_languages_fkey FOREIGN KEY (language_id) REFERENCES languages(id);
|
||||
25
examples/jets/sqlc.json
Normal file
25
examples/jets/sqlc.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"version": "1",
|
||||
"cloud": {
|
||||
"project": "01HAQMMECEYQYKFJN8MP16QC41"
|
||||
},
|
||||
"packages": [
|
||||
{
|
||||
"path": "postgresql",
|
||||
"name": "jets",
|
||||
"schema": "postgresql/schema.sql",
|
||||
"queries": "postgresql/query-building.sql",
|
||||
"engine": "postgresql",
|
||||
"sql_package": "pgx/v5",
|
||||
"database": {
|
||||
"uri": "${VET_TEST_EXAMPLES_POSTGRES_JETS}"
|
||||
},
|
||||
"analyzer": {
|
||||
"database": false
|
||||
},
|
||||
"rules": [
|
||||
"sqlc/db-prepare"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user