db

package
v0.0.0-...-da5f288 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package db is a db wrapper

Index

Constants

This section is empty.

Variables

View Source
var (
	AutoParam = map[string]bool{
		"created": true,
	}
	SkipParam = map[string]bool{
		"post_results": true,
		"pre_results":  true,
	}
	TimeParam = map[string]bool{
		"created":       true,
		"logged_in":     true,
		"expires_after": true,
		"time":          true,
	}
)

AutoParam are parameters that are created automatically SkipParam are parameters that are supposed to be skipped over TimeParams are parameters of type time.Time

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     string
	User     string
	Password string
	Database string
	URL      string
}

Config is a database configuration

type Db

type Db struct {
	Pool *pgxpool.Pool
	// contains filtered or unexported fields
}

Db contains the database connection pool and its config

func Setup

func Setup(cfg Config) (Db, error)

Setup setups the database

func (*Db) Close

func (db *Db) Close()

Close closes the connection pool

func (*Db) Delete

func (db *Db) Delete(options SearchOptions) (err error)

Delete attempts to provide a generalized search through the specified table based on the provided queries. It takes a query for the queryable fields, and an operator such as "AND" or "OR" to define the context of the search. It takes in a table name to act on. It returns all the data for all found objects and an error if one exists.

func (*Db) DeleteAll

func (db *Db) DeleteAll(table string) (err error)

DeleteAll permanently removes all objects from the table. It takes in a string representing the table name. It returns an error if one exists.

func (*Db) DeleteByCol

func (db *Db) DeleteByCol(column, columnValue, table string) (err error)

DeleteByCol removes the one row from table where column=columnValue

func (*Db) DeleteByID

func (db *Db) DeleteByID(id uuid.UUID, table string) (err error)

DeleteByID removes one row from table where id=id

func (*Db) Update

func (db *Db) Update(id uuid.UUID, table string, updates interface{}) (data []map[string]interface{}, err error)

Update updates the model row(s) in the table based on the incoming object. It takes in an id to identify the object in the DB, a string representing the table name and the fileds to update the object on. It returns the data representing an updated model.

type SearchOptions

type SearchOptions struct {
	Query      interface{} // The query to use
	Op         string      // AND / OR
	CompareOp  string      // The comparison operator to use (default =)
	TableName  string      // Name of table to query from
	Order      string      // ASC or DESC
	OrderQuery string      // Columns to order by
	Limit      int64       // Number of rows to select
}

SearchOptions is a list of options to call db.Get with

Jump to

Keyboard shortcuts

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