summaryrefslogtreecommitdiffstats
path: root/pkg/database/sqlc
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/database/sqlc')
-rw-r--r--pkg/database/sqlc/db.go31
-rw-r--r--pkg/database/sqlc/entries.sql.go89
-rw-r--r--pkg/database/sqlc/models.go20
3 files changed, 140 insertions, 0 deletions
diff --git a/pkg/database/sqlc/db.go b/pkg/database/sqlc/db.go
new file mode 100644
index 0000000..e4d7828
--- /dev/null
+++ b/pkg/database/sqlc/db.go
@@ -0,0 +1,31 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+// sqlc v1.29.0
+
+package sqlc
+
+import (
+ "context"
+ "database/sql"
+)
+
+type DBTX interface {
+ ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
+ PrepareContext(context.Context, string) (*sql.Stmt, error)
+ QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
+ QueryRowContext(context.Context, string, ...interface{}) *sql.Row
+}
+
+func New(db DBTX) *Queries {
+ return &Queries{db: db}
+}
+
+type Queries struct {
+ db DBTX
+}
+
+func (q *Queries) WithTx(tx *sql.Tx) *Queries {
+ return &Queries{
+ db: tx,
+ }
+}
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
+}
diff --git a/pkg/database/sqlc/models.go b/pkg/database/sqlc/models.go
new file mode 100644
index 0000000..2e74c4b
--- /dev/null
+++ b/pkg/database/sqlc/models.go
@@ -0,0 +1,20 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+// sqlc v1.29.0
+
+package sqlc
+
+type Entry struct {
+ ID int64 `json:"id"`
+ Title string `json:"title"`
+ Kind int64 `json:"kind"`
+ Url string `json:"url"`
+ Description string `json:"description"`
+ Timestamp string `json:"timestamp"`
+}
+
+type Kind struct {
+ ID int64 `json:"id"`
+ Name string `json:"name"`
+ Emoji string `json:"emoji"`
+}