database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EqualPattern              string = `%v = '%v'`
	LikePattern               string = `%v LIKE '%%%v%%'`
	BetweenPattern            string = `%v BETWEEN '%v' AND '%v'`
	InPattern                 string = `%v IN (%v)`
	GreaterThanPattern        string = `%v > '%v'`
	GreaterThanOrEqualPattern string = `%v >= '%v'`
	LessThanPattern           string = `%v < '%v'`
	LessThanOrEqualPattern    string = `%v <= '%v'`
)

Patterns

Variables

View Source
var (
	// DBEmptyString variable para definir un campo vacio
	DBEmptyString = "EmpStr__"
	// DBZero variable para definir un campo numerico cero
	DBZero = "EmpZero__"
)

Functions

This section is empty.

Types

type DBProps

type DBProps struct {
	Host             string
	Port             uint16
	Name             string
	User             string
	Pass             string
	MaxOpenConns     uint16
	MaxIdleConns     uint16
	MaxLifeTimeConns uint16
	EnableScriptLog  bool
	Log              logger.Logger
}

type Database

type Database interface {
	SetLogger(logger.Logger)
	SetProperties(props DBProps)
	GetConnection() *sql.DB
	CheckDBHealth(in HealthIn) HealthOut
	NewItemDB(in NewItemIn) NewItemOut
	UpdateItemsDB(in UpdateItemIn) UpdateItemOut
	UpdateItemDB(in UpdateItemIn) UpdateItemOut
	RemoveItemsDB(in RemoveItemIn) RemoveItemOut
	RemoveItemDB(in RemoveItemIn) RemoveItemOut
	ItemsCounterDB(in ItemsCounterIn) ItemsCounterOut
	ItemDB(in ItemIn) ItemOut
	ItemsDB(in ItemsIn) ItemsOut
	RunScript(in RunScriptIn) RunScriptOut
	SelectScript(in SelectScriptIn) SelectScriptOut
	// contains filtered or unexported methods
}

ClientDB interfaz cliente de Base de datos

func New

func New(d Driver, props DBProps) (Database, error)

InstanceClientDB create the connection with db

type Driver

type Driver string

Driver of storage

const (
	MySQLDB      Driver = "MYSQL"
	MongoDB      Driver = "MONGO"
	SQLiteDB     Driver = "SQLITE"
	PostgreSQLDB Driver = "POSTGRES"
)

Drivers

type FilterAllowed

type FilterAllowed struct {
	Column  string                 `json:"-"`
	Order   string                 `json:"-"`
	Pattern string                 `json:"-"`
	Public  map[string]interface{} `json:"public,omitempty"`
}

ItemsDB

type HealthData

type HealthData struct {
	Current *string `db:"now"`
}

HealthDB

type HealthIn

type HealthIn struct {
	Micro string
	Trace string
}

HealthDB

type HealthOut

type HealthOut struct {
	Success bool        `json:"success"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
	Micro   string      `json:"micro"`
}

HealthDB

type ItemIn

type ItemIn struct {
	Script          string
	CheckDuplicated bool
	Dest            interface{}
	Trace           string
	Label           string
}

ItemDB

type ItemOut

type ItemOut struct {
	Success   bool        `json:"success"`
	ItemFound bool        `json:"itemFound"`
	Message   string      `json:"message,omitempty"`
	Item      interface{} `json:"item,omitempty"`
}

ItemDB

type ItemsCounterIn

type ItemsCounterIn struct {
	Script string
	Trace  string
	Label  string
}

ItemsCounterDB

type ItemsCounterOut

type ItemsCounterOut struct {
	Success      bool    `json:"success"`
	Message      string  `json:"message"`
	ItemsCounter *uint32 `db:"itemsCounter"`
}

ItemsCounterDB

type ItemsIn

type ItemsIn struct {
	SelectScript       string
	WhereScript        string
	CounterScript      string
	FiltersAllowed     map[string]FilterAllowed
	FilterVals         string
	OrdersAllowed      map[string]OrdersAllowed
	OrdersVals         string
	DefaultOrderBy     string
	EnablePaging       bool
	PagingSize         uint32
	PagingIndex        uint32
	EnableDefaultLimit bool
	DefaultLimit       uint32
	Dest               interface{}
	Trace              string
	Label              string
}

ItemsDB

type ItemsOut

type ItemsOut struct {
	Success        bool          `json:"success"`
	Message        string        `json:"message"`
	Items          interface{}   `json:"items"`
	HasFilter      bool          `json:"hasFilter"`
	HasPaging      bool          `json:"hasPaging"`
	ItemsCounter   uint32        `json:"itemsCounter"`
	PagingSize     uint32        `json:"pagingSize"`
	DefaultLimit   uint32        `json:"defaultLimit"`
	Applied        interface{}   `json:"applied,omitempty"`
	FiltersAllowed []interface{} `json:"filtersAllowed,omitempty"`
	OrdersAllowed  []interface{} `json:"ordersAllowed,omitempty"`
}

ItemsDB

type MySQL

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

func (*MySQL) CheckDBHealth

func (obj *MySQL) CheckDBHealth(in HealthIn) HealthOut

func (*MySQL) GetConnection

func (mysql *MySQL) GetConnection() *sql.DB

func (MySQL) ItemDB

func (obj MySQL) ItemDB(in ItemIn) ItemOut

func (MySQL) ItemsCounterDB

func (obj MySQL) ItemsCounterDB(in ItemsCounterIn) ItemsCounterOut

func (MySQL) ItemsDB

func (obj MySQL) ItemsDB(in ItemsIn) ItemsOut

func (MySQL) NewItemDB

func (obj MySQL) NewItemDB(in NewItemIn) NewItemOut

func (MySQL) RemoveItemDB

func (obj MySQL) RemoveItemDB(in RemoveItemIn) RemoveItemOut

func (MySQL) RemoveItemsDB

func (obj MySQL) RemoveItemsDB(in RemoveItemIn) RemoveItemOut

func (MySQL) RunScript

func (obj MySQL) RunScript(in RunScriptIn) RunScriptOut

func (MySQL) SelectScript

func (obj MySQL) SelectScript(in SelectScriptIn) SelectScriptOut

func (*MySQL) SetLogger

func (o *MySQL) SetLogger(log logger.Logger)

func (*MySQL) SetProperties

func (o *MySQL) SetProperties(props DBProps)

func (MySQL) UpdateItemDB

func (obj MySQL) UpdateItemDB(in UpdateItemIn) UpdateItemOut

func (MySQL) UpdateItemsDB

func (obj MySQL) UpdateItemsDB(in UpdateItemIn) UpdateItemOut

type NewItemIn

type NewItemIn struct {
	Script          string
	CheckDuplicated bool
	Dest            interface{}
	Trace           string
	Label           string
}

NewItemDB

type NewItemOut

type NewItemOut struct {
	Success  bool   `json:"success"`
	Message  string `json:"message"`
	InsertId int64  `json:"insertId"`
}

NewItemDB

type OrdersAllowed

type OrdersAllowed struct {
	Column string                 `json:"-"`
	Order  string                 `json:"-"`
	Public map[string]interface{} `json:"public,omitempty"`
}

ItemsDB

type RemoveItemIn

type RemoveItemIn struct {
	Script               string
	AffectedRowsScript   string
	CheckDuplicated      bool
	EnableAffectedRows   bool
	ExpectedAffectedRows uint32
	Dest                 interface{}
	Trace                string
	Label                string
}

RemoveItemDB

type RemoveItemOut

type RemoveItemOut struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

RemoveItemDB

type RunScriptIn

type RunScriptIn struct {
	Script string
	Trace  string
}

RunScript

type RunScriptOut

type RunScriptOut struct {
	Error        error `json:"error"`
	AffectedRows int32 `json:"affectedRows"`
	LastInsertId int64 `json:"lastInsertId"`
	ChangedRows  int32 `json:"changedRows"`
}

RunScript

type SelectScriptIn

type SelectScriptIn struct {
	Script string
	Trace  string
	Dest   interface{}
}

SelectScript

type SelectScriptOut

type SelectScriptOut struct {
	Error   error  `json:"error"`
	DataLen uint32 `json:"dataLen"`
}

SelectScript

type UpdateItemIn

type UpdateItemIn struct {
	Script               string
	AffectedRowsScript   string
	CheckDuplicated      bool
	EnableAffectedRows   bool
	ExpectedAffectedRows uint32
	Dest                 interface{}
	Trace                string
	Label                string
}

type UpdateItemOut

type UpdateItemOut struct {
	Success      bool   `json:"success"`
	AffectedRows int32  `json:"affectedRows"`
	Message      string `json:"message"`
}

type UtilsDB

type UtilsDB struct {
}

func (UtilsDB) AffectedRowsScript

func (mysql UtilsDB) AffectedRowsScript(table string, where string) string

func (UtilsDB) BuildFilter

func (obj UtilsDB) BuildFilter(filtersAllowed map[string]FilterAllowed, filtersVals string) string

func (UtilsDB) BuildOrder

func (obj UtilsDB) BuildOrder(filtersAllowed map[string]FilterAllowed, filtersVals string,
	ordersAllowed map[string]OrdersAllowed, orderVals string) string

func (UtilsDB) BuildPaging

func (obj UtilsDB) BuildPaging(data ItemsIn) string

func (UtilsDB) ColsScript

func (mysql UtilsDB) ColsScript(i interface{}, alias string) string

ColsScript .

func (UtilsDB) DeleteScript

func (mysql UtilsDB) DeleteScript(table string, where string) string

func (UtilsDB) InsertScript

func (mysql UtilsDB) InsertScript(table string, i interface{}) string

InsertScript .

func (UtilsDB) UpdateScript

func (mysql UtilsDB) UpdateScript(table string, i interface{}, where string) string

UpdateScript .

func (UtilsDB) WhereScript

func (mysql UtilsDB) WhereScript(i interface{}, joinClause string, alias string) string

WhereScript .

Jump to

Keyboard shortcuts

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