postgres

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvPostgresHost     = "POSTGRES_HOST"
	EnvPostgresPort     = "POSTGRES_PORT"
	EnvPostgresDB       = "POSTGRES_DATABASE"
	EnvPostgresUsername = "POSTGRES_USERNAME"
	EnvPostgresPassword = "POSTGRES_PASSWORD"
)

Constants containing names of ENV variables

View Source
const (
	ConnectionString    = `postgresql://{{.Host}}:{{.Port}}/{{.Database}}?user={{.Username}}&password={{.Password}}`
	DefaultPostgresDB   = "sat_dev"
	DefaultPostgresHost = "postgres"
	DefaultPostgresPort = "5432"
)

Variables

View Source
var (
	//go:embed template/mission/create.sql
	MissionCreateSQL string
	//go:embed template/mission/info.sql
	MissionInfoSQL string
	//go:embed template/mission/select.sql
	MissionSelectSQL string

	//go:embed template/missions_registry/create.sql
	MissionsRegistryCreateSQL string
	//go:embed template/missions_registry/insert.sql
	MissionsRegistryInsertSQL string
	//go:embed template/missions_registry/update.sql
	MissionsRegistryUpdateSQL string
	//go:embed template/missions_registry/select.sql
	MissionsRegistrySelectSQL string
	//go:embed template/missions_registry/get_columns.sql
	MissionsRegistryGetColumnsSQL string
	//go:embed template/missions_registry/select_one.sql
	MissionsRegistrySelectOneSQL string
)
View Source
var (
	ErrNoColumns = fmt.Errorf("no columns for the table")
)

Functions

func BuildCreate

func BuildCreate(name string, columns map[string]string) (string, error)

func BuildInsert

func BuildInsert(data map[string]interface{}) (string, []interface{}, error)

func Divide

func Divide(flatData map[string]interface{}) (columns []string, values []interface{})

func Enumerate

func Enumerate(d []interface{}) string

Types

type Config

type Config struct {
	Host     string
	Port     string
	Database string
	Username string
	Password string
}

func NewConfig

func NewConfig() (Config, error)

type ErrNotConfigured

type ErrNotConfigured struct {
	What string
}

func (ErrNotConfigured) Error

func (err ErrNotConfigured) Error() string

func (ErrNotConfigured) Is

func (err ErrNotConfigured) Is(target error) bool

type PostgresClient

type PostgresClient struct {
	Client *pgxpool.Pool
}

func New

func New(ctx context.Context) (PostgresClient, error)

func (PostgresClient) Close

func (p PostgresClient) Close(ctx context.Context) error

func (PostgresClient) CreateMission

func (p PostgresClient) CreateMission(ctx context.Context, name string, description string, columns map[string]string) error

func (PostgresClient) GetValues added in v0.1.3

func (p PostgresClient) GetValues(ctx context.Context, id string) (out []map[string]interface{}, err error)

func (PostgresClient) ListMissions

func (p PostgresClient) ListMissions(ctx context.Context) (out []map[string]string, err error)

func (PostgresClient) MissionInfo

func (p PostgresClient) MissionInfo(ctx context.Context, id string) (map[string]interface{}, error)

func (PostgresClient) Save

func (p PostgresClient) Save(ctx context.Context, data map[string]interface{}) error

func (PostgresClient) UpdateMission

func (p PostgresClient) UpdateMission(ctx context.Context, name string, description string) error

Jump to

Keyboard shortcuts

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