|
|
@@ -0,0 +1,150 @@
|
|
|
+// Code generated by sqlc. DO NOT EDIT.
|
|
|
+// versions:
|
|
|
+// sqlc v1.14.0
|
|
|
+// source: query.sql
|
|
|
+
|
|
|
+package database
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "database/sql"
|
|
|
+)
|
|
|
+
|
|
|
+const createAuthor = `-- name: CreateAuthor :execresult
|
|
|
+INSERT INTO authors (
|
|
|
+ name
|
|
|
+) VALUES (
|
|
|
+ ?
|
|
|
+)
|
|
|
+`
|
|
|
+
|
|
|
+func (q *Queries) CreateAuthor(ctx context.Context, name string) (sql.Result, error) {
|
|
|
+ return q.db.ExecContext(ctx, createAuthor, name)
|
|
|
+}
|
|
|
+
|
|
|
+const createLink = `-- name: CreateLink :execresult
|
|
|
+INSERT INTO golinks (
|
|
|
+ name, target
|
|
|
+) VALUES (
|
|
|
+ ?, ?
|
|
|
+)
|
|
|
+`
|
|
|
+
|
|
|
+type CreateLinkParams struct {
|
|
|
+ Name string
|
|
|
+ Target string
|
|
|
+}
|
|
|
+
|
|
|
+func (q *Queries) CreateLink(ctx context.Context, arg CreateLinkParams) (sql.Result, error) {
|
|
|
+ return q.db.ExecContext(ctx, createLink, arg.Name, arg.Target)
|
|
|
+}
|
|
|
+
|
|
|
+const deleteAuthor = `-- name: DeleteAuthor :exec
|
|
|
+DELETE FROM authors
|
|
|
+WHERE id = ?
|
|
|
+`
|
|
|
+
|
|
|
+func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error {
|
|
|
+ _, err := q.db.ExecContext(ctx, deleteAuthor, id)
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+const deleteLink = `-- name: DeleteLink :exec
|
|
|
+DELETE FROM golinks
|
|
|
+WHERE id = ?
|
|
|
+`
|
|
|
+
|
|
|
+func (q *Queries) DeleteLink(ctx context.Context, id int64) error {
|
|
|
+ _, err := q.db.ExecContext(ctx, deleteLink, id)
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+const getAuthor = `-- name: GetAuthor :one
|
|
|
+SELECT id, name FROM authors
|
|
|
+WHERE id = ? LIMIT 1
|
|
|
+`
|
|
|
+
|
|
|
+func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) {
|
|
|
+ row := q.db.QueryRowContext(ctx, getAuthor, id)
|
|
|
+ var i Author
|
|
|
+ err := row.Scan(&i.ID, &i.Name)
|
|
|
+ return i, err
|
|
|
+}
|
|
|
+
|
|
|
+const getLink = `-- name: GetLink :one
|
|
|
+SELECT id, name, target, visit_count FROM golinks
|
|
|
+WHERE name = ? LIMIT 1
|
|
|
+`
|
|
|
+
|
|
|
+func (q *Queries) GetLink(ctx context.Context, name string) (Golink, error) {
|
|
|
+ row := q.db.QueryRowContext(ctx, getLink, name)
|
|
|
+ var i Golink
|
|
|
+ err := row.Scan(
|
|
|
+ &i.ID,
|
|
|
+ &i.Name,
|
|
|
+ &i.Target,
|
|
|
+ &i.VisitCount,
|
|
|
+ )
|
|
|
+ return i, err
|
|
|
+}
|
|
|
+
|
|
|
+const listAuthors = `-- name: ListAuthors :many
|
|
|
+SELECT id, name FROM authors
|
|
|
+ORDER BY name
|
|
|
+`
|
|
|
+
|
|
|
+func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) {
|
|
|
+ rows, err := q.db.QueryContext(ctx, listAuthors)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer rows.Close()
|
|
|
+ var items []Author
|
|
|
+ for rows.Next() {
|
|
|
+ var i Author
|
|
|
+ if err := rows.Scan(&i.ID, &i.Name); 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
|
|
|
+}
|
|
|
+
|
|
|
+const listLinks = `-- name: ListLinks :many
|
|
|
+SELECT id, name, target, visit_count FROM golinks
|
|
|
+ORDER BY name
|
|
|
+`
|
|
|
+
|
|
|
+func (q *Queries) ListLinks(ctx context.Context) ([]Golink, error) {
|
|
|
+ rows, err := q.db.QueryContext(ctx, listLinks)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer rows.Close()
|
|
|
+ var items []Golink
|
|
|
+ for rows.Next() {
|
|
|
+ var i Golink
|
|
|
+ if err := rows.Scan(
|
|
|
+ &i.ID,
|
|
|
+ &i.Name,
|
|
|
+ &i.Target,
|
|
|
+ &i.VisitCount,
|
|
|
+ ); 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
|
|
|
+}
|