pqkeydb

package
v1.26.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package pqkeydb is a simple key-value database on top of postgres

Index

Constants

This section is empty.

Variables

View Source
var DBSchemas = []string{
	`
CREATE TABLE IF NOT EXISTS keydb (
	guild_id BIGINT NOT NULL,
	key TEXT NOT NULL,
	new BOOLEAN NOT NULl,

	value TEXT NOT NULL,
	updated_at TIMESTAMP WITH TIME ZONE NOT NULL,

	PRIMARY KEY (guild_id, key)
)
	`,
}

DBSchemas is a slice of commands that should be ran to initialize the database

View Source
var ErrKeyNotFound = errors.NewPlain("Key not found")

ErrKeyNotFound is returned when the key is not found

Functions

This section is empty.

Types

type DB

type DB struct {
	PQ *sql.DB
}

DB represents a database

func (*DB) Get

func (db *DB) Get(guildID int64, key string) (r *Result)

Get returns the entry at key for the specified guild

func (*DB) SetString

func (db *DB) SetString(guildID int64, key, value string) (new bool, err error)

SetString creates a new or updates an existing string in the database

type Entry

type Entry struct {
	GuildID int64
	Key     string

	Value     string
	UpdatedAt time.Time
}

Entry represents a entry in the keydb

type Result

type Result struct {
	Entry Entry

	// Set if an error occured
	Error error
}

Result represents a result form the Get operations

func (*Result) Int64

func (r *Result) Int64() (int64, error)

Int64 returns the value parsed as a int64, or an error if an error occured

func (*Result) Str

func (r *Result) Str() (string, error)

Str returns the string value of the entry, or an error if an error occured

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL