common

package
v0.0.0-...-96c3624 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: Apache-2.0 Imports: 19 Imported by: 4

Documentation

Index

Constants

View Source
const SubTypeTag = "sub"
View Source
const TagName = "flynn"

TagName name to be used for tagging structure field

Variables

View Source
var Databases = make([]Database, 0)

Functions

func CreateInterface

func CreateInterface(i interface{}, createFields []string) *typeInterface

func CreateTypeData

func CreateTypeData(ct []*sql.ColumnType) []interface{}

func DBHelper

func DBHelper() string

func RegisterDbClient

func RegisterDbClient(db Database)

RegisterDbClient register database

func Unpointer

func Unpointer(data []interface{}) []interface{}

Types

type Column

type Column struct {
	Name       string
	DataType   DataType
	Length     uint16
	Digits     uint8
	SubColumns []*Column
}

func CreateHeader

func CreateHeader(ct []*sql.ColumnType) []*Column

type CommonDatabase

type CommonDatabase struct {
	RegDbID     RegDbID
	Transaction bool
	LastUsed    time.Time
}

func (*CommonDatabase) IsTransaction

func (cd *CommonDatabase) IsTransaction() bool

func (*CommonDatabase) Used

func (cd *CommonDatabase) Used()

type CreateStatus

type CreateStatus byte
const (
	CreateError CreateStatus = iota
	CreateExists
	CreateCreated
	CreateDriver
	CreateConnError
)

type DataType

type DataType byte
const (
	None DataType = iota
	Alpha
	Text
	Unicode
	Integer
	Decimal
	Number
	Bit
	Bytes
	CurrentTimestamp
	Date
	BLOB
	Character
)

func SqlDataType

func SqlDataType(sqlType string) DataType

func (DataType) SqlType

func (dt DataType) SqlType(arg ...any) string

type Database

type Database interface {
	Used()
	ID() RegDbID
	URL() string
	Ping() error
	SetCredentials(string, string) error
	Maps() ([]string, error)
	Clone() Database
	GetTableColumn(tableName string) ([]string, error)
	CreateTable(string, any) error
	DeleteTable(string) error
	Open() (any, error)
	Close()
	FreeHandler()
	Insert(name string, insert *Entries) ([][]any, error)
	Update(name string, insert *Entries) ([][]any, int64, error)
	Delete(name string, remove *Entries) (int64, error)
	Batch(batch string) error
	BatchSelect(batch string) ([][]interface{}, error)
	BatchSelectFct(search *Query, f ResultFunction) error
	Query(search *Query, f ResultFunction) (*Result, error)
	BeginTransaction() error
	Commit() error
	Rollback() error
	Stream(search *Query, sf StreamFunction) error
}

type Entries

type Entries struct {
	Fields     []string
	DataStruct any
	Update     []string
	Values     [][]any
	Returning  []string
	Criteria   string
}

type NullBytes

type NullBytes struct {
	Bytes []byte
	Valid bool
}

func (*NullBytes) Scan

func (n *NullBytes) Scan(value any) error

Scan implements the Scanner interface.

func (NullBytes) Value

func (n NullBytes) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullUint

type NullUint struct {
	Val   uint64
	Valid bool
}

func (*NullUint) Scan

func (n *NullUint) Scan(value any) error

Scan implements the Scanner interface.

func (NullUint) Value

func (n NullUint) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Query

type Query struct {
	TableName    string
	Search       string
	Join         string
	Fields       []string
	Order        []string
	Group        []string
	Parameters   []any
	Limit        uint32
	Blocksize    int32
	Descriptor   bool
	DataStruct   any
	TypeInfo     any
	FctParameter any
}

func (*Query) ParseRows

func (search *Query) ParseRows(rows *sql.Rows, f ResultFunction) (result *Result, err error)

func (*Query) ParseStruct

func (search *Query) ParseStruct(rows *sql.Rows, f ResultFunction) (result *Result, err error)

func (*Query) Select

func (q *Query) Select() (string, error)

type Reference

type Reference struct {
	Driver   ReferenceType
	Host     string
	Port     int
	User     string
	Database string
	Options  []string
}

func NewReference

func NewReference(url string) (*Reference, string, error)

NewReference new reference of database link

func (*Reference) OptionString

func (ref *Reference) OptionString() string

func (*Reference) SetType

func (r *Reference) SetType(t string)

type ReferenceType

type ReferenceType byte
const (
	NoType ReferenceType = iota
	MysqlType
	PostgresType
	AdabasType
	OracleType
)

func ParseTypeName

func ParseTypeName(t string) ReferenceType

ParseTypeName parse type string to internal type

func (ReferenceType) String

func (rt ReferenceType) String() string

type RegDbID

type RegDbID uint64

func (RegDbID) Batch

func (id RegDbID) Batch(batch string) error

Batch batch SQL with no return data in table

func (RegDbID) BatchSelect

func (id RegDbID) BatchSelect(batch string) ([][]interface{}, error)

BatchSelect batch SQL query in table

func (RegDbID) BatchSelectFct

func (id RegDbID) BatchSelectFct(batch *Query, f ResultFunction) error

BatchSelect batch SQL query in table calling function

func (RegDbID) BeginTransaction

func (id RegDbID) BeginTransaction() error

BeginTransaction begin a transaction

func (RegDbID) Close

func (id RegDbID) Close()

Close close the database connection

func (RegDbID) Commit

func (id RegDbID) Commit() error

Commit transaction commit

func (RegDbID) CreateTable

func (id RegDbID) CreateTable(tableName string, columns any) error

CreateTable create a new table

func (RegDbID) CreateTableIfNotExists

func (id RegDbID) CreateTableIfNotExists(tableName string, columns any) (CreateStatus, error)

CreateTable create a new table

func (RegDbID) Delete

func (id RegDbID) Delete(name string, remove *Entries) (int64, error)

Delete Delete database records

func (RegDbID) DeleteTable

func (id RegDbID) DeleteTable(tableName string) error

DeleteTable delete a table

func (RegDbID) FreeHandler

func (id RegDbID) FreeHandler() error

FreeHandler unregister registry id for the driver

func (RegDbID) GetTableColumn

func (id RegDbID) GetTableColumn(tableName string) ([]string, error)

GetTableColumn get table columne names

func (RegDbID) Insert

func (id RegDbID) Insert(name string, insert *Entries) ([][]any, error)

Insert insert record into table

func (RegDbID) Open

func (id RegDbID) Open() (any, error)

Open open the database connection

func (RegDbID) Ping

func (id RegDbID) Ping() error

Ping create short test database connection

func (RegDbID) Query

func (id RegDbID) Query(query *Query, f ResultFunction) (*Result, error)

Query query database records with search or SELECT

func (RegDbID) Rollback

func (id RegDbID) Rollback() error

Rollback transaction rollback

func (RegDbID) SetCredentials

func (id RegDbID) SetCredentials(user, password string) error

SetCredentials set credentials to connect to database

func (RegDbID) Stream

func (id RegDbID) Stream(search *Query, sf StreamFunction) error

Stream streaming data from a field

func (RegDbID) String

func (id RegDbID) String() string

func (RegDbID) URL

func (id RegDbID) URL() string

URL URL string

func (RegDbID) Update

func (id RegDbID) Update(name string, insert *Entries) ([][]any, int64, error)

Update update record in table

type Result

type Result struct {
	Counter uint64
	Fields  []string
	Header  []*Column
	Rows    []any
	Data    any
}

func (*Result) GenerateColumnByStruct

func (result *Result) GenerateColumnByStruct(search *Query) (*ValueDefinition, error)

type ResultFunction

type ResultFunction func(search *Query, result *Result) error

type SetType

type SetType byte
const (
	EmptySet SetType = iota
	AllSet
	GivenSet
)

type Stream

type Stream struct {
	Data []byte
}

type StreamFunction

type StreamFunction func(search *Query, stream *Stream) error

type ResultDataFunction func(index uint64, header []*Column, result []interface{}) error

type SubInterface

type SubInterface interface {
	Data() []byte
	ParseData(sub []byte) error
}

type TagInfo

type TagInfo byte
const (
	NormalTag TagInfo = iota
	IgnoreTag
	SubTag
	YAMLTag
	XMLTag
	JSONTag
	IndexTag
	KeyTag
)

func TagInfoParse

func TagInfoParse(info string) (string, TagInfo)

func (TagInfo) String

func (tagInfo TagInfo) String() string

type ValueDefinition

type ValueDefinition struct {
	Copy       any
	Values     []any
	ScanValues []any
	TagInfo    []TagInfo
	// contains filtered or unexported fields
}

func (*ValueDefinition) ShiftNormalValues

func (vd *ValueDefinition) ShiftNormalValues(d int, v any) error

func (*ValueDefinition) ShiftTransformContentValues

func (vd *ValueDefinition) ShiftTransformContentValues(d int, v any) error

func (*ValueDefinition) ShiftValues

func (vd *ValueDefinition) ShiftValues() error

Jump to

Keyboard shortcuts

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