feature: add sqlite kv db

This commit is contained in:
Seraphim Strub 2024-07-12 13:50:20 +00:00
parent 3671bf1f80
commit 759aae3b54
9 changed files with 152 additions and 2 deletions

58
pkg/db/query.sql.go Normal file
View file

@ -0,0 +1,58 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.25.0
// source: query.sql
package db
import (
"context"
)
const countItems = `-- name: CountItems :one
SELECT count(*)
FROM store
`
func (q *Queries) CountItems(ctx context.Context) (int64, error) {
row := q.db.QueryRowContext(ctx, countItems)
var count int64
err := row.Scan(&count)
return count, err
}
const createItem = `-- name: CreateItem :exec
INSERT INTO store (id, data)
VALUES (?1, ?2)
ON CONFLICT(id)
DO UPDATE SET data = ?2
`
type CreateItemParams struct {
ID string
Data []byte
}
func (q *Queries) CreateItem(ctx context.Context, arg CreateItemParams) error {
_, err := q.db.ExecContext(ctx, createItem, arg.ID, arg.Data)
return err
}
const getItem = `-- name: GetItem :one
SELECT id, data, created_at, updated_at
FROM store
WHERE id = ?
LIMIT 1
`
func (q *Queries) GetItem(ctx context.Context, id string) (Store, error) {
row := q.db.QueryRowContext(ctx, getItem, id)
var i Store
err := row.Scan(
&i.ID,
&i.Data,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}