database

package
v0.0.3-beta Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_LENGTH    = 255
	DEFAULT_PRECISION = 19
	DEFAULT_SCALE     = 4
)

Variables

This section is empty.

Functions

func AndConditionFromArray

func AndConditionFromArray(conditions []interface{ Condition }) interface{ Condition }

func ConditionFromString

func ConditionFromString(table *ReflectedTable, value string) interface{ Condition }

func OrConditionFromArray

func OrConditionFromArray(conditions []interface{ Condition }) interface{ Condition }

Types

type AndCondition

type AndCondition struct {
	GenericCondition
	// contains filtered or unexported fields
}

AndCondition struct

func NewAndCondition

func NewAndCondition(condition1, condition2 interface{ Condition }) *AndCondition

func (*AndCondition) And

func (ac *AndCondition) And(condition interface{}) interface{}

func (*AndCondition) GetConditions

func (ac *AndCondition) GetConditions() []interface{ Condition }

func (*AndCondition) Or

func (ac *AndCondition) Or(condition interface{}) interface{}

type ColumnCondition

type ColumnCondition struct {
	GenericCondition
	// contains filtered or unexported fields
}

ColumnCondition struct

func NewColumnCondition

func NewColumnCondition(column *ReflectedColumn, operator, value string) *ColumnCondition

Ugly

func (*ColumnCondition) GetColumn

func (cc *ColumnCondition) GetColumn() *ReflectedColumn

func (*ColumnCondition) GetOperator

func (cc *ColumnCondition) GetOperator() string

func (*ColumnCondition) GetValue

func (cc *ColumnCondition) GetValue() string

type ColumnConverter

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

func NewColumnConverter

func NewColumnConverter(driver string) *ColumnConverter

func (*ColumnConverter) ConvertColumnName

func (cc *ColumnConverter) ConvertColumnName(column *ReflectedColumn, value string) string

func (*ColumnConverter) ConvertColumnValue

func (cc *ColumnConverter) ConvertColumnValue(column *ReflectedColumn, parameters []interface{}) string

type ColumnIncluder

type ColumnIncluder struct {
}

func (*ColumnIncluder) GetNames

func (ci *ColumnIncluder) GetNames(table *ReflectedTable, primaryTable bool, params map[string][]string) []string

func (*ColumnIncluder) GetValues

func (ci *ColumnIncluder) GetValues(table *ReflectedTable, primaryTable bool, record map[string]interface{}, params map[string][]string) map[string]interface{}

Not sure for property exists

type ColumnsBuilder

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

func NewColumnsBuilder

func NewColumnsBuilder(driver string) *ColumnsBuilder

func (*ColumnsBuilder) GetIncrement

func (cb *ColumnsBuilder) GetIncrement(table *ReflectedTable, columnValues map[string]interface{}) (string, []interface{})

func (*ColumnsBuilder) GetInsert

func (cb *ColumnsBuilder) GetInsert(table *ReflectedTable, columnValues map[string]interface{}) (string, []interface{})

GetInsert return the insert request and the parameters to ensure to preserver column names and parameters order

func (*ColumnsBuilder) GetOffsetLimit

func (cb *ColumnsBuilder) GetOffsetLimit(offset, limit int) string

func (*ColumnsBuilder) GetOrderBy

func (cb *ColumnsBuilder) GetOrderBy(table *ReflectedTable, columnOrdering [][2]string) string

func (*ColumnsBuilder) GetSelect

func (cb *ColumnsBuilder) GetSelect(table *ReflectedTable, columnNames []string) string

done

func (*ColumnsBuilder) GetUpdate

func (cb *ColumnsBuilder) GetUpdate(table *ReflectedTable, columnValues map[string]interface{}) (string, []interface{})

type Condition

type Condition interface {
	GetCondition() interface{}
	And(condition interface{}) interface{}
	Or(condition interface{}) interface{}
	Not() interface{}
}

Condition interface

type ConditionsBuilder

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

func NewConditionsBuilder

func NewConditionsBuilder(driver string) *ConditionsBuilder

func (*ConditionsBuilder) GetWhereClause

func (cb *ConditionsBuilder) GetWhereClause(condition interface{ Condition }, arguments *[]interface{}) string

type DataConverter

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

func NewDataConverter

func NewDataConverter(driver string) *DataConverter

func (*DataConverter) ConvertColumnValues

func (dc *DataConverter) ConvertColumnValues(table *ReflectedTable, columnValues *map[string]interface{})

func (*DataConverter) ConvertRecords

func (dc *DataConverter) ConvertRecords(table *ReflectedTable, columnNames []string, records *[]map[string]interface{})

Something nasty here in type conversion

type DefinitionService

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

func NewDefinitionService

func NewDefinitionService(db *GenericDB, reflection *ReflectionService) *DefinitionService

func (*DefinitionService) AddColumn

func (ds *DefinitionService) AddColumn(tableName string, definition map[string]interface{}) bool

func (*DefinitionService) AddTable

func (ds *DefinitionService) AddTable(definition map[string]interface{}) bool

func (*DefinitionService) RemoveColumn

func (ds *DefinitionService) RemoveColumn(tableName, columnName string) bool

func (*DefinitionService) RemoveTable

func (ds *DefinitionService) RemoveTable(tableName string) bool

func (*DefinitionService) UpdateColumn

func (ds *DefinitionService) UpdateColumn(tableName, columnName string, changes map[string]interface{}) bool

func (*DefinitionService) UpdateTable

func (ds *DefinitionService) UpdateTable(tableName string, changes map[string]interface{}) bool

type GenericCondition

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

func (*GenericCondition) And

func (gc *GenericCondition) And(condition interface{}) interface{}

func (*GenericCondition) GetCondition

func (gc *GenericCondition) GetCondition() interface{}

func (*GenericCondition) Not

func (gc *GenericCondition) Not() interface{}

func (*GenericCondition) Or

func (gc *GenericCondition) Or(condition interface{}) interface{}

type GenericDB

type GenericDB struct {
	VariableStore *utils.VariableStore
	// contains filtered or unexported fields
}

func NewGenericDB

func NewGenericDB(driver string, address string, port int, database string, tables map[string]bool, mapping map[string]string, username string, password string) *GenericDB

func (*GenericDB) BeginTransaction

func (g *GenericDB) BeginTransaction() (*sql.Tx, error)

func (*GenericDB) CommitTransaction

func (g *GenericDB) CommitTransaction(tx *sql.Tx) error

func (*GenericDB) CreateSingle

func (g *GenericDB) CreateSingle(tx *sql.Tx, table *ReflectedTable, columnValues map[string]interface{}) (interface{}, error)

func (*GenericDB) Definition

func (g *GenericDB) Definition() *GenericDefinition

func (*GenericDB) DeleteSingle

func (g *GenericDB) DeleteSingle(tx *sql.Tx, table *ReflectedTable, id string) (int64, error)

func (*GenericDB) GetCacheKey

func (g *GenericDB) GetCacheKey() string

func (*GenericDB) IncrementSingle

func (g *GenericDB) IncrementSingle(tx *sql.Tx, table *ReflectedTable, columnValues map[string]interface{}, id string) (int64, error)

func (*GenericDB) PDO

func (g *GenericDB) PDO() *LazyPdo

func (*GenericDB) Ping

func (g *GenericDB) Ping() int

func (*GenericDB) Reconstruct

func (g *GenericDB) Reconstruct(driver, address string, port int, database string, tables map[string]bool, mapping map[string]string, username string, password string) bool

func (*GenericDB) Reflection

func (g *GenericDB) Reflection() *GenericReflection

func (*GenericDB) RollBackTransaction

func (g *GenericDB) RollBackTransaction(tx *sql.Tx) error

func (*GenericDB) SelectAll

func (g *GenericDB) SelectAll(table *ReflectedTable, columnNames []string, condition interface{ Condition }, columnOrdering [][2]string, offset, limit int) []map[string]interface{}

Should check error

func (*GenericDB) SelectCount

func (g *GenericDB) SelectCount(table *ReflectedTable, condition interface{ Condition }) int

Should check error

func (*GenericDB) SelectMultiple

func (g *GenericDB) SelectMultiple(table *ReflectedTable, columnNames, ids []string) []map[string]interface{}

Should check error

func (*GenericDB) SelectSingle

func (g *GenericDB) SelectSingle(tx *sql.Tx, table *ReflectedTable, columnNames []string, id string) []map[string]interface{}

Should check error

func (*GenericDB) UpdateSingle

func (g *GenericDB) UpdateSingle(tx *sql.Tx, table *ReflectedTable, columnValues map[string]interface{}, id string) (int64, error)

type GenericDefinition

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

func NewGenericDefinition

func NewGenericDefinition(pdo *LazyPdo, driver, database string, tables map[string]bool, mapper *RealNameMapper) *GenericDefinition

func (*GenericDefinition) AddColumn

func (gd *GenericDefinition) AddColumn(tableName string, newColumn *ReflectedColumn) error

func (*GenericDefinition) AddColumnForeignKey

func (gd *GenericDefinition) AddColumnForeignKey(tableName, columnName string, newColumn *ReflectedColumn) error

func (*GenericDefinition) AddColumnPrimaryKey

func (gd *GenericDefinition) AddColumnPrimaryKey(tableName, columnName string, newColumn *ReflectedColumn) error

func (*GenericDefinition) AddTable

func (gd *GenericDefinition) AddTable(newTable *ReflectedTable) error

func (*GenericDefinition) GetColumnType

func (gd *GenericDefinition) GetColumnType(column *ReflectedColumn, update bool) string

func (*GenericDefinition) RemoveColumn

func (gd *GenericDefinition) RemoveColumn(tableName, columnName string) error

func (*GenericDefinition) RemoveColumnForeignKey

func (gd *GenericDefinition) RemoveColumnForeignKey(tableName, columnName string, newColumn *ReflectedColumn) error

func (*GenericDefinition) RemoveColumnPrimaryKey

func (gd *GenericDefinition) RemoveColumnPrimaryKey(tableName, columnName string, newColumn *ReflectedColumn) error

func (*GenericDefinition) RemoveTable

func (gd *GenericDefinition) RemoveTable(tableName string) error

func (*GenericDefinition) RenameColumn

func (gd *GenericDefinition) RenameColumn(tableName, columnName string, newColumn *ReflectedColumn) error

func (*GenericDefinition) RenameTable

func (gd *GenericDefinition) RenameTable(tableName, newTableName string) error

func (*GenericDefinition) RetypeColumn

func (gd *GenericDefinition) RetypeColumn(tableName, columnName string, newColumn *ReflectedColumn) error

func (*GenericDefinition) SetColumnNullable

func (gd *GenericDefinition) SetColumnNullable(tableName, columnName string, newColumn *ReflectedColumn) error

type GenericReflection

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

func NewGenericReflection

func NewGenericReflection(pdo *LazyPdo, driver string, database string, tables map[string]bool, mapper *RealNameMapper) *GenericReflection

func (*GenericReflection) GetDatabaseName

func (r *GenericReflection) GetDatabaseName() string

func (*GenericReflection) GetIgnoredTables

func (r *GenericReflection) GetIgnoredTables() []string

func (*GenericReflection) GetTableColumns

func (r *GenericReflection) GetTableColumns(tableName string, viewType string) []map[string]interface{}

func (*GenericReflection) GetTableForeignKeys

func (r *GenericReflection) GetTableForeignKeys(tableName string) map[string]string

func (*GenericReflection) GetTablePrimaryKeys

func (r *GenericReflection) GetTablePrimaryKeys(tableName string) []string

func (*GenericReflection) GetTables

func (r *GenericReflection) GetTables() []map[string]interface{}

func (*GenericReflection) ToJdbcType

func (r *GenericReflection) ToJdbcType(jdbcType string, size string) string

type LazyPdo

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

LazyPdo is a custom db client

func NewLazyPdo

func NewLazyPdo(dsn string, user string, password string, options map[string]string) *LazyPdo

func (*LazyPdo) AddInitCommand

func (l *LazyPdo) AddInitCommand(command string)

func (*LazyPdo) BeginTransaction

func (l *LazyPdo) BeginTransaction() (*sql.Tx, error)

func (*LazyPdo) CloseConn

func (l *LazyPdo) CloseConn()

func (*LazyPdo) Commit

func (l *LazyPdo) Commit(tx *sql.Tx) error

Should check return status

func (*LazyPdo) Exec

func (l *LazyPdo) Exec(tx *sql.Tx, req string, parameters ...interface{}) (sql.Result, error)

func (*LazyPdo) GetAttribute

func (l *LazyPdo) GetAttribute(attribute string) interface{}

func (*LazyPdo) InTransaction

func (l *LazyPdo) InTransaction() bool

To be done

func (*LazyPdo) Query

func (l *LazyPdo) Query(tx *sql.Tx, req string, parameters ...interface{}) ([]map[string]interface{}, error)

func (*LazyPdo) QueryRowSingleColumn

func (l *LazyPdo) QueryRowSingleColumn(tx *sql.Tx, req string, parameters ...interface{}) (interface{}, error)

func (*LazyPdo) Reconstruct

func (l *LazyPdo) Reconstruct(dsn string, user string, password string, options map[string]string) bool

func (*LazyPdo) RollBack

func (l *LazyPdo) RollBack(tx *sql.Tx) error

Should check return status

func (*LazyPdo) Rows2Map

func (l *LazyPdo) Rows2Map(rows *sql.Rows) ([]map[string]interface{}, error)

from https://kylewbanks.com/blog/query-result-to-map-in-golang

func (*LazyPdo) SetAttribute

func (l *LazyPdo) SetAttribute(attribute, value interface{}) bool

type NoCondition

type NoCondition struct {
}

NoCondition struct

func NewNoCondition

func NewNoCondition() *NoCondition

func (*NoCondition) And

func (nc *NoCondition) And(condition interface{}) interface{}

func (*NoCondition) GetCondition

func (nc *NoCondition) GetCondition() interface{}

func (*NoCondition) Not

func (nc *NoCondition) Not() interface{}

func (*NoCondition) Or

func (nc *NoCondition) Or(condition interface{}) interface{}

type NotCondition

type NotCondition struct {
	GenericCondition
	// contains filtered or unexported fields
}

NotCondition struct

func NewNotCondition

func NewNotCondition(condition interface{ Condition }) *NotCondition

func (*NotCondition) And

func (nc *NotCondition) And(condition interface{}) interface{}

func (*NotCondition) GetCondition

func (nc *NotCondition) GetCondition() interface{}

func (*NotCondition) Or

func (nc *NotCondition) Or(condition interface{}) interface{}

type OrCondition

type OrCondition struct {
	GenericCondition
	// contains filtered or unexported fields
}

OrCondition struct

func NewOrCondition

func NewOrCondition(condition1, condition2 interface{ Condition }) *OrCondition

func (*OrCondition) And

func (oc *OrCondition) And(condition interface{}) interface{}

func (*OrCondition) GetConditions

func (ac *OrCondition) GetConditions() []interface{ Condition }

func (*OrCondition) Or

func (oc *OrCondition) Or(condition interface{}) interface{}

type RealNameMapper

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

func NewRealNameMapper

func NewRealNameMapper(mapping map[string]string) *RealNameMapper

func (*RealNameMapper) GetColumnName

func (rnm *RealNameMapper) GetColumnName(tableRealName, columnRealName string) string

func (*RealNameMapper) GetColumnRealName

func (rnm *RealNameMapper) GetColumnRealName(tableName, columnName string) string

func (*RealNameMapper) GetTableName

func (rnm *RealNameMapper) GetTableName(tableRealName string) string

func (*RealNameMapper) GetTableRealName

func (rnm *RealNameMapper) GetTableRealName(tableName string) string

type ReflectedColumn

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

func NewReflectedColumn

func NewReflectedColumn(name, realName, columnType string, length, precision, scale int, nullable, pk bool, fk string) *ReflectedColumn

done

func NewReflectedColumnFromJson

func NewReflectedColumnFromJson(json map[string]interface{}) *ReflectedColumn

func NewReflectedColumnFromReflection

func NewReflectedColumnFromReflection(reflection *GenericReflection, columnResult map[string]interface{}) *ReflectedColumn

done

func (*ReflectedColumn) GetFk

func (rc *ReflectedColumn) GetFk() string

func (*ReflectedColumn) GetLength

func (rc *ReflectedColumn) GetLength() int

func (*ReflectedColumn) GetName

func (rc *ReflectedColumn) GetName() string

func (*ReflectedColumn) GetNullable

func (rc *ReflectedColumn) GetNullable() bool

func (*ReflectedColumn) GetPk

func (rc *ReflectedColumn) GetPk() bool

func (*ReflectedColumn) GetPrecision

func (rc *ReflectedColumn) GetPrecision() int

func (*ReflectedColumn) GetRealName

func (rc *ReflectedColumn) GetRealName() string

func (*ReflectedColumn) GetScale

func (rc *ReflectedColumn) GetScale() int

func (*ReflectedColumn) GetType

func (rc *ReflectedColumn) GetType() string

func (*ReflectedColumn) HasLength

func (rc *ReflectedColumn) HasLength() bool

func (*ReflectedColumn) HasPrecision

func (rc *ReflectedColumn) HasPrecision() bool

func (*ReflectedColumn) HasScale

func (rc *ReflectedColumn) HasScale() bool

func (*ReflectedColumn) IsBinary

func (rc *ReflectedColumn) IsBinary() bool

func (*ReflectedColumn) IsBoolean

func (rc *ReflectedColumn) IsBoolean() bool

func (*ReflectedColumn) IsGeometry

func (rc *ReflectedColumn) IsGeometry() bool

func (*ReflectedColumn) IsInteger

func (rc *ReflectedColumn) IsInteger() bool

func (*ReflectedColumn) JsonSerialize

func (rc *ReflectedColumn) JsonSerialize() map[string]interface{}

func (*ReflectedColumn) MarshalJSON

func (rt *ReflectedColumn) MarshalJSON() ([]byte, error)

json marshaling for struct ReflectedTable

func (*ReflectedColumn) Serialize

func (rc *ReflectedColumn) Serialize() map[string]interface{}

func (*ReflectedColumn) SetFk

func (rc *ReflectedColumn) SetFk(value string)

func (*ReflectedColumn) SetPk

func (rc *ReflectedColumn) SetPk(value bool)

type ReflectedDatabase

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

func NewReflectedDatabase

func NewReflectedDatabase(tableTypes, tableRealNames map[string]string) *ReflectedDatabase

func NewReflectedDatabaseFromJson

func NewReflectedDatabaseFromJson(data string) *ReflectedDatabase

func NewReflectedDatabaseFromReflection

func NewReflectedDatabaseFromReflection(reflection *GenericReflection) *ReflectedDatabase

done

func (*ReflectedDatabase) GetRealName

func (rd *ReflectedDatabase) GetRealName(tableName string) string

func (*ReflectedDatabase) GetTableNames

func (rd *ReflectedDatabase) GetTableNames() []string

func (*ReflectedDatabase) GetType

func (rd *ReflectedDatabase) GetType(tableName string) string

func (*ReflectedDatabase) HasTable

func (rd *ReflectedDatabase) HasTable(tableName string) bool

done

func (*ReflectedDatabase) MarshalJSON

func (rd *ReflectedDatabase) MarshalJSON() ([]byte, error)

json marshaling for struct ReflectedDatabase

func (*ReflectedDatabase) RemoveTable

func (rd *ReflectedDatabase) RemoveTable(tableName string) bool

func (*ReflectedDatabase) Serialize

func (rd *ReflectedDatabase) Serialize() map[string]interface{}

type ReflectedTable

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

func NewReflectedTable

func NewReflectedTable(name, realName, tableType string, columns map[string]*ReflectedColumn) *ReflectedTable

func NewReflectedTableFromJson

func NewReflectedTableFromJson(json map[string]interface{}) *ReflectedTable

func NewReflectedTableFromReflection

func NewReflectedTableFromReflection(reflection *GenericReflection, name, realName, viewType string) *ReflectedTable

done

func (*ReflectedTable) GetColumn

func (rt *ReflectedTable) GetColumn(columnName string) *ReflectedColumn

func (*ReflectedTable) GetColumnNames

func (rt *ReflectedTable) GetColumnNames() []string

func (*ReflectedTable) GetFksTo

func (rt *ReflectedTable) GetFksTo(tableName string) []*ReflectedColumn

func (*ReflectedTable) GetName

func (rt *ReflectedTable) GetName() string

func (*ReflectedTable) GetPk

func (rt *ReflectedTable) GetPk() *ReflectedColumn

func (*ReflectedTable) GetRealName

func (rt *ReflectedTable) GetRealName() string

func (*ReflectedTable) GetType

func (rt *ReflectedTable) GetType() string

func (*ReflectedTable) HasColumn

func (rt *ReflectedTable) HasColumn(columnName string) bool

func (*ReflectedTable) HasPk

func (rt *ReflectedTable) HasPk() bool

func (*ReflectedTable) JsonSerialize

func (rt *ReflectedTable) JsonSerialize() map[string]interface{}

func (*ReflectedTable) MarshalJSON

func (rt *ReflectedTable) MarshalJSON() ([]byte, error)

json marshaling for struct ReflectedTable

func (*ReflectedTable) RemoveColumn

func (rt *ReflectedTable) RemoveColumn(columnName string) bool

func (*ReflectedTable) Serialize

func (rt *ReflectedTable) Serialize() map[string]interface{}

type ReflectionService

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

func NewReflectionService

func NewReflectionService(db *GenericDB, lcache cache.Cache, ttl int32) *ReflectionService

func (*ReflectionService) GetTable

func (rs *ReflectionService) GetTable(tableName string) *ReflectedTable

func (*ReflectionService) GetTableNames

func (rs *ReflectionService) GetTableNames() []string

func (*ReflectionService) GetType

func (rs *ReflectionService) GetType(tableName string) string

func (*ReflectionService) HasTable

func (rs *ReflectionService) HasTable(tableName string) bool

func (*ReflectionService) RefreshTable

func (rs *ReflectionService) RefreshTable(tableName string)

func (*ReflectionService) RefreshTables

func (rs *ReflectionService) RefreshTables()

func (*ReflectionService) RemoveTable

func (rs *ReflectionService) RemoveTable(tableName string) bool

type SpatialCondition

type SpatialCondition struct {
	ColumnCondition
}

SpatialCondition struct

func NewSpatialCondition

func NewSpatialCondition(column *ReflectedColumn, operator, value string) *SpatialCondition

Ugly

func (*SpatialCondition) And

func (sc *SpatialCondition) And(condition interface{}) interface{}

func (*SpatialCondition) Or

func (sc *SpatialCondition) Or(condition interface{}) interface{}

type TypeConverter

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

func NewTypeConverter

func NewTypeConverter(driver string) *TypeConverter

func (*TypeConverter) FromJdbc

func (t *TypeConverter) FromJdbc(jdbcType string) string

func (*TypeConverter) ToJdbc

func (t *TypeConverter) ToJdbc(jdbcType string, size string) string

Jump to

Keyboard shortcuts

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