persistence

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

package persistence contains our storage layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Quote

func Quote(in string) string

Types

type DB

type DB struct {
	*sql.DB
}

DB is a wrapper around sql.DB. This allows us to access all the functionalities of sql.DB as well as accessing the DB object in our internal functions.

func OpenDB

func OpenDB(opts Options) (db *DB, err error)

OpenDB opens a connection to our database.

type Options

type Options struct {
	// UseInMemory forces our persistence layer to use an in-memory sqlite database
	UseInMemory bool

	// DSN contains the DSN, such as the file name of our sqlite database
	DSN string
}

Options are database options

func (Options) LogValue added in v0.0.4

func (o Options) LogValue() slog.Value

LogValue implements slog.LogValuer.

type Scanner

type Scanner interface {
	Scan(args ...any) error
}

type StorageObject

type StorageObject interface {
	InitTables(db *DB) (err error)
	PrepareReplace(db *DB) (stmt *sql.Stmt, err error)
	PrepareList(db *DB) (stmt *sql.Stmt, err error)
	PrepareGet(db *DB) (stmt *sql.Stmt, err error)
	PrepareUpdate(db *DB, columns []string) (stmt *sql.Stmt, err error)
	PrepareDelete(db *DB) (stmt *sql.Stmt, err error)
	ReplaceIntoArgs() []any
	UpdateArgs([]string) []any
	Scan(sc Scanner) (StorageObject, error)
}

type StorageOperations

type StorageOperations[T StorageObject] interface {
	Replace(o StorageObject) (err error)
	List(args ...any) (list []T, err error)
	Get(key any) (obj T, err error)
	Update(key any, in T, columns []string) (out T, err error)
	Delete(key any) (err error)
}

func Ops

func Ops[T StorageObject](db *DB) StorageOperations[T]

Jump to

Keyboard shortcuts

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