database

package
v0.0.0-...-626c64f Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package database wraps `lib/pq` providing the basic methods for creating an entrypoint for our database.

Index

Constants

View Source
const (
	ErrorInternal      = errorCode(0)
	ErrorGeneric       = errorCode(1)
	ErrorCreation      = errorCode(2)
	ErrorTableCreation = errorCode(3)
	ErrorModelInvalid  = errorCode(4)
	ErrorAlreadyExists = errorCode(5)
	ErrorNoData        = errorCode(6)
	// ErrorExecute for any errors made by a bad query
	ErrorExecute           = errorCode(7)
	ErrorNoRows            = errorCode(8)
	ErrorMissingExtensions = errorCode(9)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB holds the connection pool to the database - created by a configuration object (`SQLConfig`).

func New

func New(cfg config.SQLConfig) (db *DB, err error)

New returns a SQL DB with the sql.DB set with the postgres DB connection string in the configuration

func (*DB) Close

func (db *DB) Close() (err error)

Close performs the release of any resources that `sql/database` DB pool created. This is usually meant to be used in the exitting of a program or `panic`ing.

func (*DB) FormError

func (db *DB) FormError(err error, query, table string) (dberr *Error)

FormError returns the pq(postgres) error wrapped in a Error

func (DB) GetInstance

func (db DB) GetInstance() *sql.DB

GetInstance returns the actual sql.DB

func (*DB) Init

func (db *DB) Init(tables []Table) *Error

Init will hold any type of initialization logic needed by the DB, Right now it only creates the needed Model's tables

type Error

type Error struct {
	Message string
	Query   string
	Table   string
	Inner   error
	Code    errorCode
}

Error holds DB errors

func NewError

func NewError(code errorCode, message, query, table string, inner error) *Error

NewError returns a new db Errors

func (Error) Error

func (e Error) Error() string

type Table

type Table interface {
	Create(db *DB) (dberr *Error)
	Name() string
}

Table is the interface needed by the API Models to be able to create themselves, This means creating the Tables and Indexes needed for the specific Model

Jump to

Keyboard shortcuts

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