Have got first run working and publishing to Netlify
This commit is contained in:
parent
b7e0269e9d
commit
30d99eeb9e
22 changed files with 472 additions and 47 deletions
|
|
@ -29,14 +29,16 @@ type PublishTarget struct {
|
|||
}
|
||||
|
||||
type Site struct {
|
||||
ID int64
|
||||
OwnerID int64
|
||||
Title string
|
||||
Tagline string
|
||||
ID int64
|
||||
OwnerID int64
|
||||
Title string
|
||||
Tagline string
|
||||
CreatedAt int64
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int64
|
||||
Username string
|
||||
Password string
|
||||
ID int64
|
||||
Username string
|
||||
Password string
|
||||
CreatedAt int64
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,32 +7,51 @@ package sqlgen
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const hasUsersAndSites = `-- name: HasUsersAndSites :one
|
||||
SELECT (SELECT COUNT(*) FROM users) > 0 AND (SELECT COUNT(*) FROM sites) > 0 AS has_users_and_sites
|
||||
`
|
||||
|
||||
func (q *Queries) HasUsersAndSites(ctx context.Context) (sql.NullBool, error) {
|
||||
row := q.db.QueryRowContext(ctx, hasUsersAndSites)
|
||||
var has_users_and_sites sql.NullBool
|
||||
err := row.Scan(&has_users_and_sites)
|
||||
return has_users_and_sites, err
|
||||
}
|
||||
|
||||
const insertSite = `-- name: InsertSite :one
|
||||
INSERT INTO sites (
|
||||
owner_id,
|
||||
title,
|
||||
tagline
|
||||
) VALUES (?, ?, ?)
|
||||
tagline,
|
||||
created_at
|
||||
) VALUES (?, ?, ?, ?)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type InsertSiteParams struct {
|
||||
OwnerID int64
|
||||
Title string
|
||||
Tagline string
|
||||
OwnerID int64
|
||||
Title string
|
||||
Tagline string
|
||||
CreatedAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSite(ctx context.Context, arg InsertSiteParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertSite, arg.OwnerID, arg.Title, arg.Tagline)
|
||||
row := q.db.QueryRowContext(ctx, insertSite,
|
||||
arg.OwnerID,
|
||||
arg.Title,
|
||||
arg.Tagline,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
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 = ?
|
||||
SELECT id, owner_id, title, tagline, created_at FROM sites WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) {
|
||||
|
|
@ -43,12 +62,13 @@ func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) {
|
|||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Tagline,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectSitesOwnedByUser = `-- name: SelectSitesOwnedByUser :many
|
||||
SELECT id, owner_id, title, tagline FROM sites WHERE owner_id = ?
|
||||
SELECT id, owner_id, title, tagline, created_at FROM sites WHERE owner_id = ? ORDER BY title ASC
|
||||
`
|
||||
|
||||
func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]Site, error) {
|
||||
|
|
@ -65,6 +85,7 @@ func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]
|
|||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Tagline,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,40 +10,51 @@ import (
|
|||
)
|
||||
|
||||
const insertUser = `-- name: InsertUser :one
|
||||
INSERT INTO users (username, password) VALUES (?, ?) RETURNING id
|
||||
INSERT INTO users (username, password, created_at) VALUES (?, ?, ?) RETURNING id
|
||||
`
|
||||
|
||||
type InsertUserParams struct {
|
||||
Username string
|
||||
Password string
|
||||
Username string
|
||||
Password string
|
||||
CreatedAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertUser, arg.Username, arg.Password)
|
||||
row := q.db.QueryRowContext(ctx, insertUser, arg.Username, arg.Password, arg.CreatedAt)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const selectUserByID = `-- name: SelectUserByID :one
|
||||
SELECT id, username, password FROM users WHERE id = ? LIMIT 1
|
||||
SELECT id, username, password, created_at FROM users WHERE id = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) SelectUserByID(ctx context.Context, id int64) (User, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectUserByID, id)
|
||||
var i User
|
||||
err := row.Scan(&i.ID, &i.Username, &i.Password)
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.Password,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectUserByUsername = `-- name: SelectUserByUsername :one
|
||||
SELECT id, username, password FROM users WHERE username = ? LIMIT 1
|
||||
SELECT id, username, password, created_at FROM users WHERE username = ? LIMIT 1
|
||||
`
|
||||
|
||||
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)
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.Password,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue