gorpx

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 12 Imported by: 2

README

Package gorpx

GoDoc

Documentation

Overview

Package gorpx manages connections to multiple datasources (i.e. one sqlite3, another mysql) and keeps a map for each datasource with connection pool and a data dict mapper. The mapping of tables is then application specific. Data definition stuff is then application specific. Data modification stuff is then application specific.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRes

func CheckRes(sqlRes sql.Result, err error)

CheckRes is checking the error *and* the sql result of a sql query.

func Concat

func Concat(dbType string, args ...string) string

func Db

func Db(optDataSourceID ...int) *sql.DB

Db returns the data source by data source index

func Db2Map

func Db2Map() *gorp.DbMap

Db2Map returns the second DB Map

func Db2TableName

func Db2TableName(i interface{}) string

Db2TableName returns the table name from the second data source index

func DbClose

func DbClose(optDataSourceID ...int)

DbClose closes by data source index

func DbMap

func DbMap(optDataSourceID ...int) *gorp.DbMap

DbMap returns default DB Map, that is being reused on each DB operation. On the first call, a default map is created anew. The DB default map can then be mapped to the application specific tables like this:

func MapAllTables(argDbMap *gorp.DbMap) {
		argDbMap.AddTableWithName(paramgroup.ParamGroup{}, "paramgroup")
		argDbMap.AddTable(pivot.Pivot{})
		:
}

func DbTableName

func DbTableName(i interface{}, optDataSourceID ...int) string

DbTableName - for fun and confusion, the table names are in lower case or title case, depending on windows/linux and mysql/sqlite3. It depends on the MySQL server settings, whether it objects to wrong case. We cannot take any chances, we must derive the table name dynamical:

func IndependentDbMapper

func IndependentDbMapper(optDataSourceID ...int) *gorp.DbMap

IndependentDbMapper creates a new DB Mapper on each call. Because for instance EnablePlainInserts() creates irreversible changes to a DB map, and we need a new one afterwards.

func IndependentDbMapperFunc

func IndependentDbMapperFunc(idx int) func() *gorp.DbMap

IndependentDbMapperFunc for some operations who need several DB mappers in a row. For this, we have a DB mapper "factory".

func SetAndInitDatasourceId

func SetAndInitDatasourceId(hosts SQLHosts, dataSourceId int)

SetAndInitDatasourceId - the key to SQLHosts config is given either

by environment variable DATASOURCEX

or set to default "dsnX" or explicitly submitted as optional key (i.e. for temporary backups)

The resulting connection is then set as data source id x. data source id 0 is the default. data source id 1 is the target for comparisons. data source id 2 is for backups

func TraceOff

func TraceOff()

TraceOff disables SQL tracing

func TraceOn

func TraceOn()

TraceOn enables SQL tracing for all default dbMappers. Does not affect independent dbMappers.

func Type

func Type(optDataSourceID ...int) string

Type returns "sqllite or mysql" by data source index

Types

type SQLHost

type SQLHost struct {
	Type             string            `json:"type"` // sqlite3
	User             string            `json:"user"`
	Host             string            `json:"host"`
	Port             string            `json:"port"`
	DbName           string            `json:"db_name"` // also sqlite3 filename
	ConnectionParams map[string]string `json:"connection_params"`
}

SQLHost represents DB resource

type SQLHosts

type SQLHosts map[string]SQLHost

SQLHosts organizes multiple DB resources

Jump to

Keyboard shortcuts

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