lyspgdb

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 10 Imported by: 0

README

lyspgdb

Functions for creating and monitoring Postgres databases.

Documentation

Overview

Package lyspgdb contains functions for creating and monitoring Postgres databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDb

func CreateDb(ctx context.Context, pgUserPgDb *pgxpool.Pool, dbName string) (err error)

CreateDb creates a database pgUserPgDb is a connection to the postgres database with the postgres user

func CreateLocalDb

func CreateLocalDb(ctx context.Context, sqlAssets embed.FS, dbConf Database, dbSuperUser, dbOwnerConf User,
	dropExisting, addSecurityPermissions bool, replacementsMap map[string]string, infoLog *slog.Logger) (err error)

CreateLocalDb creates or recreates a test or dev db

func DropDb

func DropDb(ctx context.Context, pgUserPgDb *pgxpool.Pool, dbName string) (err error)

DropDb deletes a database pgUserPgDb is a connection to the postgres database with the postgres user

func GetConfig

func GetConfig(dbConfig Database, userConfig User) (cfg *pgxpool.Config, err error)

GetConn returns a connection pool to the postgres database matching the config params

func GetPool

func GetPool(ctx context.Context, dbConfig Database, userConfig User) (db *pgxpool.Pool, err error)

GetPool returns a connection pool to the postgres database matching the config params

func GetPoolWithTypes

func GetPoolWithTypes(ctx context.Context, dbConfig Database, userConfig User, dataTypeNames []string) (db *pgxpool.Pool, err error)

GetPoolWithTypes returns a connection pool and registers the supplied types to each connection

func GrantAll

func GrantAll(ctx context.Context, pgUserDb *pgxpool.Pool, userConf User, dbName string) (err error)

GrantAll grants all rights to the specified user on the specified db pgUserDb is a connection to the target database with the postgres user

func PopulateDb

func PopulateDb(ctx context.Context, db *pgxpool.Pool, sqlAssets embed.FS, schemaCreationOrder []string, replacementsMap map[string]string,
	infoLog *slog.Logger) (err error)

PopulateDb writes schema, tables, functions and views

Types

type Database

type Database struct {
	Host                string
	Port                string
	Database            string
	SchemaCreationOrder []string
}

Database holds postgres database config options

type StatActivity

type StatActivity struct {
	ApplicationName string           `db:"application_name" json:"application_name"`
	ClientAddr      string           `db:"client_addr" json:"client_addr"`
	Pid             int              `db:"pid" json:"pid"`
	Query           string           `db:"query" json:"query"`
	QueryStart      lystype.Datetime `db:"query_start" json:"query_start"`
	State           string           `db:"state" json:"state"`
	UseName         string           `db:"usename" json:"usename"`
}

type User

type User struct {
	Name     string `toml:"userName"`
	Password string
}

User holds postgres user details

Jump to

Keyboard shortcuts

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