db

package module
v0.0.0-...-3d368e2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Dbh *sqlx.DB
)

Functions

func Connect

func Connect(o InitConnect)

Подключение к базе

func ForeachItemInterface

func ForeachItemInterface(fiio ForeachItemInterfaceObj) (objs []interface{}, err error)

Получаем группу интерфейсов из базы

func GetMysqlTimeFormat

func GetMysqlTimeFormat() string

Возвращаем формат даты для mysql

func InsertSet

func InsertSet(now string, n string) string

func MustBegin

func MustBegin() *sqlx.Tx

MustBegin starts a transaction, and panics on error. Returns an *sqlx.Tx instead of an *sql.Tx.

Types

type Field

type Field struct {
	Name   string
	Type   string
	Value  interface{}
	IsJson bool
	IsDb   bool
	Null   bool
	// contains filtered or unexported fields
}

Объект значения строки

func (*Field) CheckNullValue

func (f *Field) CheckNullValue(v interface{})

Проверяем не надо ли значение заменить на NULL

func (*Field) FormatTime

func (f *Field) FormatTime() string

Преобразование значения времени в строку понятную mysql

type ForeachItemInterfaceObj

type ForeachItemInterfaceObj struct {
	NewFunc     func(*InitObj) (interface{}, error)
	ForeachFunc func(interface{}, *ForeachParam, ...interface{}) (interface{}, *sql.Rows, error)
	ParseFunc   func(interface{}, *sql.Rows) (interface{}, error)
	TxFunc      func(interface{}) *sqlx.Tx
	Param       *ForeachParam
	Vals        []interface{}
}

Объект для запроса группы интерфейсов

type ForeachParam

type ForeachParam struct {
	OrderBy     string
	Limit       string
	GroupBy     string
	Where       string
	Fields      string
	CondEntries []string
	ForUpdate   bool
}

Объект для запроса группы объектов

func (*ForeachParam) Clean

func (fp *ForeachParam) Clean()

type InitConnect

type InitConnect struct {
	Login    string
	Password string
	Socket   string
	DBName   string
	Charset  string
}

Объект конекта к базе

type InitObj

type InitObj struct {
	PK        string
	SKN       string
	SKV       string
	Fields    string
	ForUpdate bool
	Tx        *sqlx.Tx
	Empty     bool
}

Объект для инициализации значения из базы

type Parent

type Parent struct {
	Fields     []Field
	DbTable    string
	PKey       string
	SKeys      []string
	MapAddFunc func(map[string]interface{})
	Tx         *sqlx.Tx
	Existed    bool
	sync.RWMutex
}

Родительский объект

func (*Parent) AddField

func (p *Parent) AddField(f Field)

Добавляем поле в объект

func (*Parent) ByteToDescribe

func (p *Parent) ByteToDescribe(b []byte)

Сохраняем описание объекта

func (*Parent) Commit

func (p *Parent) Commit() (err error)

Коммит данных в базу

func (*Parent) CommitTx

func (p *Parent) CommitTx(txcommit bool) (err error)

func (*Parent) CreateFields

func (p *Parent) CreateFields() (err error)

Формируем структуру объекта

func (*Parent) Delete

func (p *Parent) Delete() (err error)

Удаление записи

func (*Parent) DescribeToByte

func (p *Parent) DescribeToByte() (b []byte)

Сохраняем описание объекта

func (*Parent) ForeachItem

func (p *Parent) ForeachItem(param *ForeachParam, vals ...interface{}) (rows *sql.Rows, err error)

Получаем группу объектов

func (*Parent) Get

func (p *Parent) Get(n string) (v interface{})

Получаем значение объекта

func (*Parent) GetBool

func (p *Parent) GetBool(n string) (v bool)

Получаем значение объекта строки

func (*Parent) GetFiledsString

func (p *Parent) GetFiledsString() string

Формируем набор строк для запроса в mysql

func (*Parent) GetFloat

func (p *Parent) GetFloat(n string) (v float64)

Получаем значение объекта float64

func (*Parent) GetFromDB

func (p *Parent) GetFromDB(o *InitObj) (err error)

Инициализация по первичному ключу

func (*Parent) GetInt

func (p *Parent) GetInt(n string) (v int)

Получаем значение объекта int

func (*Parent) GetInt64

func (p *Parent) GetInt64(n string) (v int64)

Получаем значение объекта int64

func (*Parent) GetIntArr

func (p *Parent) GetIntArr(n string) (v []int)

Получаем значение объекта срез строк

func (*Parent) GetJson

func (p *Parent) GetJson() (b []byte)

Возвращаем json объета

func (*Parent) GetMap

func (p *Parent) GetMap() (m map[string]interface{})

Возвращаем хэш объекта

func (*Parent) GetStr

func (p *Parent) GetStr(n string) (v string)

Получаем значение объекта строки

func (*Parent) GetStrArr

func (p *Parent) GetStrArr(n string) (v []string)

Получаем значение объекта срез строк

func (*Parent) GetTableName

func (p *Parent) GetTableName() string

Получаем название таблицы

func (*Parent) GetTime

func (p *Parent) GetTime(n string) (v time.Time)

Получаем значение объекта строки

func (*Parent) ParseDbFields

func (p *Parent) ParseDbFields(rows *sql.Rows) (err error)

Парсинг параметров полученных из базы

func (*Parent) Rollback

func (p *Parent) Rollback() (err error)

Откат

func (*Parent) Set

func (p *Parent) Set(n string, v interface{})

Устанавливаем значение объекта

func (*Parent) SetSpecial

func (p *Parent) SetSpecial(n, v string)

Устанавливаем особое значение

Jump to

Keyboard shortcuts

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