1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-30 22:33:49 +02:00
Files
go-micro/store/postgres/pgx/templates.go
Brian Ketelsen ddc34801ee Plugins and profiles (#2764)
* feat: more plugins

* chore(ci): split out benchmarks

Attempt to resolve too many open files in ci

* chore(ci): split out benchmarks

* fix(ci): Attempt to resolve too many open files in ci

* fix: set DefaultX for cli flag and service option

* fix: restore http broker

* fix: default http broker

* feat: full nats profile

* chore: still ugly, not ready

* fix: better initialization for profiles

* fix(tests): comment out flaky listen tests

* fix: disable benchmarks on gha

* chore: cleanup, comments

* chore: add nats config source
2025-05-20 13:24:06 -04:00

36 lines
1.2 KiB
Go

package pgx
// init
const createSchema = "CREATE SCHEMA IF NOT EXISTS %s"
const createTable = `CREATE TABLE IF NOT EXISTS %s.%s
(
key text primary key,
value bytea,
metadata JSONB,
expiry timestamp with time zone
)`
const createMDIndex = `create index if not exists idx_md_%s ON %s.%s USING GIN (metadata)`
const createExpiryIndex = `create index if not exists idx_expiry_%s on %s.%s (expiry) where (expiry IS NOT NULL)`
// base queries
const (
list = "SELECT key FROM %s.%s WHERE key LIKE $1 and (expiry < now() or expiry isnull)"
readOne = "SELECT key, value, metadata, expiry FROM %s.%s WHERE key = $1 and (expiry < now() or expiry isnull)"
readMany = "SELECT key, value, metadata, expiry FROM %s.%s WHERE key LIKE $1 and (expiry < now() or expiry isnull)"
write = `INSERT INTO %s.%s(key, value, metadata, expiry)
VALUES ($1, $2::bytea, $3, $4)
ON CONFLICT (key)
DO UPDATE
SET value = EXCLUDED.value, metadata = EXCLUDED.metadata, expiry = EXCLUDED.expiry`
deleteRecord = "DELETE FROM %s.%s WHERE key = $1"
deleteExpired = "DELETE FROM %s.%s WHERE expiry < now()"
)
// suffixes
const (
limit = " LIMIT $2 OFFSET $3"
asc = " ORDER BY key ASC"
desc = " ORDER BY key DESC"
)