summaryrefslogtreecommitdiffstats
path: root/pkg/database/sqlc/entries.sql.go
blob: f412811ab17f8062e22f858cc73ca4d16a051ef2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: entries.sql

package sqlc

import (
	"context"
)

const createEntryWithKindName = `-- name: CreateEntryWithKindName :one
INSERT INTO entries (title, kind, url, description) 
SELECT ?, kinds.id, ?, ?
FROM kinds
WHERE kinds.name = ?
RETURNING id, title, kind, url, description, timestamp
`

type CreateEntryWithKindNameParams struct {
	Title       string `json:"title"`
	Url         string `json:"url"`
	Description string `json:"description"`
	Name        string `json:"name"`
}

func (q *Queries) CreateEntryWithKindName(ctx context.Context, arg CreateEntryWithKindNameParams) (Entry, error) {
	row := q.db.QueryRowContext(ctx, createEntryWithKindName,
		arg.Title,
		arg.Url,
		arg.Description,
		arg.Name,
	)
	var i Entry
	err := row.Scan(
		&i.ID,
		&i.Title,
		&i.Kind,
		&i.Url,
		&i.Description,
		&i.Timestamp,
	)
	return i, err
}

const getEntries = `-- name: GetEntries :many
SELECT title, url, description, timestamp, kinds.name as kind_name, kinds.emoji as kind_emoji FROM entries
JOIN kinds ON entries.id == kinds.id
ORDER BY timestamp DESC
`

type GetEntriesRow struct {
	Title       string `json:"title"`
	Url         string `json:"url"`
	Description string `json:"description"`
	Timestamp   string `json:"timestamp"`
	KindName    string `json:"kind_name"`
	KindEmoji   string `json:"kind_emoji"`
}

func (q *Queries) GetEntries(ctx context.Context) ([]GetEntriesRow, error) {
	rows, err := q.db.QueryContext(ctx, getEntries)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GetEntriesRow
	for rows.Next() {
		var i GetEntriesRow
		if err := rows.Scan(
			&i.Title,
			&i.Url,
			&i.Description,
			&i.Timestamp,
			&i.KindName,
			&i.KindEmoji,
		); 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
}