lyspgdb

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 12 Imported by: 3

README

lyspgdb

Functions for creating and connecting to Postgres databases.

Documentation

Overview

Package lyspgdb contains functions for creating and connecting to 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 CreateUserIfNotExists added in v0.1.48

func CreateUserIfNotExists(ctx context.Context, db *pgxpool.Pool, userConf User, options []string) (err error)

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 ExecuteFile added in v0.1.46

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

ExecuteFile extracts the supplied file from the supplied filesystem and executes it into supplied database

func GetConfig

func GetConfig(dbConfig Database, userConfig User, appName string) (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, appName string) (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, appName string, 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 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