database

package
v0.0.0-...-015e340 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDBHostMandatory is the error that indicates that the DB host is mandatory, but has not been set.
	ErrDBHostMandatory = errors.New(`db host is mandatory`)
	// ErrDBPortMandatory is the error that indicates that the DB port is mandatory, but has not been set.
	ErrDBPortMandatory = errors.New(`db port is mandatory`)
	// ErrDBUserMandatory is the error that indicates that the DB user is mandatory, but has not been set.
	ErrDBUserMandatory = errors.New(`db user is mandatory`)
	// ErrDBNameMandatory is the error that indicates that the DB name is mandatory, but has not been set.
	ErrDBNameMandatory = errors.New(`db name is mandatory`)
	// ErrDBPasswordMandatory is the error that indicates that the DB password is mandatory, but has not been set.
	ErrDBPasswordMandatory = errors.New(`db password is mandatory`)
)

Functions

func Init

func Init(opts *DBOptions) error

Init runs the migrations, needed to have a working Gira DB. It gets the SQL files from the default `./sql` directory.

func InitFromDirectory

func InitFromDirectory(opts *DBOptions, sqlDirectory string) error

InitFromDirectory runs the migrations, needed to have a working Gira DB. It gets the SQL files from the provided directory.

func MigrationsDirectory

func MigrationsDirectory() (string, error)

MigrationsDirectory returns the path to the directory containing the SQL migrations. It will return an absolute path that can be passed directly to `InitFromDirectory`.

func NewDB

func NewDB(opts *DBOptions) (db *sql.DB, err error)

NewDB builds a new *sql.DB from the passed options.

Types

type DBOptions

type DBOptions struct {
	Host   string
	Port   int
	User   string
	DBName string
	DBPass string
	UseSSL bool
}

DBOptions is the struct that encapsulates the fields needed to construct a database.

func (*DBOptions) ConnectionString

func (o *DBOptions) ConnectionString() (string, error)

ConnectionString returns a connection string build from the values of o. This method will call Validate beforehand, and will propagate any error returned from Validate. The connections string will be in the format of PostgresSQL.

func (*DBOptions) Validate

func (o *DBOptions) Validate() error

Validate validates the values of o, and error an error if any of the values is invalid If an error is returned it will be of type *multierror.Error and will contains information about all invalid fields.

Jump to

Keyboard shortcuts

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