Added a database

This commit is contained in:
Leon Mika 2026-02-19 22:29:44 +11:00
parent ebaec3d296
commit 8136655336
35 changed files with 925 additions and 134 deletions

View file

@ -0,0 +1,31 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
package sqlgen
import (
"context"
"database/sql"
)
type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *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,38 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
package sqlgen
type Post struct {
ID int64
SiteID int64
Guid string
Title string
Body string
Slug string
CreatedAt int64
PublishedAt int64
}
type PublishTarget struct {
ID int64
SiteID int64
TargetType int64
BaseUrl string
TargetRef string
TargetKey string
}
type Site struct {
ID int64
OwnerID int64
Title string
Tagline string
}
type User struct {
ID int64
Username string
Password string
}

View file

@ -0,0 +1,84 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: posts.sql
package sqlgen
import (
"context"
)
const insertPost = `-- name: InsertPost :one
INSERT INTO posts (
site_id,
guid,
title,
body,
slug,
created_at,
published_at
) VALUES (?, ?, ?, ?, ?, ?, ?)
RETURNING id
`
type InsertPostParams struct {
SiteID int64
Guid string
Title string
Body string
Slug string
CreatedAt int64
PublishedAt int64
}
func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertPost,
arg.SiteID,
arg.Guid,
arg.Title,
arg.Body,
arg.Slug,
arg.CreatedAt,
arg.PublishedAt,
)
var id int64
err := row.Scan(&id)
return id, err
}
const selectPostsOfSite = `-- name: SelectPostsOfSite :many
SELECT id, site_id, guid, title, body, slug, created_at, published_at FROM posts WHERE site_id = ? ORDER BY created_at DESC LIMIT 10
`
func (q *Queries) SelectPostsOfSite(ctx context.Context, siteID int64) ([]Post, error) {
rows, err := q.db.QueryContext(ctx, selectPostsOfSite, siteID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Post
for rows.Next() {
var i Post
if err := rows.Scan(
&i.ID,
&i.SiteID,
&i.Guid,
&i.Title,
&i.Body,
&i.Slug,
&i.CreatedAt,
&i.PublishedAt,
); 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
}

View file

@ -0,0 +1,76 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: pubtargets.sql
package sqlgen
import (
"context"
)
const insertPublishTarget = `-- name: InsertPublishTarget :one
INSERT INTO publish_targets (
site_id,
target_type,
base_url,
target_ref,
target_key
) VALUES (?, ?, ?, ?, ?)
RETURNING id
`
type InsertPublishTargetParams struct {
SiteID int64
TargetType int64
BaseUrl string
TargetRef string
TargetKey string
}
func (q *Queries) InsertPublishTarget(ctx context.Context, arg InsertPublishTargetParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertPublishTarget,
arg.SiteID,
arg.TargetType,
arg.BaseUrl,
arg.TargetRef,
arg.TargetKey,
)
var id int64
err := row.Scan(&id)
return id, err
}
const selectPublishTargetsOfSite = `-- name: SelectPublishTargetsOfSite :many
SELECT id, site_id, target_type, base_url, target_ref, target_key FROM publish_targets WHERE site_id = ?
`
func (q *Queries) SelectPublishTargetsOfSite(ctx context.Context, siteID int64) ([]PublishTarget, error) {
rows, err := q.db.QueryContext(ctx, selectPublishTargetsOfSite, siteID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []PublishTarget
for rows.Next() {
var i PublishTarget
if err := rows.Scan(
&i.ID,
&i.SiteID,
&i.TargetType,
&i.BaseUrl,
&i.TargetRef,
&i.TargetKey,
); 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
}

View file

@ -0,0 +1,80 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: sites.sql
package sqlgen
import (
"context"
)
const insertSite = `-- name: InsertSite :one
INSERT INTO sites (
owner_id,
title,
tagline
) VALUES (?, ?, ?)
RETURNING id
`
type InsertSiteParams struct {
OwnerID int64
Title string
Tagline string
}
func (q *Queries) InsertSite(ctx context.Context, arg InsertSiteParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertSite, arg.OwnerID, arg.Title, arg.Tagline)
var id int64
err := row.Scan(&id)
return id, err
}
const selectSiteByID = `-- name: SelectSiteByID :one
SELECT id, owner_id, title, tagline FROM sites WHERE id = ?
`
func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) {
row := q.db.QueryRowContext(ctx, selectSiteByID, id)
var i Site
err := row.Scan(
&i.ID,
&i.OwnerID,
&i.Title,
&i.Tagline,
)
return i, err
}
const selectSitesOwnedByUser = `-- name: SelectSitesOwnedByUser :many
SELECT id, owner_id, title, tagline FROM sites WHERE owner_id = ?
`
func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]Site, error) {
rows, err := q.db.QueryContext(ctx, selectSitesOwnedByUser, ownerID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Site
for rows.Next() {
var i Site
if err := rows.Scan(
&i.ID,
&i.OwnerID,
&i.Title,
&i.Tagline,
); 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
}

View file

@ -0,0 +1,52 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: users.sql
package sqlgen
import (
"context"
)
const insertUser = `-- name: InsertUser :one
INSERT INTO users (username, password) VALUES (?, ?) RETURNING id
`
type InsertUserParams struct {
Username string
Password string
}
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertUser, arg.Username, arg.Password)
var id int64
err := row.Scan(&id)
return id, err
}
const selectUserByUsername = `-- name: SelectUserByUsername :one
SELECT id, username, password FROM users WHERE username = ?
`
func (q *Queries) SelectUserByUsername(ctx context.Context, username string) (User, error) {
row := q.db.QueryRowContext(ctx, selectUserByUsername, username)
var i User
err := row.Scan(&i.ID, &i.Username, &i.Password)
return i, err
}
const updateUser = `-- name: UpdateUser :exec
UPDATE users SET username = ?, password = ? WHERE id = ?
`
type UpdateUserParams struct {
Username string
Password string
ID int64
}
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
_, err := q.db.ExecContext(ctx, updateUser, arg.Username, arg.Password, arg.ID)
return err
}