code.pablomurad.com

patchwork

Publishes the revisions of your pages as a feed, with notes and readable diffs, written in Go

internal/store/meta.go raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package store

import (
	"context"
	"database/sql"
	"errors"
)

// Meta reads a value from the meta table; missing keys return "".
func (q *Queries) Meta(ctx context.Context, key string) (string, error) {
	var v string
	err := q.q.QueryRowContext(ctx, `SELECT value FROM meta WHERE key = ?`, key).Scan(&v)
	if errors.Is(err, sql.ErrNoRows) {
		return "", nil
	}
	return v, err
}

// SetMeta writes a value to the meta table.
func (q *Queries) SetMeta(ctx context.Context, key, value string) error {
	_, err := q.q.ExecContext(ctx,
		`INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value`, key, value)
	return err
}