From f1741a7faa9538e9b12ac60e0fbf6c7721a36059 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Tue, 9 Sep 2025 22:44:09 +0100 Subject: Initial commit --- pkg/database/sqlc/entries.sql.go | 89 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 pkg/database/sqlc/entries.sql.go (limited to 'pkg/database/sqlc/entries.sql.go') diff --git a/pkg/database/sqlc/entries.sql.go b/pkg/database/sqlc/entries.sql.go new file mode 100644 index 0000000..f412811 --- /dev/null +++ b/pkg/database/sqlc/entries.sql.go @@ -0,0 +1,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 +} -- cgit v1.2.3-70-g09d2