db

package
v0.0.0-...-65594e8 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

db defines correct database query to send to external server connection string is grep via YAML file

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotConnected should be thrown when there isn't connection established to db
	ErrNotConnected error = errors.New("Invalid connection to db")
	// PingTimeout defines how long before connection should be ping for healthcheck
	PingTimeout time.Duration = 3 * time.Second
	// RetryTimeout defines how long to wait before retry to connect
	RetryTimeout time.Duration = 10 * time.Second
)
View Source
var ErrExists error = errors.New("Table already exists")

ErrExists is thrown when table is already exists in schema

Functions

func FetchQueries

func FetchQueries(fpath string) ([]string, error)

FetchQueries returns queries in given sql file

func GetProductID

func GetProductID(id int) (bool, error)

GetProductID returns context of whether a product exists in database or not

Types

type Attribute

type Attribute struct {
	ID             int          `json:"id"`
	Name           string       `json:"name"`
	IsProduct      sql.NullBool `json:"isproduct"`
	IsMaterial     sql.NullBool `json:"ismaterial"`
	IsSewingTrims  sql.NullBool `json:"issewingtrims"`
	IsPackingTrims sql.NullBool `json:"ispackingtrims"`
}

Attribute defines attribute structure from db

func FetchAttributes

func FetchAttributes() ([]Attribute, error)

FetchAttributes returns list of attributes from database

type ConnectionPool

type ConnectionPool struct {
	Host       string `yaml:"host"`
	Port       int    `yaml:"port"`
	User       string `yaml:"user"`
	Password   string `yaml:"password"`
	Database   string `yaml:"database"`
	SearchPath string `yaml:"search_path"`
}

ConnectionPool defines info for connection string

func GetCreds

func GetCreds(file string) (*ConnectionPool, error)

GetCreds returns credentials from secrets file

func() {
	conpool, err := GetCreds(fpath)
	if err != nil {
		log.Errorf(err)
	}
	cnnstr := fmt.Sprintf("host=%s user=%s password=%s port=%d database=%s search_path=%s",
		conpool.Host, conpool.User, conpool.Password, conpool.Port, conpool.Database, conpool.SearchPath)
	// Output: cnnstr:= [host=localhost user=postgres password=postgre database=postgres search_path=public]
}()

type ProductInfo

type ProductInfo struct {
	ProductID          int            `json:"product_id" example:"152"`
	ProductName        string         `json:"product_name"`
	AttributeValueID   int            `json:"attribute_value_id"`
	AttributeValueName sql.NullString `json:"attribute_value_name"`
	AttributeID        int            `json:"attribute_id"`
	AttributeName      string         `json:"attribute_name"`
}

ProductInfo defines product info for each product

func FetchProducts

func FetchProducts(query string) ([]ProductInfo, error)

FetchProducts returns product_info table for inference

type Registered

type Registered struct {
	RegClass string `json:"regclass"`
}

Registered defines validity of a table in db

Jump to

Keyboard shortcuts

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