feat(store): generate typed queries with sqlc
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
018b24948e
commit
0af74267b9
6 files changed
+143
No files matched your search
@@ -0,0 +1,32 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.31.1
|
||||||
|
|
||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
"github.com/jackc/pgx/v5/pgconn"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DBTX interface {
|
||||||
|
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||||
|
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||||
|
QueryRow(context.Context, string, ...interface{}) 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.31.1
|
||||||
|
|
||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Org struct {
|
||||||
|
ID uuid.UUID
|
||||||
|
Slug string
|
||||||
|
Name string
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.31.1
|
||||||
|
// source: orgs.sql
|
||||||
|
|
||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
const createOrg = `-- name: CreateOrg :one
|
||||||
|
INSERT INTO orgs (slug, name) VALUES ($1, $2)
|
||||||
|
RETURNING id, slug, name, created_at, updated_at
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateOrgParams struct {
|
||||||
|
Slug string
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateOrg(ctx context.Context, arg CreateOrgParams) (Org, error) {
|
||||||
|
row := q.db.QueryRow(ctx, createOrg, arg.Slug, arg.Name)
|
||||||
|
var i Org
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Slug,
|
||||||
|
&i.Name,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const getOrgBySlug = `-- name: GetOrgBySlug :one
|
||||||
|
SELECT id, slug, name, created_at, updated_at FROM orgs WHERE slug = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
||||||
|
row := q.db.QueryRow(ctx, getOrgBySlug, slug)
|
||||||
|
var i Org
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Slug,
|
||||||
|
&i.Name,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.31.1
|
||||||
|
|
||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Querier interface {
|
||||||
|
CreateOrg(ctx context.Context, arg CreateOrgParams) (Org, error)
|
||||||
|
GetOrgBySlug(ctx context.Context, slug string) (Org, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Querier = (*Queries)(nil)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- name: CreateOrg :one
|
||||||
|
INSERT INTO orgs (slug, name) VALUES ($1, $2)
|
||||||
|
RETURNING *;
|
||||||
|
|
||||||
|
-- name: GetOrgBySlug :one
|
||||||
|
SELECT * FROM orgs WHERE slug = $1;
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
version: "2"
|
||||||
|
sql:
|
||||||
|
- engine: postgresql
|
||||||
|
schema: internal/migrations/sql
|
||||||
|
queries: internal/store/queries
|
||||||
|
gen:
|
||||||
|
go:
|
||||||
|
package: store
|
||||||
|
out: internal/store
|
||||||
|
sql_package: pgx/v5
|
||||||
|
emit_interface: true
|
||||||
|
emit_empty_slices: true
|
||||||
|
emit_pointers_for_null_types: true
|
||||||
|
overrides:
|
||||||
|
- db_type: uuid
|
||||||
|
go_type: github.com/google/uuid.UUID
|
||||||
|
- db_type: citext
|
||||||
|
go_type: string
|
||||||
|
- db_type: timestamptz
|
||||||
|
go_type: time.Time
|
||||||
Reference in new issue
Block a user