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

@ -1,37 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: users.sql
package sql
import (
"context"
)
const insertUserByUsername = `-- name: InsertUserByUsername :one
INSERT INTO users (username, password) VALUES (?, ?) RETURNING id
`
type InsertUserByUsernameParams struct {
Username string
Password string
}
func (q *Queries) InsertUserByUsername(ctx context.Context, arg InsertUserByUsernameParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertUserByUsername, 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
}

View file

@ -1,8 +1,8 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// sqlc v1.28.0
package sql
package sqlgen
import (
"context"

View file

@ -1,8 +1,8 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// sqlc v1.28.0
package sql
package sqlgen
type Post struct {
ID int64
@ -16,12 +16,12 @@ type Post struct {
}
type PublishTarget struct {
ID int64
SiteID int64
PublishTargetType int64
BaseUrl string
TargetSiteID string
TargetPublishKey string
ID int64
SiteID int64
TargetType int64
BaseUrl string
TargetRef string
TargetKey string
}
type Site struct {

View file

@ -1,9 +1,9 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// sqlc v1.28.0
// source: posts.sql
package sql
package sqlgen
import (
"context"

View file

@ -1,9 +1,9 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// sqlc v1.28.0
// source: pubtargets.sql
package sql
package sqlgen
import (
"context"
@ -12,29 +12,29 @@ import (
const insertPublishTarget = `-- name: InsertPublishTarget :one
INSERT INTO publish_targets (
site_id,
publish_target_type,
target_type,
base_url,
target_site_id,
target_publish_key
target_ref,
target_key
) VALUES (?, ?, ?, ?, ?)
RETURNING id
`
type InsertPublishTargetParams struct {
SiteID int64
PublishTargetType int64
BaseUrl string
TargetSiteID string
TargetPublishKey string
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.PublishTargetType,
arg.TargetType,
arg.BaseUrl,
arg.TargetSiteID,
arg.TargetPublishKey,
arg.TargetRef,
arg.TargetKey,
)
var id int64
err := row.Scan(&id)
@ -42,7 +42,7 @@ func (q *Queries) InsertPublishTarget(ctx context.Context, arg InsertPublishTarg
}
const selectPublishTargetsOfSite = `-- name: SelectPublishTargetsOfSite :many
SELECT id, site_id, publish_target_type, base_url, target_site_id, target_publish_key FROM publish_targets WHERE site_id = ?
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) {
@ -57,10 +57,10 @@ func (q *Queries) SelectPublishTargetsOfSite(ctx context.Context, siteID int64)
if err := rows.Scan(
&i.ID,
&i.SiteID,
&i.PublishTargetType,
&i.TargetType,
&i.BaseUrl,
&i.TargetSiteID,
&i.TargetPublishKey,
&i.TargetRef,
&i.TargetKey,
); err != nil {
return nil, err
}

View file

@ -1,9 +1,9 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// sqlc v1.28.0
// source: sites.sql
package sql
package sqlgen
import (
"context"
@ -31,6 +31,22 @@ func (q *Queries) InsertSite(ctx context.Context, arg InsertSiteParams) (int64,
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 = ?
`

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
}