db

package
v1.8.9 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package db to support openM++ model database operations.

Database may contain multiple openM++ models and consists of two parts: (a) metadata to describe models: data types, input parameters, output tables, etc. (b) actual modeling data itself: database tables for input parameters and output tables.

To run the model we need to have a set of model input parameters, called "input working set" or "workset". User can "open" workset in read-write mode and modify model input parameters. To use that set as model run input user must "close" it by marking workset as read-only. After model run user can again open workset as read-write and continue input editing. Each workset has a name (unique inside of the model) and set id (database unique positive int).

Result of model run stored in output tables and also include copy of all input parameters used to run the model. That pair of input and output data called "run" and identified by run id (database unique positive int).

Index

Constants

View Source
const (
	SQLiteDbDriver  = "SQLite"  // default db driver name
	SQLiteTimeout   = 86400     // default SQLite busy timeout
	Sqlite3DbDriver = "sqlite3" // SQLite db driver name
	OdbcDbDriver    = "odbc"    // ODBC db driver name
)

Database connection values

View Source
const (
	InitRunStatus     = "i" // i = initial status
	ProgressRunStatus = "p" // p = run in progress
	WaitRunStatus     = "w" // w = wait: run in progress, under external supervision
	DoneRunStatus     = "s" // s = completed successfully
	ExitRunStatus     = "x" // x = exit and not completed
	ErrorRunStatus    = "e" // e = error failure
)

Model run status (run_lst table) and modeling task run status (task_run_lst table):

if task status = w (wait) then
   model wait and NOT completed until other process set status to one of finals: s,x,e
   model check if any new sets inserted into task_set and run it as they arrive
View Source
const IsOdbcSupported = false

IsOdbcSupported indicate support of ODBC connections built-in

View Source
const MaxSchemaVersion = 102

MaxSchemaVersion is a maximum compatible db schema version

View Source
const MinSchemaVersion = 102

MinSchemaVersion is a minimal compatible db schema version

View Source
const TotalEnumCode = "all"

TotalEnumCode is predefined enum code for "total" enum

Variables

This section is empty.

Functions

func CheckOpenmppSchemaVersion

func CheckOpenmppSchemaVersion(dbConn *sql.DB) error

CheckOpenmppSchemaVersion return error if it is not openM++ db or schema version incompatible

func CopyParameterFromRun

func CopyParameterFromRun(dbConn *sql.DB, modelDef *ModelMeta, wst *WorksetRow, paramName string, rst *RunRow) error

CopyParameterFromRun copy parameter metadata and parameter values into workset from model run.

If parameter already exist in destination workset then error returned. Destination workset must be in read-write state. Source model run must be completed, run status one of: s=success, x=exit, e=error.

func CopyParameterFromWorkset

func CopyParameterFromWorkset(dbConn *sql.DB, modelDef *ModelMeta, dstWs *WorksetRow, paramName string, srcWs *WorksetRow) error

CopyParameterFromWorkset copy parameter metadata and parameter values from one workset to another.

If parameter already exist in destination workset then error returned. Destination workset must be in read-write state, source workset must be read-only.

func DeleteModel

func DeleteModel(dbConn *sql.DB, modelId int) error

DeleteModel delete existing model metadata and drop model data tables from database.

func DeleteProfile

func DeleteProfile(dbConn *sql.DB, name string) error

DeleteProfile delete rows from profile in profile_lst and profile_option tables.

func DeleteProfileOption

func DeleteProfileOption(dbConn *sql.DB, name, key string) error

DeleteProfileOption delete row from profile_option table.

func DeleteRun

func DeleteRun(dbConn *sql.DB, runId int) error

DeleteRun delete model run metadata, parameters run values and output tables run values from database.

func DeleteTask

func DeleteTask(dbConn *sql.DB, taskId int) error

DeleteTask delete modeling task and task run history from database.

func DeleteWorkset

func DeleteWorkset(dbConn *sql.DB, setId int) error

DeleteWorkset delete workset metadata and workset parameter values from database.

func DeleteWorksetAllParameters added in v1.6.3

func DeleteWorksetAllParameters(dbConn *sql.DB, setId int) error

DeleteWorksetAllParameters delete all parameters metadata and values from workset.

Workset must be read-write in order to delete all parameters. If workset does not exist then nothing deleted and no errors returned, it is empty operation.

func DeleteWorksetParameter

func DeleteWorksetParameter(dbConn *sql.DB, modelId int, setName, paramName string) (int, error)

DeleteWorksetParameter do delete parameter metadata and values from workset.

If parameter not exist in workset then nothing deleted. Workset must be read-write in order to delete parameter. It is return parameter Hid = 0 if nothing deleted.

func GetModelId

func GetModelId(dbConn *sql.DB, name, digest string) (bool, int, error)

GetModelId return model id if exists.

Model selected by name and/or digest, i.e.: ("modelOne", "abcd20120817160459148") if digest is empty then first model with min(model_id) is used

func GetModelRunOptions

func GetModelRunOptions(dbConn *sql.DB, modelId int) (map[int]map[string]string, error)

GetModelOptions return model run_option table rows as map of maps: map(run_id, map(key, value)).

func GetProfileList

func GetProfileList(dbConn *sql.DB) ([]string, error)

GetProfileList return profile names: profile_lst table rows.

Profile is a named group of (key, value) options, similar to ini-file. Default model options has profile_name = model_name.

func GetRunListText

func GetRunListText(dbConn *sql.DB, modelId int, langCode string) ([]RunRow, []RunTxtRow, error)

GetRunListText return list of model runs with description and notes: run_lst and run_txt rows.

If langCode not empty then only specified language selected else all languages

func GetRunOptions

func GetRunOptions(dbConn *sql.DB, runId int) (map[string]string, error)

GetRunOptions return run_option table rows as (key, value) map.

func GetTaskListText

func GetTaskListText(dbConn *sql.DB, modelId int, langCode string) ([]TaskRow, []TaskTxtRow, error)

GetTaskListText return list of modeling tasks with description and notes: task_lst and task_txt rows.

If langCode not empty then only specified language selected else all languages

func GetTaskSetIds

func GetTaskSetIds(dbConn *sql.DB, taskId int) ([]int, error)

GetTaskSetIds return modeling task set id's by task id from task_set db table

func GetWorksetListText

func GetWorksetListText(dbConn *sql.DB, modelId int, langCode string) ([]WorksetRow, []WorksetTxtRow, error)

GetWorksetListText return list of model worksets, description and notes: workset_lst and workset_txt rows.

If langCode not empty then only specified language selected else all languages

func GetWorksetParam added in v1.6.3

func GetWorksetParam(dbConn *sql.DB, setId int, paramHid int) (int, int, error)

GetWorksetParam return sub-values count and default sub-value id for workset parameter: SELECT sub_count, default_sub_id FROM workset_parameter

func GetWorksetParamList

func GetWorksetParamList(dbConn *sql.DB, setId int) ([]int, []int, []int, error)

GetWorksetParamList return Hid, sub-values count and default sub-value id for all parameters included in that workset: SELECT parameter_hid, sub_count, default_sub_id FROM workset_parameter

func GetWorksetRunIds

func GetWorksetRunIds(dbConn *sql.DB, setId int) ([]int, error)

GetWorksetRunIds return ids of model run results (run_id) where input parameters are from specified working set.

Only successfully completed run ids returned, not failed, not "in progress". This method is "local" to database and if data transfered between databases it very likely return wrong results. This method is not recommended, use modeling task to establish relationship between input set and model run.

func IfEmptyMakeDefault

func IfEmptyMakeDefault(modelName, dbConnStr, dbDriver string) (string, string)

IfEmptyMakeDefault return SQLite connection string and driver name based on model name:

Database=modelName.sqlite; Timeout=86400; OpenMode=ReadWrite;

func IsRunCompleted

func IsRunCompleted(status string) bool

IsRunCompleted retrun true if run status one of: s=success, x=exit, e=error

func MakeSqliteDefault

func MakeSqliteDefault(modelSqlitePath string) string

MakeSqliteDefault return default SQLite connection string based on model.sqlite file path:

Database=model.sqlite; Timeout=86400; OpenMode=ReadWrite;

func OpenmppSchemaVersion

func OpenmppSchemaVersion(dbConn *sql.DB) (int, error)

OpenmppSchemaVersion return db schema: select id_value from id_lst where id_key = 'openmpp'

func RenameRun added in v1.6.3

func RenameRun(dbConn *sql.DB, runId int, newRunName string) (bool, error)

RenameRun do rename model run if new name is not empty "" string.

func RenameTask added in v1.6.3

func RenameTask(dbConn *sql.DB, taskId int, newTaskName string) (bool, error)

RenameTask do rename task if new name is not empty "" string

func RenameWorkset added in v1.6.3

func RenameWorkset(dbConn *sql.DB, setId int, newSetName string, isAnyReadonly bool) (bool, error)

RenameWorkset do rename workset if new name is not empty "" string.

If isAnyReadonly parameter is true then do rename regarless of workset read-only status else return error if workset is not read-write.

func SelectFirst

func SelectFirst(dbConn *sql.DB, query string, cvt func(row *sql.Row) error) error

SelectFirst select first db row and pass it to cvt() for row.Scan()

func SelectRows

func SelectRows(dbConn *sql.DB, query string, cvt func(rows *sql.Rows) error) error

SelectRows select db rows and pass each to cvt() for rows.Scan()

func TrxSelectFirst

func TrxSelectFirst(dbTrx *sql.Tx, query string, cvt func(row *sql.Row) error) error

TrxSelectFirst select first db row in transaction scope and pass it to cvt() for row.Scan()

func TrxSelectRows

func TrxSelectRows(dbTrx *sql.Tx, query string, cvt func(rows *sql.Rows) error) error

TrxSelectRows select db rows in transaction scope and pass each to cvt() for rows.Scan()

func TrxUpdate

func TrxUpdate(dbTrx *sql.Tx, query string) error

TrxUpdate execute sql query in transaction scope

func TrxUpdateStatement

func TrxUpdateStatement(dbTrx *sql.Tx, query string, put func() (bool, []interface{}, error)) error

TrxUpdateStatement execute sql statement in transaction scope until put() return true

func Update

func Update(dbConn *sql.DB, query string) error

Update execute sql query outside of transaction scope (on different connection)

func UpdateLanguage

func UpdateLanguage(dbConn *sql.DB, langDef *LangMeta) error

UpdateLanguage insert new or update existing language and words in lang_lst and lang_word tables. Language ids updated with actual id's from database

func UpdateModel

func UpdateModel(dbConn *sql.DB, dbFacet Facet, modelDef *ModelMeta) (bool, error)

UpdateModel insert new model metadata in database, return true if model inserted or false if already exist.

If model with same digest already exist then call simply return existing model metadata (no changes made in database). Parameters and output tables Hid's and db table names updated with actual database values If new model inserted then modelDef updated with actual id's (model id, parameter Hid...) If parameter (output table) not exist then create db tables for parameter values (output table values) If db table names is "" empty then make db table names for parameter values (output table values)

func UpdateModelText

func UpdateModelText(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta, modelTxt *ModelTxtMeta) error

UpdateModelText insert new or update existing model text (description and notes) in database.

Model id, type Hid, parameter Hid, table Hid, language id updated with actual database id's

func UpdateModelWord

func UpdateModelWord(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta, mwDef *ModelWordMeta) error

UpdateModelWord insert new or update existing model language-specific strings in model_word table.

func UpdateProfile

func UpdateProfile(dbConn *sql.DB, profile *ProfileMeta) error

UpdateProfile insert new or replace existing profile in profile_lst and profile_option tables.

It always replacing all existing rows by delete from profile_lst and profile_option where profile_name = profile.Name and insert new rows into profile_lst and profile_option tables.

func UpdateProfileOption

func UpdateProfileOption(dbConn *sql.DB, name, key, val string) error

UpdateProfileOption insert new or replace existing profile option in profile_option table. It is also will insert profile name into profile_lst table if such name does not already exist.

func UpdateRunValueDigest

func UpdateRunValueDigest(dbConn *sql.DB, runId int) (string, error)

UpdateRunValueDigest does recalculate and update run_lst table with new run value digest and return it. If run not exist or status is not success or exit then digest is "" empty (not updated).

func UpdateWorksetReadonly

func UpdateWorksetReadonly(dbConn *sql.DB, setId int, isReadonly bool) error

UpdateWorksetReadonly update workset readonly status.

func UpdateWorksetReadonlyByName

func UpdateWorksetReadonlyByName(dbConn *sql.DB, modelId int, name string, isReadonly bool) error

UpdateWorksetReadonlyByName update workset readonly status by workset name.

func WriteOutputTable

func WriteOutputTable(
	dbConn *sql.DB, modelDef *ModelMeta, layout *WriteTableLayout, accCellLst *list.List, exprCellLst *list.List) error

WriteOutputTable insert output table values (accumulators or expressions) into model run.

Model run must exist and be in completed state (i.e. success or error state). Model run should not already contain output table values: it can be inserted only once in model run and cannot be updated after. Double format is used for float model types digest calculation, if non-empty format supplied

func WriteParameter

func WriteParameter(dbConn *sql.DB, modelDef *ModelMeta, layout *WriteParamLayout, cellLst *list.List) error

WriteParameter insert or update parameter values in workset or insert parameter values into model run.

If this is model run update (layout.IsToRun is true) then model run must exist and be in completed state (i.e. success or error state). Model run should not already contain parameter values: parameter can be inserted only once in model run and cannot be updated after.

If workset already contain parameter values then values updated else inserted. If only "page" of workset parameter rows supplied (layout.IsPage is true) then each row deleted by primary key before insert else all rows deleted by one delete by set id.

Double format is used for float model types digest calculation, if non-empty format supplied

Types

type CellAcc

type CellAcc struct {
	AccId int // output table accumulator id
	SubId int // output table subvalue id
	// contains filtered or unexported fields
}

CellAcc is value of output table accumulator.

func (CellAcc) CsvFileName

func (CellAcc) CsvFileName(modelDef *ModelMeta, name string, isIdCsv bool) (string, error)

CsvFileName return file name of csv file to store output table accumulator rows

func (CellAcc) CsvHeader

func (CellAcc) CsvHeader(modelDef *ModelMeta, name string, isIdHeader bool, valueName string) ([]string, error)

CsvHeader retrun first line for csv file: column names. It is like: acc_name,sub_id,dim0,dim1,acc_value or if isIdHeader is true: acc_id,sub_id,dim0,dim1,acc_value

func (CellAcc) CsvToCell

func (CellAcc) CsvToCell(
	modelDef *ModelMeta, name string, subCount int, valueName string,
) (
	func(row []string) (interface{}, error), error)

CsvToCell return closure to convert csv row []string to output table accumulator cell (dimensions and value).

It does retrun error if len(row) not equal to number of fields in cell db-record. If dimension type is enum based then csv row is enum code and cell.DimIds is enum id.

func (CellAcc) CsvToIdRow

func (CellAcc) CsvToIdRow(
	modelDef *ModelMeta, name string, doubleFmt string, valueName string,
) (
	func(interface{}, []string) error, error)

CsvToIdRow return converter from output table cell (acc_id, sub_id, dimensions, value) to csv row []string.

Converter simply does Sprint() for each dimension item id, accumulator id, subvalue number and value. Converter will retrun error if len(row) not equal to number of fields in csv record. Double format string is used if parameter type is float, double, long double

func (CellAcc) CsvToRow

func (CellAcc) CsvToRow(
	modelDef *ModelMeta, name string, doubleFmt string, valueName string,
) (
	func(interface{}, []string) error, error)

CsvToRow return converter from output table cell (acc_id, sub_id, dimensions, value) to csv row []string (acc_name, sub_id, dimensions, value).

Converter will retrun error if len(row) not equal to number of fields in csv record. Double format string is used if parameter type is float, double, long double If dimension type is enum based then csv row is enum code and cell.DimIds is enum id.

func (CellAcc) IdToCodeCell

func (CellAcc) IdToCodeCell(
	modelDef *ModelMeta, name string,
) (
	func(interface{}) (interface{}, error), error)

IdToCodeCell return converter from output table cell of ids: (acc_id, sub_id, dimensions, value) to cell of codes: (acc_id, sub_id, dimensions as enum code, value)

If dimension type is enum based then dimensions enum ids can be converted to enum code. If dimension type is simple (bool or int) then dimension value converted to string.

type CellAllAcc

type CellAllAcc struct {
	DimIds []int     // dimensions item as enum ids or int values if dimension type simple
	SubId  int       // output table subvalue id
	IsNull []bool    // if true then value is NULL
	Value  []float64 // accumulator value(s)
}

CellAllAcc is value of multiple output table accumulators.

func (CellAllAcc) CsvFileName

func (CellAllAcc) CsvFileName(modelDef *ModelMeta, name string, isIdCsv bool) (string, error)

CsvFileName return file name of csv file to store all accumulators rows

func (CellAllAcc) CsvHeader

func (CellAllAcc) CsvHeader(modelDef *ModelMeta, name string, isIdHeader bool, valueName string) ([]string, error)

CsvHeader retrun first line for csv file: column names. It is like: sub_id,dim0,dim1,acc0,acc1,acc2 If valueName is "" empty then all accumulators use for csv else one

func (CellAllAcc) CsvToCell

func (CellAllAcc) CsvToCell(
	modelDef *ModelMeta, name string, subCount int, valueName string,
) (
	func(row []string) (interface{}, error), error)

CsvToCell return closure to convert csv row []string to output table accumulator cell (dimensions and value).

It does retrun error if len(row) not equal to number of fields in cell db-record. If dimension type is enum based then csv row is enum code and cell.DimIds is enum id.

func (CellAllAcc) CsvToIdRow

func (CellAllAcc) CsvToIdRow(
	modelDef *ModelMeta, name string, doubleFmt string, valueName string,
) (
	func(interface{}, []string) error, error)

CsvToIdRow return converter from output table cell (sub_id, dimensions, acc0, acc1, acc2) to csv row []string.

Converter simply does Sprint() for each dimension item id, subvalue number and value(s). Converter will retrun error if len(row) not equal to number of fields in csv record. Double format string is used if parameter type is float, double, long double If valueName is "" empty then all accumulators converted else one

func (CellAllAcc) CsvToRow

func (CellAllAcc) CsvToRow(
	modelDef *ModelMeta, name string, doubleFmt string, valueName string,
) (
	func(interface{}, []string) error, error)

CsvToRow return converter from output table cell (sub_id, dimensions, acc0, acc1, acc2 to csv row []string (acc_name, sub_id, dimensions, value).

Converter will retrun error if len(row) not equal to number of fields in csv record. Double format string is used if parameter type is float, double, long double If dimension type is enum based then csv row is enum code and cell.DimIds is enum id. If valueName is "" empty then all accumulators converted else one

func (CellAllAcc) IdToCodeCell

func (CellAllAcc) IdToCodeCell(
	modelDef *ModelMeta, name string,
) (
	func(interface{}) (interface{}, error), error)

IdToCodeCell return converter from output table cell of ids: (sub_id, dimensions, acc0, acc1, acc2) to cell of codes: (sub_id, dimensions as enum code, acc0, acc1, acc2)

If dimension type is enum based then dimensions enum ids can be converted to enum code. If dimension type is simple (bool or int) then dimension value converted to string.

type CellCodeAcc

type CellCodeAcc struct {
	AccId int // output table accumulator id
	SubId int // output table subvalue id
	// contains filtered or unexported fields
}

CellCodeAcc is value of output table accumulator. Dimension(s) items are enum codes, not enum ids.

type CellCodeAllAcc

type CellCodeAllAcc struct {
	Dims   []string  // dimensions as enum codes or string of item if dimension type simple then
	SubId  int       // output table subvalue id
	IsNull []bool    // if true then value is NULL
	Value  []float64 // accumulator value(s)
}

CellCodeAllAcc is value of multiple output table accumulators. Dimension(s) items are enum codes, not enum ids.

type CellCodeExpr

type CellCodeExpr struct {
	ExprId int // output table expression id
	// contains filtered or unexported fields
}

CellCodeExpr is value of output table expression. Dimension(s) items are enum codes, not enum ids.

type CellCodeParam

type CellCodeParam struct {
	SubId int // parameter subvalue id
	// contains filtered or unexported fields
}

CellCodeParam is value of input parameter. Dimension(s) items are enum codes, not enum ids.

func (CellCodeParam) CodeToIdCell

func (CellCodeParam) CodeToIdCell(modelDef *ModelMeta, name string,
) (
	func(interface{}) (interface{}, error), error)

CodeToIdCell return converter from parameter cell of codes: (sub id, dimensions as enum code, value) to cell of ids: (sub id, dimensions, value)

If dimension type is enum based then dimensions enum codes converted to enum ids. If dimension type is simple (bool or int) then dimension code converted from string to dimension type. If parameter type is enum based then cell value enum code converted to enum id.

type CellExpr

type CellExpr struct {
	ExprId int // output table expression id
	// contains filtered or unexported fields
}

CellExpr is value of output table expression.

func (CellExpr) CsvFileName

func (CellExpr) CsvFileName(modelDef *ModelMeta, name string, isIdCsv bool) (string, error)

CsvFileName return file name of csv file to store output table expression rows

func (CellExpr) CsvHeader

func (CellExpr) CsvHeader(modelDef *ModelMeta, name string, isIdHeader bool, valueName string) ([]string, error)

CsvHeader retrun first line for csv file: column names. It is like: expr_name,dim0,dim1,expr_value or if isIdHeader is true: expr_id,dim0,dim1,expr_value

func (CellExpr) CsvToCell

func (CellExpr) CsvToCell(
	modelDef *ModelMeta, name string, subCount int, valueName string,
) (
	func(row []string) (interface{}, error), error)

CsvToCell return closure to convert csv row []string to output table expression cell (dimensions and value).

It does retrun error if len(row) not equal to number of fields in cell db-record. If dimension type is enum based then csv row is enum code and cell.DimIds is enum id.

func (CellExpr) CsvToIdRow

func (CellExpr) CsvToIdRow(
	modelDef *ModelMeta, name string, doubleFmt string, valueName string,
) (
	func(interface{}, []string) error, error)

CsvToIdRow return converter from output table cell (expr_id, dimensions, value) to csv row []string.

Converter simply does Sprint() for each dimension item id, expression id and value. Converter will retrun error if len(row) not equal to number of fields in csv record. Double format string is used if parameter type is float, double, long double

func (CellExpr) CsvToRow

func (CellExpr) CsvToRow(
	modelDef *ModelMeta, name string, doubleFmt string, valueName string,
) (
	func(interface{}, []string) error, error)

CsvToRow return converter from output table cell (expr_id, dimensions, value) to csv row []string (expr_name, dimensions, value).

Converter will retrun error if len(row) not equal to number of fields in csv record. Double format string is used if parameter type is float, double, long double. If dimension type is enum based then csv row is enum code and cell.DimIds is enum id.

func (CellExpr) IdToCodeCell

func (CellExpr) IdToCodeCell(
	modelDef *ModelMeta, name string,
) (
	func(interface{}) (interface{}, error), error)

IdToCodeCell return converter from output table cell of ids: (expr_id, dimensions enum ids, value) to cell of codes: (expr_id, dimensions as enum codes, value).

If dimension type is enum based then dimensions enum ids can be converted to enum code. If dimension type is simple (bool or int) then dimension value converted to string.

type CellParam

type CellParam struct {
	SubId int // parameter subvalue id
	// contains filtered or unexported fields
}

CellParam is value of input parameter.

func (CellParam) CsvFileName

func (CellParam) CsvFileName(modelDef *ModelMeta, name string, isIdCsv bool) (string, error)

CsvFileName return file name of csv file to store parameter rows

func (CellParam) CsvHeader

func (CellParam) CsvHeader(modelDef *ModelMeta, name string, isIdHeader bool, valueName string) ([]string, error)

CsvHeader retrun first line for csv file: column names, it's look like: sub_id,dim0,dim1,param_value.

func (CellParam) CsvToCell

func (CellParam) CsvToCell(
	modelDef *ModelMeta, name string, subCount int, valueName string,
) (
	func(row []string) (interface{}, error), error)

CsvToCell return closure to convert csv row []string to parameter cell (sub id, dimensions, value).

It does retrun error if len(row) not equal to number of fields in cell db-record. If dimension type is enum based then csv row is enum code and cell.DimIds is enum id. If parameter type is enum based then csv row value is enum code and cell value is enum id.

func (CellParam) CsvToIdRow

func (CellParam) CsvToIdRow(
	modelDef *ModelMeta, name string, doubleFmt string, valueName string,
) (
	func(interface{}, []string) error, error)

CsvToIdRow return converter from parameter cell (sub id, dimensions, value) to csv row []string.

Converter simply does Sprint() for each sub-value id, dimension item id and value. Converter will retrun error if len(row) not equal to number of fields in csv record. Double format string is used if parameter type is float, double, long double

func (CellParam) CsvToRow

func (CellParam) CsvToRow(
	modelDef *ModelMeta, name string, doubleFmt string, valueName string,
) (
	func(interface{}, []string) error, error)

CsvToRow return converter from parameter cell (sub id, dimensions, value) to csv row []string.

Converter will retrun error if len(row) not equal to number of fields in csv record. Double format string is used if parameter type is float, double, long double If dimension type is enum based then csv row is enum code and cell.DimIds is enum id. If parameter type is enum based then csv row value is enum code and cell value is enum id.

func (CellParam) IdToCodeCell

func (CellParam) IdToCodeCell(modelDef *ModelMeta, name string,
) (
	func(interface{}) (interface{}, error), error)

IdToCodeCell return converter from parameter cell of ids: (sub id, dimensions, value) to cell of codes: (sub id, dimensions as enum code, value)

If dimension type is enum based then dimensions enum ids can be converted to enum code. If dimension type is simple (bool or int) then dimension value converted to string. If parameter type is enum based then cell value enum id converted to enum code.

type CellToCodeConverter

type CellToCodeConverter interface {

	// IdToCodeCell return converter from id cell to code cell.
	// Cell is dimensions and value of parameter or output table.
	// It does convert from enum id to code for all dimensions and enum-based parameter value.
	IdToCodeCell(modelDef *ModelMeta, name string) (
		func(interface{}) (interface{}, error), error)
}

CellToCodeConverter provide methods to convert parameters or output table row from enum id to enum code. If dimension type is enum based then dimensions enum ids can be converted to enum code. If dimension type is simple (bool or int) then dimension value converted to string. If parameter type is enum based then cell value enum id converted to enum code.

type CellToIdConverter

type CellToIdConverter interface {

	// CodeToIdCell return converter from code cell to id cell.
	// Cell is dimensions and value of parameter or output table.
	// It does convert from enum code to id for all dimensions and enum-based parameter value.
	CodeToIdCell(modelDef *ModelMeta, name string) (
		func(interface{}) (interface{}, error), error)
}

CellToIdConverter provide methods to convert parameters or output table row from enum code to enum id. If dimension type is enum based then dimensions enum codes converted to enum ids. If dimension type is simple (bool or int) then dimension code converted from string to dimension type. If parameter type is enum based then cell value enum code converted to enum id.

type CsvConverter

type CsvConverter interface {
	// return file name of csv file to store parameter or output table rows
	CsvFileName(modelDef *ModelMeta, name string, isIdCsv bool) (string, error)

	// retrun first line of csv file with column names: expr_name,dim0,dim1,expr_value.
	// if isIdHeader is true: expr_id,dim0,dim1,expr_value
	// if isAllAcc is true: sub_id,dim0,dim1,acc0,acc1,acc2
	CsvHeader(modelDef *ModelMeta, name string, isIdHeader bool, valueName string) ([]string, error)

	// return converter from cell (dimensions and value) of parameter or output table to csv row []string.
	// it simply sprint() dimension id's and value into []string.
	CsvToIdRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (
		func(interface{}, []string) error, error)

	// return converter from cell (dimensions and value) of parameter or output table to csv row []string.
	// it does convert from enum id to code for all dimensions and enum-based parameter value.
	CsvToRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (
		func(interface{}, []string) error, error)

	// return converter from csv row []string to parameter or output table cell (dimensions and value)
	CsvToCell(modelDef *ModelMeta, name string, subCount int, valueName string) (
		func(row []string) (interface{}, error), error)
}

CsvConverter provide methods to convert parameters or output table data from or to row []string for csv file. Double format string is used for output bale values or if parameter type is float, double, long double. If dimension type is enum based then csv row is enum code and cell.DimIds is enum id. If parameter type is enum based then cell value is enum id and csv row value is enum code.

type DescrNote

type DescrNote struct {
	LangCode string // lang_code VARCHAR(32)  NOT NULL
	Descr    string // descr     VARCHAR(255) NOT NULL
	Note     string // note      VARCHAR(32000)
}

DescrNote is a holder for language code, descripriton and notes

type Facet

type Facet uint8

Facet is type to define database provider and driver facets, ie: name of bigint type

const (
	DefaultFacet Facet = iota // common default db facet
	SqliteFacet               // SQLite db facet
	PgSqlFacet                // PostgreSQL db facet
	MySqlFacet                // MySQL and MariaDB facet
	MsSqlFacet                // MS SQL db facet
	OracleFacet               // Oracle db facet
	Db2Facet                  // DB2 db facet
)

func Open

func Open(dbConnStr, dbDriver string, isFacetRequired bool) (*sql.DB, Facet, error)

Open database connection.

Default driver name: "SQLite" and connection string is compatible with model connection, ie:

Database=modelName.sqlite; Timeout=86400; OpenMode=ReadWrite;

Otherwise it is expected to be driver-specific connection string, ie:

DSN=ms2014; UID=sa; PWD=secret;
file:m1.sqlite?mode=rw&_busy_timeout=86400000

If isFacetRequired is true then database facet determined

func (Facet) String

func (facet Facet) String() string

String is default printable value of db facet, Stringer implementation

type FilterColumn

type FilterColumn struct {
	DimName string   // dimension name
	Op      FilterOp // filter operator: equal, IN, BETWEEN
	Enums   []string // enum code(s): one, two or many ids depending on filter condition
}

FilterColumn define dimension column and condition to filter enum codes to build select where

type FilterIdColumn

type FilterIdColumn struct {
	DimName string   // dimension name
	Op      FilterOp // filter operator: equal, IN, BETWEEN
	EnumIds []int    // enum id(s): one, two or many ids depending on filter condition
}

FilterIdColumn define dimension column and condition to filter enum ids to build select where

type FilterOp

type FilterOp string

FilterOp is enum type for filter operators in select where conditions

const (
	InAutoOpFilter  FilterOp = "IN_AUTO" // auto convert IN list filter into equal or BETWEEN if possible
	InOpFilter      FilterOp = "IN"      // dimension enum ids in: dim2 IN (11, 22, 33)
	EqOpFilter      FilterOp = "="       // dimension equal: dim1 = 12
	BetweenOpFilter FilterOp = "BETWEEN" // dimension enum ids between: dim3 BETWEEN 44 AND 88
)

Select filter operators for dimension enum ids.

type GroupLstRow

type GroupLstRow struct {
	ModelId  int    // model_id     INT          NOT NULL
	GroupId  int    // group_id     INT          NOT NULL
	IsParam  bool   // is_parameter SMALLINT     NOT NULL, -- if <> 0 then parameter group else output table group
	Name     string // group_name   VARCHAR(255) NOT NULL
	IsHidden bool   // is_hidden    SMALLINT     NOT NULL
}

GroupLstRow is db row of group_lst table

type GroupMeta

type GroupMeta struct {
	GroupLstRow              // parameters or output tables group rows: group_lst
	GroupPc     []GroupPcRow // group parent-child relationship rows: group_pc
}

GroupMeta is db rows to describe parent-child group of parameters or output tables, it is join of group_lst to group_pc

type GroupPcRow

type GroupPcRow struct {
	ModelId      int // model_id       INT NOT NULL
	GroupId      int // group_id       INT NOT NULL
	ChildPos     int // child_pos      INT NOT NULL
	ChildGroupId int // child_group_id INT NULL, -- if not NULL then id of child group
	ChildLeafId  int // leaf_id        INT NULL, -- if not NULL then id of parameter or output table
}

GroupPcRow is db row of group_pc table

type GroupTxtRow

type GroupTxtRow struct {
	ModelId   int // model_id  INT          NOT NULL
	GroupId   int // group_id  INT          NOT NULL
	DescrNote     // language, description, notes
}

GroupTxtRow is db row of group_txt table

type LangLstRow

type LangLstRow struct {
	LangCode string // lang_code VARCHAR(32)  NOT NULL
	Name     string // lang_name VARCHAR(255) NOT NULL
	// contains filtered or unexported fields
}

LangLstRow is db row of lang_lst table.

langId is db-unique id of the language. LangCode is unique language code: EN, FR.

type LangMeta

type LangMeta struct {
	Lang []langWord // languages and words in that language
	// contains filtered or unexported fields
}

LangMeta is language and words in that language

func GetLanguages

func GetLanguages(dbConn *sql.DB) (*LangMeta, error)

GetLanguages return language rows from lang_lst join to lang_word tables and map from lang_code to lang_id.

func (*LangMeta) Clone

func (src *LangMeta) Clone() (*LangMeta, error)

Clone return deep copy of source language metadata

func (*LangMeta) CodeById

func (langDef *LangMeta) CodeById(langId int) (string, bool)

CodeIdId return language code by language id or first language if id not found

func (*LangMeta) FromJson

func (dst *LangMeta) FromJson(srcJson []byte) (bool, error)

FromJson restore language list from json string bytes

func (*LangMeta) IdByCode

func (langDef *LangMeta) IdByCode(langCode string) (int, bool)

IdByCode return language id by language code or first language if code not found

type LangNote

type LangNote struct {
	LangCode string // lang_code VARCHAR(32)  NOT NULL
	Note     string // note      VARCHAR(32000)
}

LangNote is a holder for language code and notes

type ModelDicRow

type ModelDicRow struct {
	ModelId         int    // model_id         INT          NOT NULL
	Name            string // model_name       VARCHAR(255) NOT NULL
	Digest          string // model_digest     VARCHAR(32)  NOT NULL
	Type            int    // model_type       INT          NOT NULL
	Version         string // model_ver        VARCHAR(32)  NOT NULL
	CreateDateTime  string // create_dt        VARCHAR(32)  NOT NULL
	DefaultLangCode string // model default language code
}

ModelDicRow is db row of model_dic table.

ModelId (model_dic.model_id) is db-unique id of the model, use digest to find same model in other db.

func GetModelList

func GetModelList(dbConn *sql.DB) ([]ModelDicRow, error)

GetModelList return list of the models: model_dic table rows.

func GetModelRow added in v1.6.3

func GetModelRow(dbConn *sql.DB, modelId int) (*ModelDicRow, error)

GetModelRow return model_dic table row by model id.

type ModelMeta

type ModelMeta struct {
	Model ModelDicRow // model_dic table row
	Type  []TypeMeta  // types metadata: type name and enums
	Param []ParamMeta // parameters metadata: parameter name, type, dimensions
	Table []TableMeta // output tables metadata: table name, dimensions, accumulators, expressions
	Group []GroupMeta // groups of parameters or output tables
}

ModelMeta is model metadata db rows, language-neutral portion of it.

Types, parameters and output tables can be shared between different models and even between different databases. Use digest hash to find same type (parameter, table or model) in other database. As it is today language-specific part of model metadata (labels, description, notes, etc.) does not considered for "equality" comparison and not included in digest.

For example, logical type consists of 2 enum (code, value) pairs: [(0, "false") (1, "true")] and even it has different labels in different databases, i.e. (1, "Truth") vs (1, "OK") such type(s) considered the same and should have identical digest(s).

Inside of database *_hid (type_hid, parameter_hid, table_hid) is a unique id of corresponding object (primary key). Those _hid's are database-unique and should be used to find same type (parameter, output table) in other database. Also each type, parameter, output table have model-unique *_id (type_id, parameter_id, table_id) assigned by compiler and it is possible to find type, parameter or table by combination of (model_id, type_id).

Unless otherwise specified each array is ordered by model-specific id's and binary search can be used. For example type array is ordered by (model_id, type_id) and type enum array by (model_id, type_id, enum_id).

func GetModel

func GetModel(dbConn *sql.DB, name, digest string) (*ModelMeta, error)

GetModel return model metadata: parameters and output tables definition.

Model selected by name and/or digest, i.e.: ("modelOne", "abcd201208171604590148") if digest is empty then first model with min(model_id) is used

func GetModelById

func GetModelById(dbConn *sql.DB, modelId int) (*ModelMeta, error)

GetModelById return model metadata: parameters and output tables definition.

Model selected by model id, which expected to be positive.

func (*ModelMeta) Clone

func (src *ModelMeta) Clone() (*ModelMeta, error)

Clone return deep copy of source model metadata

func (*ModelMeta) FromJson

func (dst *ModelMeta) FromJson(srcJson []byte) (bool, error)

FromJson restore model metadata list from json string bytes

func (*ModelMeta) OutTableByDigest

func (meta *ModelMeta) OutTableByDigest(digest string) (int, bool)

OutTableByDigest return index of output table by digest

func (*ModelMeta) OutTableByHid

func (meta *ModelMeta) OutTableByHid(tableHid int) (int, bool)

OutTableByHid return index of output table by table Hid

func (*ModelMeta) OutTableByKey

func (meta *ModelMeta) OutTableByKey(tableId int) (int, bool)

OutTableByKey return index of output table by key: tableId

func (*ModelMeta) OutTableByName

func (meta *ModelMeta) OutTableByName(name string) (int, bool)

OutTableByName return index of output table by name

func (*ModelMeta) OutTableHidById

func (meta *ModelMeta) OutTableHidById(tableId int) int

OutTableHidById return output table Hid by id or -1 if not found

func (*ModelMeta) OutTableIdByHid

func (meta *ModelMeta) OutTableIdByHid(tableHid int) int

OutTableIdByHid return output table id by Hid or -1 if not found

func (*ModelMeta) ParamByDigest

func (meta *ModelMeta) ParamByDigest(digest string) (int, bool)

ParamByDigest return index of parameter by parameter digest

func (*ModelMeta) ParamByHid

func (meta *ModelMeta) ParamByHid(paramHid int) (int, bool)

ParamByHid return index of parameter by parameter Hid

func (*ModelMeta) ParamByKey

func (meta *ModelMeta) ParamByKey(paramId int) (int, bool)

ParamByKey return index of parameter by key: paramId

func (*ModelMeta) ParamByName

func (meta *ModelMeta) ParamByName(name string) (int, bool)

ParamByName return index of parameter by name

func (*ModelMeta) ParamHidById

func (meta *ModelMeta) ParamHidById(paramId int) int

ParamHidById return parameter Hid by id or -1 if not found

func (*ModelMeta) ParamIdByHid

func (meta *ModelMeta) ParamIdByHid(paramHid int) int

ParamIdByHid return parameter id by Hid or -1 if not found

func (*ModelMeta) TypeByKey

func (meta *ModelMeta) TypeByKey(typeId int) (int, bool)

TypeByKey return index of type by key: typeId

type ModelTxtMeta

type ModelTxtMeta struct {
	ModelName    string            // model name for text metadata
	ModelDigest  string            // model digest for text metadata
	ModelTxt     []ModelTxtRow     // model text rows: model_dic_txt
	TypeTxt      []TypeTxtRow      // model type text rows: type_dic_txt join to model_type_dic
	TypeEnumTxt  []TypeEnumTxtRow  // type enum text rows: type_enum_txt join to model_type_dic
	ParamTxt     []ParamTxtRow     // model parameter text rows: parameter_dic_txt join to model_parameter_dic
	ParamDimsTxt []ParamDimsTxtRow // parameter dimension text rows: parameter_dims_txt join to model_parameter_dic
	TableTxt     []TableTxtRow     // model output table text rows: table_dic_txt join to model_table_dic
	TableDimsTxt []TableDimsTxtRow // output table dimension text rows: table_dims_txt join to model_table_dic
	TableAccTxt  []TableAccTxtRow  // output table accumulator text rows: table_acc_txt join to model_table_dic
	TableExprTxt []TableExprTxtRow // output table expression text rows: table_expr_txt join to model_table_dic
	GroupTxt     []GroupTxtRow     // group text rows: group_txt
}

ModelTxtMeta is language-specific portion of model metadata db rows.

func GetModelText

func GetModelText(dbConn *sql.DB, modelId int, langCode string) (*ModelTxtMeta, error)

GetModelText return model text metadata: description and notes. If langCode not empty then only specified language selected else all languages.

type ModelTxtRow

type ModelTxtRow struct {
	ModelId  int    // model_id     INT          NOT NULL
	LangCode string // lang_code    VARCHAR(32)  NOT NULL
	Descr    string // descr        VARCHAR(255) NOT NULL
	Note     string // note         VARCHAR(32000)
}

ModelTxtRow is db row of model_dic_txt join to model_dic

func GetModelTextById

func GetModelTextById(dbConn *sql.DB, modelId int, langCode string) ([]ModelTxtRow, error)

GetModelTextById return model_dic_txt table rows by model id.

If langCode not empty then only specified language selected else all languages.

type ModelWordMeta

type ModelWordMeta struct {
	ModelName   string          // model name for text metadata
	ModelDigest string          // model digest for text metadata
	ModelWord   []modelLangWord // language and db rows of model_word in that language
}

ModelWordMeta is language-specific model_word db rows.

func GetModelWord

func GetModelWord(dbConn *sql.DB, modelId int, langCode string) (*ModelWordMeta, error)

GetModelWord return model "words": language-specific stirngs. If langCode not empty then only specified language selected else all languages.

type OrderByColumn

type OrderByColumn struct {
	IndexOne int  // one-based column index
	IsDesc   bool // if true then descending order
}

OrderByColumn define column to order by rows selected from parameter or output table.

type ParamDicRow

type ParamDicRow struct {
	ModelId      int    // model_id           INT          NOT NULL
	ParamId      int    // model_parameter_id INT          NOT NULL
	ParamHid     int    // parameter_hid      INT          NOT NULL, -- unique parameter id
	Name         string // parameter_name     VARCHAR(255) NOT NULL
	Digest       string // parameter_digest   VARCHAR(32)  NOT NULL
	Rank         int    // parameter_rank     INT          NOT NULL
	TypeId       int    // model_type_id      INT          NOT NULL
	IsExtendable bool   // is_extendable      SMALLINT     NOT NULL
	IsHidden     bool   // is_hidden          SMALLINT     NOT NULL
	NumCumulated int    // num_cumulated      INT          NOT NULL
	DbRunTable   string // db_run_table       VARCHAR(64)  NOT NULL
	DbSetTable   string // db_set_table       VARCHAR(64)  NOT NULL
	ImportDigest string // import_digest      VARCHAR(32)  NOT NULL
}

ParamDicRow is db row of parameter_dic join to model_parameter_dic table

ParamHid (parameter_dic.parameter_hid) is db-unique id of the parameter, use digest to find same parameter in other db. ParamId (model_parameter_dic.model_parameter_id) is model-unique parameter id, assigned by model compiler.

type ParamDimsRow

type ParamDimsRow struct {
	ModelId int    // model_id           INT        NOT NULL
	ParamId int    // model_parameter_id INT        NOT NULL
	DimId   int    // dim_id             INT        NOT NULL
	Name    string // dim_name           VARCHAR(8) NOT NULL
	TypeId  int    // model_type_id      INT        NOT NULL
	// contains filtered or unexported fields
}

ParamDimsRow is db row of parameter_dims join to model_parameter_dic table

type ParamDimsTxtRow

type ParamDimsTxtRow struct {
	ModelId  int    // model_id           INT          NOT NULL
	ParamId  int    // model_parameter_id INT          NOT NULL
	DimId    int    // dim_id             INT          NOT NULL
	LangCode string // lang_code          VARCHAR(32)  NOT NULL
	Descr    string // descr              VARCHAR(255) NOT NULL
	Note     string // note               VARCHAR(32000)
}

ParamDimsTxtRow is db row of parameter_dims_txt join to model_parameter_dic table

type ParamImportRow

type ParamImportRow struct {
	ModelId     int    // model_id           INT          NOT NULL
	ParamId     int    // model_parameter_id INT          NOT NULL
	FromName    string // from_name          VARCHAR(255) NOT NULL
	FromModel   string // from_model_name    VARCHAR(255) NOT NULL
	IsSampleDim bool   // is_sample_dim      SMALLINT     NOT NULL
}

ParamImportRow is db row of model_parameter_import table

type ParamMeta

type ParamMeta struct {
	ParamDicRow                  // model parameter row: parameter_dic join to model_parameter_dic table
	Dim         []ParamDimsRow   // parameter dimension rows: parameter_dims join to model_parameter_dic table
	Import      []ParamImportRow // parameter import from upstream model
	// contains filtered or unexported fields
}

ParamMeta is parameter metadata: parameter name, type, dimensions

func (*ParamMeta) DimByKey

func (param *ParamMeta) DimByKey(dimId int) (int, bool)

DimByKey return index of parameter dimension by key: dimId

type ParamRunSetPub

type ParamRunSetPub struct {
	Name         string     // parameter name
	SubCount     int        // number of parameter sub-values
	DefaultSubId int        // default sub-value id for that parameter workset
	Txt          []LangNote // parameter value notes by language
}

ParamRunSetPub is "public" run or workset parameter metadata for json import-export

type ParamTxtRow

type ParamTxtRow struct {
	ModelId  int    // model_id           INT          NOT NULL
	ParamId  int    // model_parameter_id INT          NOT NULL
	LangCode string // lang_code          VARCHAR(32)  NOT NULL
	Descr    string // descr              VARCHAR(255) NOT NULL
	Note     string // note               VARCHAR(32000)
}

ParamTxtRow is db row of parameter_dic_txt join to model_parameter_dic table

type ParamValuePub

type ParamValuePub struct {
	ParamRunSetPub                 // parameter metadata
	Value          []CellCodeParam // parameter value(s)
}

ParamValuePub is "public" run or workset parameter metadata and values for json import-export.

type ProfileMeta

type ProfileMeta struct {
	Name string            // profile name
	Opts map[string]string // profile (key, value) options
}

ProfileMeta is rows from profile_option table.

Profile is a named group of (key, value) options, similar to ini-file. Default model options has profile_name = model_name.

func GetProfile

func GetProfile(dbConn *sql.DB, name string) (*ProfileMeta, error)

GetProfile return profile_option table rows as (key, value) map.

Profile is a named group of (key, value) options, similar to ini-file. Default model options has profile_name = model_name.

type ReadLayout

type ReadLayout struct {
	Name           string           // parameter name or output table name
	FromId         int              // run id or set id to select input parameter or output table values
	ReadPageLayout                  // read page first row offset, size and last page flag
	Filter         []FilterColumn   // dimension filters, final WHERE does join all filters by AND
	FilterById     []FilterIdColumn // dimension filters by enum ids, final WHERE does join filters by AND
	OrderBy        []OrderByColumn  // order by columnns, if empty then dimension id ascending order is used
}

ReadLayout describes source and size of data page to read input parameter or output table values.

If IsLastPage true then return non-empty last page and actual first row offset and size.

Row filters combined by AND and allow to select dimension items, it can be enum codes or enum id's, ex.: dim0 = 'CA' AND dim1 IN (2010, 2011, 2012)

Order by applied to output columns, dimension columns always contain enum id's, therefore result ordered by id's and not by enum codes. Columns list depending on output table or parameter query:

parameter values:

SELECT sub_id, dim0, dim1, param_value FROM parameterTable ORDER BY...

output table expressions:

SELECT expr_id, dim0, dim1, expr_value FROM outputTable ORDER BY...

output table accumulators:

SELECT acc_id, sub_id, dim0, dim1, acc_value FROM outputTable ORDER BY...

all-accumulators view:

SELECT sub_id, dim0, dim1, acc0_value, acc1_value... FROM outputTable ORDER BY...

type ReadPageLayout

type ReadPageLayout struct {
	Offset     int64 // first row to return from select, zero-based ofsset
	Size       int64 // max row count to select, if <= 0 then all rows
	IsLastPage bool  // if true then return non-empty last page
}

ReadPageLayout describes first row offset and size of data page to read input parameter or output table values. If IsLastPage true then return non-empty last page and actual first row offset and size.

func ReadOutputTable

func ReadOutputTable(dbConn *sql.DB, modelDef *ModelMeta, layout *ReadTableLayout) (*list.List, *ReadPageLayout, error)

ReadOutputTable read ouput table page (dimensions and values) from model run results.

If layout.IsAccum true then select accumulator(s) else output expression value(s) If layout.ValueName not empty then select only that expression (accumulator) else all expressions (accumulators)

func ReadParameter

func ReadParameter(dbConn *sql.DB, modelDef *ModelMeta, layout *ReadParamLayout) (*list.List, *ReadPageLayout, error)

ReadParameter read input parameter page (sub id, dimensions, value) from workset or model run results.

func SelectToList

func SelectToList(
	dbConn *sql.DB, query string, layout ReadPageLayout, cvt func(rows *sql.Rows) (interface{}, error)) (*list.List, *ReadPageLayout, error)

SelectToList select db rows into list using cvt to convert (scan) each db row into struct.

It selects "page size" number of rows starting from row number == offset (zero based). If page size <= 0 then all rows returned.

type ReadParamLayout

type ReadParamLayout struct {
	ReadLayout      // parameter name, page size, where filters and order by
	IsFromSet  bool // if true then select from workset else from model run
	IsEditSet  bool // if true then workset must be editable (readonly = false)
}

ReadParamLayout describes source and size of data page to read input parameter values.

It can read parameter values from model run results or from input working set (workset). If this is read from workset then it can be read-only or read-write (editable) workset.

type ReadTableCompareLayout added in v1.8.4

type ReadTableCompareLayout struct {
	ReadTableLayout      // output table name, page size of rows to select, where filters and order by
	IsDiff          bool // if true then also select difference: current run value - base run value
	IsRatio         bool // if true then also select ratio: current run value / base run value
	// contains filtered or unexported fields
}

ReadTableCompareLayout describes source and size of data page to read output table values from multiple runs.

Result is a page of data where each row contains base run value, current run value and optional difference and ratio. Columns list depending on output table or parameter query:

output table expressions from multiple runs:

SELECT
  M.run_id, C.run_id, M.expr_id, M.dim0, M.dim1,
  M.expr_value,
  C.expr_value,
  C.expr_value - M.expr_value AS "diff",
  C.expr_value / CASE WHEN ABS(M.expr_value) > 1.0e-37 THEN M.expr_value ELSE NULL END AS "ratio"
FROM outputTable M
INNER JOIN outputTable C ON (M.expr_id = C.expr_id AND M.dim0 = C.dim0 AND M.dim1 = C.dim1)
WHERE M.run_id = 123 AND C.run_id = 456
AND ....filter by dimensions....
ORDER BY...

output table accumulators from multiple runs:

SELECT
  M.run_id, C.run_id, M.acc_id, M.sub_id, M.dim0, M.dim1,
  M.acc_value,
  C.acc_value,
  C.acc_value - M.acc_value AS "diff",
  C.acc_value / CASE WHEN ABS(M.acc_value) > 1.0e-37 THEN M.acc_value ELSE NULL END AS "ratio"
FROM outputTable M
INNER JOIN outputTable C ON (M.acc_id = C.acc_id AND M.sub_id = C.sub_id AND M.dim0 = C.dim0 AND M.dim1 = C.dim1)
WHERE M.run_id = 123 AND C.run_id = 456
AND ....filter by dimensions....
ORDER BY...

type ReadTableLayout

type ReadTableLayout struct {
	ReadLayout        // output table name, page size, where filters and order by
	ValueName  string // if not empty then expression or accumulator name to select
	IsAccum    bool   // if true then select output table accumulator else expression
	IsAllAccum bool   // if true then select from all accumulators view else from accumulators table
}

ReadTableLayout describes source and size of data page to read output table values.

If ValueName is not empty then only accumulator or output expression with that name selected (i.e: "acc1" or "expr4") else all output table accumulators (expressions) selected.

type RunMeta

type RunMeta struct {
	Run      RunRow            // model run master row: run_lst
	Txt      []RunTxtRow       // run text rows: run_txt
	Opts     map[string]string // options used to run the model: run_option
	Param    []runParam        // run parameters: parameter_hid, sub-value count, run_parameter_txt table rows
	Table    []runTable        // run tables: table_hid fom run_table rows
	Progress []RunProgress     // run progress by sub-values: run_progress table rows
}

RunMeta is metadata of model run: name, status, run options, description, notes.

func GetRunFull

func GetRunFull(dbConn *sql.DB, runRow *RunRow) (*RunMeta, error)

GetRunFull return full metadata for completed model run: run_lst, run_option, run_parameter, run_table, run_progress rows.

func GetRunFullText

func GetRunFullText(dbConn *sql.DB, runRow *RunRow, langCode string) (*RunMeta, error)

GetRunFullText return full metadata, including text, for completed model run: run_lst, run_txt, run_option, run_parameter, run_parameter_txt, run_table, run_progress rows.

It does not return non-completed runs (run in progress). If langCode not empty then only specified language selected else all languages

func GetRunFullTextList

func GetRunFullTextList(dbConn *sql.DB, modelId int, isSuccess bool, langCode string) ([]RunMeta, error)

GetRunFullTextList return list of full metadata, including text, for completed model runs: run_lst, run_txt, run_option, run_parameter, run_parameter_txt, run_table, run_progress rows.

If isSuccess true then return only successfully completed runs else all completed runs. It does not return non-completed runs (run in progress). If langCode not empty then only specified language selected else all languages

func (*RunMeta) ToPublic

func (meta *RunMeta) ToPublic(dbConn *sql.DB, modelDef *ModelMeta) (*RunPub, error)

ToPublic convert model run db rows into "public" model run format for json import-export.

func (*RunMeta) UpdateRun

func (meta *RunMeta) UpdateRun(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta, doubleFmt string) (bool, error)

UpdateRun insert new or return existing model run metadata in database.

Run status must be completed (success, exit or error) otherwise error returned. If this run already exist then nothing is updated in database, only metadata updated with actual run id. Run digest is used to find existing model run, it cannot be empty "" string otherwise error returned.

Double format is used for progress value float conversion, if non-empty format supplied.

It return "is found" flag and update metadata with actual run id in database.

func (*RunMeta) UpdateRunText

func (meta *RunMeta) UpdateRunText(dbConn *sql.DB, modelDef *ModelMeta, runId int, langDef *LangMeta) error

UpdateRunText merge run text (run description and notes) and run parameter notes into run_txt and run_parameter_txt tables.

New run text merged with existing db rows by update or insert if rows not exist db tables. If run not exist then function does nothing. Run status must be completed (success, exit or error) otherwise error returned. Run id of the input run metadata updated with runId value.

type RunParamTxtRow

type RunParamTxtRow struct {
	RunId    int    // run_id        INT         NOT NULL
	ParamHid int    // parameter_hid INT         NOT NULL
	LangCode string // lang_code     VARCHAR(32) NOT NULL
	Note     string // note          VARCHAR(32000)
}

RunParamTxtRow is db row of run_parameter_txt

func GetRunAllParamText

func GetRunAllParamText(dbConn *sql.DB, runId int, langCode string) ([]RunParamTxtRow, error)

GetRunAllParamText return all run parameters value notes: run_parameter_txt table rows.

If langCode not empty then only specified language selected else all languages

func GetRunParamText

func GetRunParamText(dbConn *sql.DB, runId int, paramHid int, langCode string) ([]RunParamTxtRow, error)

GetRunParamText return run parameter value notes: run_parameter_txt table rows.

If langCode not empty then only specified language selected else all languages

type RunProgress

type RunProgress struct {
	SubId          int     // sub_id         INT         NOT NULL, -- sub-value id (zero based index)
	CreateDateTime string  // create_dt      VARCHAR(32) NOT NULL, -- start date-time
	Status         string  // status         VARCHAR(1)  NOT NULL, -- run status: i=init p=progress s=success x=exit e=error(failed)
	UpdateDateTime string  // update_dt      VARCHAR(32) NOT NULL, -- last update date-time
	Count          int     // progress_count INT         NOT NULL, -- progress count: percent completed
	Value          float64 // progress_value FLOAT       NOT NULL, -- progress value: number of cases (case based) or time (time based)
}

RunProgress is a "public" sub-value run_progress db row

func GetRunProgress

func GetRunProgress(dbConn *sql.DB, runId int) ([]RunProgress, error)

GetRunProgress return sub-values run progress for specified run id: run_progress table rows.

type RunPub

type RunPub struct {
	ModelName      string            // model name for that run
	ModelDigest    string            // model digest for that run
	Name           string            // run_name      VARCHAR(255) NOT NULL
	SubCount       int               // sub_count     INT          NOT NULL, -- subvalue count
	SubStarted     int               // sub_started   INT          NOT NULL, -- number of subvalues started
	SubCompleted   int               // sub_completed INT          NOT NULL, -- number of subvalues completed
	CreateDateTime string            // create_dt     VARCHAR(32)  NOT NULL, -- start date-time
	Status         string            // status        VARCHAR(1)   NOT NULL, -- run status: i=init p=progress s=success x=exit e=error(failed)
	UpdateDateTime string            // update_dt     VARCHAR(32)  NOT NULL, -- last update date-time
	RunDigest      string            // run_digest    VARCHAR(32)  NULL,     -- digest of the run metadata: model digest, run name, sub count, created date-time, run stamp
	ValueDigest    string            // value_digest  VARCHAR(32),           -- if not NULL then digest of the run values: all parameters and output tables
	RunStamp       string            // run_stamp     VARCHAR(32)  NOT NULL, -- process run stamp, by default is log time stamp
	Txt            []DescrNote       // run text: description and notes by language
	Opts           map[string]string // options used to run the model: run_option
	Param          []ParamRunSetPub  // run parameters: name, sub-value count and value notes by language
	Table          []TableRunPub     // run tables: name for tables included in run_table
	Progress       []RunProgress     // run progress by sub-values: run_progress table rows
}

RunPub is "public" model run metadata for json import-export

func (*RunPub) FromPublic

func (pub *RunPub) FromPublic(dbConn *sql.DB, modelDef *ModelMeta) (*RunMeta, error)

FromPublic convert model run metadata from "public" format (coming from json import-export) into db rows.

type RunRow

type RunRow struct {
	RunId          int    // run_id        INT          NOT NULL, -- unique run id
	ModelId        int    // model_id      INT          NOT NULL
	Name           string // run_name      VARCHAR(255) NOT NULL, -- model run name
	SubCount       int    // sub_count     INT          NOT NULL, -- subvalue count
	SubStarted     int    // sub_started   INT          NOT NULL, -- number of subvalues started
	SubCompleted   int    // sub_completed INT          NOT NULL, -- number of subvalues completed
	CreateDateTime string // create_dt     VARCHAR(32)  NOT NULL, -- start date-time
	Status         string // status        VARCHAR(1)   NOT NULL, -- run status: i=init p=progress s=success x=exit e=error(failed)
	UpdateDateTime string // update_dt     VARCHAR(32)  NOT NULL, -- last update date-time
	RunDigest      string // run_digest    VARCHAR(32)  NULL,     -- digest of the run metadata: model digest, run name, sub count, created date-time, run stamp
	ValueDigest    string // value_digest  VARCHAR(32),           -- if not NULL then digest of the run values: all parameters and output tables
	RunStamp       string // run_stamp     VARCHAR(32)  NOT NULL, -- process run stamp, by default is log time stamp
}

RunRow is model run row: run_lst table row.

Run status: i=init p=progress s=success x=exit e=error(failed). Run id must be different from working set id (use id_lst to get it)

func GetFirstRun

func GetFirstRun(dbConn *sql.DB, modelId int) (*RunRow, error)

GetFirstRun return first run of the model: run_lst table row.

func GetLastCompletedRun

func GetLastCompletedRun(dbConn *sql.DB, modelId int) (*RunRow, error)

GetLastCompletedRun return last completed run of the model: run_lst table row.

Run completed if run status one of: s=success, x=exit, e=error

func GetLastRun

func GetLastRun(dbConn *sql.DB, modelId int) (*RunRow, error)

GetLastRun return last run of the model: run_lst table row.

func GetLastRunByName added in v1.6.3

func GetLastRunByName(dbConn *sql.DB, modelId int, name string) (*RunRow, error)

GetLastRunByName return model run row by run name: run_lst table row.

If there is multiple runs with this name then run with max(run_id) returned

func GetRun

func GetRun(dbConn *sql.DB, runId int) (*RunRow, error)

GetRun return model run row by id: run_lst table row.

func GetRunByDigest

func GetRunByDigest(dbConn *sql.DB, digest string) (*RunRow, error)

GetRunByDigest return model run row by digest: run_lst table row.

func GetRunByDigestOrStampOrName

func GetRunByDigestOrStampOrName(dbConn *sql.DB, modelId int, rdsn string) (*RunRow, error)

GetRunByDigestOrStampOrName return model run row by run digest or run stamp or run name: run_lst table row.

It does select run row by digest, if not found then by model id and stamp, if not found by model id and run name. If there is multiple runs with this stamp or name then run with min(run_id) returned

func GetRunByName

func GetRunByName(dbConn *sql.DB, modelId int, name string) (*RunRow, error)

GetRunByName return model run row by run name: run_lst table row.

If there is multiple runs with this name then run with min(run_id) returned

func GetRunByStamp

func GetRunByStamp(dbConn *sql.DB, modelId int, stamp string) (*RunRow, error)

GetRunByStamp return model run row by run stamp: run_lst table row.

If there is multiple runs with this stamp then run with min(run_id) returned

func GetRunList

func GetRunList(dbConn *sql.DB, modelId int, afterRunId int) ([]RunRow, error)

GetRunList return list of model runs by model_id: run_lst rows.

If afterRunId > 0 then return only runs where run_id > afterRunId

func GetRunListByDigestOrStampOrName

func GetRunListByDigestOrStampOrName(dbConn *sql.DB, modelId int, rdsn string) ([]RunRow, error)

GetRunListByDigestOrStampOrName return list of model run rows by run digest or run stamp or run name: run_lst table rows.

It does select run row by digest, if not found then by model id and stamp, if not found by model id and run name. If there is multiple runs with this stamp or name then multiple rows returned

type RunTxtRow

type RunTxtRow struct {
	RunId    int    // run_id    INT          NOT NULL
	LangCode string // lang_code VARCHAR(32)  NOT NULL
	Descr    string // descr     VARCHAR(255) NOT NULL
	Note     string // note      VARCHAR(32000)
}

RunTxtRow is db row of run_txt

func GetRunText

func GetRunText(dbConn *sql.DB, runId int, langCode string) ([]RunTxtRow, error)

GetRunText return model run description and notes: run_txt table rows.

If langCode not empty then only specified language selected else all languages

type TableAccRow

type TableAccRow struct {
	ModelId   int    // model_id       INT          NOT NULL
	TableId   int    // model_table_id INT          NOT NULL
	AccId     int    // acc_id         INT          NOT NULL
	Name      string // acc_name       VARCHAR(8)   NOT NULL
	IsDerived bool   // is_derived     SMALLINT     NOT NULL
	SrcAcc    string // acc_src        VARCHAR(255)  NOT NULL
	AccSql    string // acc_sql        VARCHAR(2048) NOT NULL
}

TableAccRow is db row of table_acc join to model_table_dic table

type TableAccTxtRow

type TableAccTxtRow struct {
	ModelId  int    // model_id       INT          NOT NULL
	TableId  int    // model_table_id INT          NOT NULL
	AccId    int    // acc_id         INT          NOT NULL
	LangCode string // lang_code      VARCHAR(32)  NOT NULL
	Descr    string // descr          VARCHAR(255) NOT NULL
	Note     string // note           VARCHAR(32000)
}

TableAccTxtRow is db row of table_acc_txt join to model_table_dic table

type TableDicRow

type TableDicRow struct {
	ModelId      int    // model_id        INT          NOT NULL
	TableId      int    // model_table_id  INT          NOT NULL
	TableHid     int    // table_hid       INT          NOT NULL, -- unique table id
	Name         string // table_name      VARCHAR(255) NOT NULL
	Digest       string // table_digest    VARCHAR(32)  NOT NULL
	IsUser       bool   // is_user         SMALLINT     NOT NULL
	Rank         int    // table_rank      INT          NOT NULL
	IsSparse     bool   // is_sparse       SMALLINT     NOT NULL
	DbExprTable  string // db_expr_table   VARCHAR(64)  NOT NULL
	DbAccTable   string // db_acc_table    VARCHAR(64)  NOT NULL
	DbAccAllView string // db_acc_all_view VARCHAR(64)  NOT NULL
	ExprPos      int    // expr_dim_pos    INT          NOT NULL
	IsHidden     bool   // is_hidden       SMALLINT     NOT NULL
	ImportDigest string // import_digest   VARCHAR(32)  NOT NULL
}

TableDicRow is db row of table_dic join to model_table_dic table.

TableHid (table_dic.table_hid) is db-unique id of the output table, use digest to find same table in other db. TableId (model_table_dic.model_table_id) is model-unique output table id, assigned by model compiler.

type TableDimsRow

type TableDimsRow struct {
	ModelId int    // model_id       INT        NOT NULL
	TableId int    // model_table_id INT        NOT NULL
	DimId   int    // dim_id         INT        NOT NULL
	Name    string // dim_name       VARCHAR(8) NOT NULL
	TypeId  int    // model_type_id  INT        NOT NULL
	IsTotal bool   // is_total       SMALLINT   NOT NULL
	DimSize int    // dim_size       INT        NOT NULL
	// contains filtered or unexported fields
}

TableDimsRow is db row of table_dims join to model_table_dic table

type TableDimsTxtRow

type TableDimsTxtRow struct {
	ModelId  int    // model_id       INT          NOT NULL
	TableId  int    // model_table_id INT          NOT NULL
	DimId    int    // dim_id         INT          NOT NULL
	LangCode string // lang_code      VARCHAR(32)  NOT NULL
	Descr    string // descr          VARCHAR(255) NOT NULL
	Note     string // note           VARCHAR(32000)
}

TableDimsTxtRow is db row of table_dims_txt join to model_table_dic table

type TableExprRow

type TableExprRow struct {
	ModelId  int    // model_id       INT           NOT NULL
	TableId  int    // model_table_id INT           NOT NULL
	ExprId   int    // expr_id        INT           NOT NULL
	Name     string // expr_name      VARCHAR(8)    NOT NULL
	Decimals int    // expr_decimals  INT           NOT NULL
	SrcExpr  string // expr_src       VARCHAR(255)  NOT NULL
	ExprSql  string // expr_sql       VARCHAR(2048) NOT NULL
}

TableExprRow is db row of table_expr join to model_table_dic table

type TableExprTxtRow

type TableExprTxtRow struct {
	ModelId  int    // model_id       INT          NOT NULL
	TableId  int    // model_table_id INT          NOT NULL
	ExprId   int    // expr_id        INT           NOT NULL
	LangCode string // lang_code      VARCHAR(32)  NOT NULL
	Descr    string // descr          VARCHAR(255) NOT NULL
	Note     string // note           VARCHAR(32000)
}

TableExprTxtRow is db row of table_expr_txt join to model_table_dic table

type TableMeta

type TableMeta struct {
	TableDicRow                // model output table row: table_dic join to model_table_dic
	Dim         []TableDimsRow // output table dimension rows: table_dims join to model_table_dic
	Acc         []TableAccRow  // output table accumulator rows: table_acc join to model_table_dic
	Expr        []TableExprRow // output table expression rows: table_expr join to model_table_dic
	// contains filtered or unexported fields
}

TableMeta is output table metadata: table name, dimensions, accumulators, expressions

func (*TableMeta) DimByKey

func (table *TableMeta) DimByKey(dimId int) (int, bool)

DimByKey return index of output table dimension by key: dimId

type TableRunPub added in v1.8.4

type TableRunPub struct {
	Name string // parameter name
}

TableRunPub is "public" metadata for output tables included in model run results

type TableRunsCompareLayout added in v1.8.5

type TableRunsCompareLayout struct {
	TableLayout ReadTableCompareLayout // output table name, page size, where filters and order by
	RunTags     []string               // model runs to compare with base run: run digests or run stamps or run names
	Task        struct {
		Name   string // task name to select model runs for comparison
		RunTag string // task run name or task run stamp to select model runs for comparison
	}
}

TableRunsCompareLayout describes source and size of data page to read output table values from multiple runs.

Result is a page of data where each row contains base run value, current run value and optional difference and ratio.

Runs to compare are selected either task_run_set table or from run_lst table. Select from task_run_set table is done by task name and task run name or stamp. Select from run_lst table is done by RunTags[] elements, which are run digests, or run stamps or run names. Content of RunTags[] must be uniform, all elements must be of the same kind: run digest or run stamp or run name, it cannot be a mix of digests, stamps, names.

type TableTxtRow

type TableTxtRow struct {
	ModelId   int    // model_id       INT          NOT NULL
	TableId   int    // model_table_id INT          NOT NULL
	LangCode  string // lang_code      VARCHAR(32)  NOT NULL
	Descr     string // descr          VARCHAR(255) NOT NULL
	Note      string // note           VARCHAR(32000)
	ExprDescr string // expr_descr     VARCHAR(255) NOT NULL
	ExprNote  string // expr_note      VARCHAR(32000)
}

TableTxtRow is db row of table_dic_txt join to model_table_dic table

type TaskDef

type TaskDef struct {
	Task TaskRow      // modeling task row: task_lst
	Txt  []TaskTxtRow // task text rows: task_txt
	Set  []int        // task body (current list of workset id's): task_set
}

TaskDef is modeling task definition: metadata and input worksets

type TaskDefPub

type TaskDefPub struct {
	ModelName   string      // model name for that task list
	ModelDigest string      // model digest for that task list
	Name        string      // task_name    VARCHAR(255) NOT NULL
	Txt         []DescrNote // task text: description and notes by language
	Set         []string    // task body: list of workset names
}

TaskDefPub is "public" modeling task metadata and task input worksets for json import-export

type TaskMeta

type TaskMeta struct {
	TaskDef               // task definition: metadata and input worksets
	TaskRun []taskRunItem // task run history: task_run_lst and task_run_set rows
}

TaskMeta is metadata for modeling task: name, status, description, notes, task run history.

Modeling task is a named set of input model inputs (of workset ids) to run the model. Typical use case: create multiple input sets by varying some model parameters, combine it under named "task" and run the model with that task name. As result multiple model "runs" created ("run" is input and output data of model run). Such run of model called "task run" and allow to study dependencies between model input and output.

Task can be edited by user: new input workset ids added or some workset id(s) excluded. As result current task body (workset ids of the task) may be different from older version of it: task_set set_id's may not be same as task_run_set set_id's. TaskRun and TaskRunSet is a history and result of that task run, but there is no guarantee of any workset in task history still exist or contain same input parameter values as it was at the time of task run. To find actual input for any particular model run and/or task run we must use run_id.

func GetTaskFull

func GetTaskFull(dbConn *sql.DB, taskRow *TaskRow, langCode string) (*TaskMeta, error)

GetTaskFull return modeling task metadata, description, notes and run history from db-tables: task_lst, task_txt, task_set, task_run_lst, task_run_set.

It does not return non-completed task runs (run in progress). If langCode not empty then only specified language selected else all languages

func GetTaskFullList

func GetTaskFullList(dbConn *sql.DB, modelId int, isSuccess bool, langCode string) ([]TaskMeta, error)

GetTaskFullList return list of modeling tasks metadata, description, notes and run history from db-tables: task_lst, task_txt, task_set, task_run_lst, task_run_set.

If isSuccess true then return only successfully completed task runs else all completed runs. It does not return non-completed task runs (run in progress). If langCode not empty then only specified language selected else all languages

func GetTaskRunList

func GetTaskRunList(dbConn *sql.DB, taskRow *TaskRow) (*TaskMeta, error)

GetTaskRunList return model run history: master row from task_lst and all rows from task_run_lst, task_run_set where task run is completed.

It does not return non-completed task runs (run in progress). Task run completed if run status one of: s=success, x=exit, e=error

func (*TaskMeta) MergeTaskDef

func (meta *TaskMeta) MergeTaskDef(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta) error

MergeTaskDef update existing and insert new modeling task definition: task metadata and task input worksets.

It does replace: task_txt and task_set db rows. It does not change anything in task run history: task_run_lst and task_run_set tables. If task not exist then new task created. Task input worksets (new content of task_set table) must exist in workset_lst.set_id. Model id and task id updated with actual database id's.

func (*TaskMeta) ReplaceTaskDef

func (meta *TaskMeta) ReplaceTaskDef(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta) error

ReplaceTaskDef delete existing and insert new modeling task definition: task metadata and task input worksets.

It does replace: task_txt and task_set db rows. It does not change anything in task run history: task_run_lst and task_run_set tables. If task not exist then new task created. Task input worksets (new content of task_set table) must exist in workset_lst.set_id. Model id and task id updated with actual database id's.

func (*TaskMeta) ToPublic

func (meta *TaskMeta) ToPublic(dbConn *sql.DB, modelDef *ModelMeta) (*TaskPub, error)

ToPublic convert modeling task metadata db rows into "public" modeling task format for json import-export.

func (*TaskMeta) UpdateTaskFull

func (meta *TaskMeta) UpdateTaskFull(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta) error

UpdateTaskFull delete existing and insert new modeling task and task run history in database.

Model id, task id, run id, set id updated with actual database id's. Task input worksets (new content of task_set table) must exist in workset_lst table.

type TaskPub

type TaskPub struct {
	TaskDefPub              // task definition: metadata and input worksets
	TaskRun    []taskRunPub // task run history: task_run_lst
}

TaskPub is "public" modeling task metadata, task input worksets and task run history for json import-export

func (*TaskPub) FromPublic

func (pub *TaskPub) FromPublic(dbConn *sql.DB, modelDef *ModelMeta) (*TaskMeta, bool, bool, error)

FromPublic convert modeling task metadata from "public" format (coming from json import-export) into db rows.

It return task metadata and two boolean flags: (1) isSetNotFound = true if some of task workset names not found in current database (2) isTaskRunNotFound = true if some of task run (pairs of set, model run) set or model run not found in current database.

Worksets are searched by set name, which is unique inside of the model. Model run searched by run digest.

type TaskRow

type TaskRow struct {
	TaskId  int    // task_id      INT          NOT NULL, -- unique task id
	ModelId int    // model_id     INT          NOT NULL
	Name    string // task_name    VARCHAR(255) NOT NULL
}

TaskRow is db row of task_lst.

func GetTask

func GetTask(dbConn *sql.DB, taskId int) (*TaskRow, error)

GetTask return modeling task rows by id: task_lst table row and set ids from task_set

func GetTaskByName

func GetTaskByName(dbConn *sql.DB, modelId int, name string) (*TaskRow, error)

GetTaskByName return modeling task rows by id: task_lst table row and set ids from task_set

func GetTaskList

func GetTaskList(dbConn *sql.DB, modelId int) ([]TaskRow, error)

GetTaskList return list of model tasks: task_lst rows.

type TaskRunRow

type TaskRunRow struct {
	TaskRunId      int    // task_run_id INT          NOT NULL, -- unique task run id
	TaskId         int    // task_id     INT          NOT NULL
	Name           string // run_name    VARCHAR(255) NOT NULL, -- task run name
	SubCount       int    // sub_count   INT          NOT NULL, -- subvalue count of task run
	CreateDateTime string // create_dt   VARCHAR(32)  NOT NULL, -- start date-time
	Status         string // status      VARCHAR(1)   NOT NULL, -- task status: i=init p=progress w=wait s=success x=exit e=error(failed)
	UpdateDateTime string // update_dt   VARCHAR(32)  NOT NULL, -- last update date-time
	RunStamp       string // run_stamp   VARCHAR(32)  NOT NULL, -- process run stamp, by default is log time stamp
}

TaskRunRow is db row of task_run_lst. This table contains task run history and status.

Task status: i=init p=progress w=wait s=success x=exit e=error(failed)

if task status = w (wait) then
   model wait and NOT completed until other process set status to one of finals: s,x,e
   model check if any new sets inserted into task_set and run it as they arrive

func GetTaskFirstRun

func GetTaskFirstRun(dbConn *sql.DB, taskId int) (*TaskRunRow, error)

GetTaskFirstRun return first run of the modeling task: task_run_lst table row.

func GetTaskLastCompletedRun

func GetTaskLastCompletedRun(dbConn *sql.DB, taskId int) (*TaskRunRow, error)

GetTaskLastCompletedRun return last completed run of the modeling task: task_run_lst table row.

Task run completed if run status one of: s=success, x=exit, e=error

func GetTaskLastRun

func GetTaskLastRun(dbConn *sql.DB, taskId int) (*TaskRunRow, error)

GetTaskLastRun return last run of the modeling task: task_run_lst table row.

func GetTaskRun

func GetTaskRun(dbConn *sql.DB, taskRunId int) (*TaskRunRow, error)

GetTaskRun return modeling task run status: task_run_lst table row.

func GetTaskRunByName

func GetTaskRunByName(dbConn *sql.DB, taskId int, name string) (*TaskRunRow, error)

GetTaskRunByName return modeling task run status by task id and task run name: task_run_lst table row. If there is multiple task runs with this name then run with min(task_run_id) returned

func GetTaskRunByStamp

func GetTaskRunByStamp(dbConn *sql.DB, taskId int, stamp string) (*TaskRunRow, error)

GetTaskRunByStamp return modeling task run status by task id and task run stamp: task_run_lst table row. If there is multiple task runs with this stamp then run with min(task_run_id) returned

func GetTaskRunByStampOrName

func GetTaskRunByStampOrName(dbConn *sql.DB, taskId int, trsn string) (*TaskRunRow, error)

GetTaskRunByStampOrName return modeling task run status by task id and task run stamp or task run name: task_run_lst table row.

It does select task run row by task id and stamp, if not found then by task id and run name. If there is multiple task runs with this stamp or name then run with min(task_run_id) returned.

func GetTaskRunListByStampOrName

func GetTaskRunListByStampOrName(dbConn *sql.DB, taskId int, trsn string) ([]TaskRunRow, error)

GetTaskRunListByStampOrName return modeling task run rows from task_run_lst table by task id and task run stamp or task run name.

It does select task run rows by task id and stamp, if not found then by task id and run name. If there is multiple task runs with this stamp or name then multiple rows returned.

type TaskRunSetRow

type TaskRunSetRow struct {
	TaskRunId int // task_run_id INT NOT NULL
	RunId     int // run_id      INT NOT NULL, -- if > 0 then result run id
	SetId     int // set_id      INT NOT NULL, -- if > 0 then input working set id
	TaskId    int // task_id     INT NOT NULL
}

TaskRunSetRow is db row of task_run_set. This table contains task run input (working set id) and output (model run id)

func GetTaskRunSetRows added in v1.8.4

func GetTaskRunSetRows(dbConn *sql.DB, taskRunId int) ([]TaskRunSetRow, error)

GetTaskRunSetRows retrun task run body (pairs of run id and set id) by task run id: task_run_set table rows.

It does not return non-completed task run (run in progress). Task run completed if run status one of: s=success, x=exit, e=error

type TaskRunSetTxt

type TaskRunSetTxt struct {
	SetTxt map[string][]DescrNote // map workset name to description and notes by language
	RunTxt map[string][]DescrNote // map run digest-or-name to description and notes by language
}

TaskRunSetTxt is additional task text: description and notes by language for all input worksets and model runs of the task. Run identified by run digest or, if digest is null then by run name

func GetTaskRunSetText

func GetTaskRunSetText(dbConn *sql.DB, taskId int, langCode string) (*TaskRunSetTxt, error)

GetTaskRunSetText return additinal modeling task text description and notes for all task worksets and model runs: workset_txt, run_txt table rows.

It includes all input worksets text (description and notes) and comlpleted model runs text (description and notes). Task run completed if run status one of: s=success, x=exit, e=error If langCode not empty then only specified language selected else all languages.

type TaskTxtRow

type TaskTxtRow struct {
	TaskId   int    // task_id  INT           NOT NULL
	LangCode string // lang_code VARCHAR(32)  NOT NULL
	Descr    string // descr     VARCHAR(255) NOT NULL
	Note     string // note      VARCHAR(32000)
}

TaskTxtRow is db row of task_txt

type TypeDicRow

type TypeDicRow struct {
	ModelId     int    // model_id      INT          NOT NULL
	TypeId      int    // model_type_id INT          NOT NULL
	TypeHid     int    // type_hid      INT          NOT NULL, -- unique type id
	Name        string // type_name     VARCHAR(255) NOT NULL, -- type name: int, double, etc.
	Digest      string // type_digest   VARCHAR(32)  NOT NULL
	DicId       int    // dic_id        INT NOT NULL, -- dictionary id: 0=simple 1=logical 2=classification 3=range 4=partition 5=link
	TotalEnumId int    // total_enum_id INT NOT NULL, -- if total enabled this is enum_value of total item =max+1
}

TypeDicRow is db row of type_dic join to model_type_dic table.

TypeHid (type_dic.type_hid) is db-unique id of the type, use digest to find same type in other db. TypeId (model_type_dic.model_type_id) is model-unique type id, assigned by model compiler.

func (*TypeDicRow) IsBool

func (typeRow *TypeDicRow) IsBool() bool

IsBool return true if model type is boolean.

func (*TypeDicRow) IsBuiltIn

func (typeRow *TypeDicRow) IsBuiltIn() bool

IsBuiltIn return true if model type is built-in, ie: int, double, logical.

func (*TypeDicRow) IsFloat

func (typeRow *TypeDicRow) IsFloat() bool

IsFloat return true if model type is float.

func (*TypeDicRow) IsInt

func (typeRow *TypeDicRow) IsInt() bool

IsInt return true if model type is integer (not float, string or boolean). If type is not a built-in then it must be integer enums.

func (*TypeDicRow) IsString

func (typeRow *TypeDicRow) IsString() bool

IsString return true if model type is string.

type TypeEnumRow

type TypeEnumRow struct {
	ModelId int    // model_id      INT NOT NULL
	TypeId  int    // model_type_id INT NOT NULL
	EnumId  int    // enum_id       INT NOT NULL
	Name    string // enum_name     VARCHAR(255) NOT NULL
}

TypeEnumRow is db row of type_enum_lst join to model_type_dic table

type TypeEnumTxtRow

type TypeEnumTxtRow struct {
	ModelId  int    // model_id      INT          NOT NULL
	TypeId   int    // model_type_id INT          NOT NULL
	EnumId   int    // enum_id       INT          NOT NULL
	LangCode string // lang_code     VARCHAR(32)  NOT NULL
	Descr    string // descr         VARCHAR(255) NOT NULL
	Note     string // note          VARCHAR(32000)
}

TypeEnumTxtRow is db row of type_enum_txt join to model_type_dic table

type TypeMeta

type TypeMeta struct {
	TypeDicRow               // model type rows: type_dic join to model_type_dic
	Enum       []TypeEnumRow // type enum rows: type_enum_lst join to model_type_dic
}

TypeMeta is type metadata: type name and enums

type TypeTxtRow

type TypeTxtRow struct {
	ModelId  int    // model_id      INT          NOT NULL
	TypeId   int    // model_type_id INT          NOT NULL
	LangCode string // lang_code     VARCHAR(32)  NOT NULL
	Descr    string // descr         VARCHAR(255) NOT NULL
	Note     string // note          VARCHAR(32000)
}

TypeTxtRow is db row of type_dic_txt join to model_type_dic table

type WorksetHdrPub

type WorksetHdrPub struct {
	ModelName      string      // model name for that workset
	ModelDigest    string      // model digest for that workset
	Name           string      // workset name: set_name VARCHAR(255) NOT NULL
	BaseRunDigest  string      // if not empty then digest of the base run
	IsReadonly     bool        // readonly flag
	UpdateDateTime string      // last update date-time
	Txt            []DescrNote // workset text: description and notes by language
}

WorksetHdrPub is "public" workset metadata for json import-export

type WorksetMeta

type WorksetMeta struct {
	Set   WorksetRow      // workset master row: workset_lst
	Txt   []WorksetTxtRow // workset text rows: workset_txt
	Param []worksetParam  // workset parameter: parameter_hid, sub-value count and workset_parameter_txt rows
}

WorksetMeta is a model workset metadata: name, parameters, decription, notes.

Workset (working set of model input parameters): it can be a full set, which include all model parameters or subset and include only some parameters.

Each model must have "default" workset. Default workset must include ALL model parameters (it is a full set). Default workset is a first workset of the model: set_id = min(set_id). If workset is a subset (does not include all model parameters) then it can be based on model run results, specified by run_id (not NULL).

Workset can be editable or read-only. If workset is editable then you can modify input parameters or workset description, notes, etc. If workset is read-only then you can run the model using that workset as input.

Important: working set_id must be different from run_id (use id_lst to get it) Important: always update parameter values inside of transaction scope Important: before parameter update do is_readonly = is_readonly + 1 to "lock" workset

WorksetMeta is workset metadata db rows: workset_lst, workset_txt, workset_parameter, workset_parameter_txt

func GetWorksetFull

func GetWorksetFull(dbConn *sql.DB, setRow *WorksetRow, langCode string) (*WorksetMeta, error)

GetWorksetFull return full workset metadata: workset_lst, workset_txt, workset_parameter, workset_parameter_txt table rows.

If langCode not empty then only specified language selected else all languages

func GetWorksetFullList

func GetWorksetFullList(dbConn *sql.DB, modelId int, isReadonly bool, langCode string) ([]WorksetMeta, error)

GetWorksetFullList return list of full workset metadata: workset_lst, workset_txt, workset_parameter, workset_parameter_txt table rows.

If isReadonly true then return only readonly worksets else all worksets. If langCode not empty then only specified language selected else all languages

func (*WorksetMeta) ToPublic

func (meta *WorksetMeta) ToPublic(dbConn *sql.DB, modelDef *ModelMeta) (*WorksetPub, error)

ToPublic convert workset db rows into "public" workset format for json import-export

func (*WorksetMeta) UpdateWorkset

func (meta *WorksetMeta) UpdateWorkset(dbConn *sql.DB, modelDef *ModelMeta, isReplace bool, langDef *LangMeta) error

UpdateWorkset create new workset metadata, replace or merge existing workset metadata in database.

Set name is used to find workset and set id updated with actual database value. Workset must be read-write for replace or merge.

Only metadata updated: list of workset parameters not changed. To add or remove parameters form workset use UpdateWorksetParameter() method. It is an error if incoming list parameters include any parameter which are not already in workset_parameter table.

If workset does not exist then empty workset created, without parameters. Parameter list in workset metadata must be empty if workset does not exist.

Replace is replace of existing metadata or create empty new workset. If workset exist then workset metadata replaced and parameters text metadata replaced.

Merge does merge of text metadata with existing workset or create empty new workset. If workset exist then text is updated if such language already exist or inserted if no text in that language.

func (*WorksetMeta) UpdateWorksetParameter

func (meta *WorksetMeta) UpdateWorksetParameter(
	dbConn *sql.DB, modelDef *ModelMeta, isReplaceMeta bool, param *ParamRunSetPub, cellLst *list.List, langDef *LangMeta,
) (int, error)

UpdateWorksetParameter add new or replace existing workset parameter.

If parameter already exist in workset then parameter metadata either merged or replaced. If parameter not exist in workset then parameter values must be supplied, it cannot be empty. If parameter not exist in workset then new parameter metadata and values inserted. If list of new parameter values supplied then parameter values completely replaced.

Set name is used to find workset and set id updated with actual database value. Workset must be read-write for replace or merge.

type WorksetParamTxtRow

type WorksetParamTxtRow struct {
	SetId    int    // set_id        INT NOT NULL
	ParamHid int    // parameter_hid INT NOT NULL
	LangCode string // lang_code VARCHAR(32)  NOT NULL
	Note     string // note          VARCHAR(32000), -- parameter value note
}

WorksetParamTxtRow is workset_parameter_txt table row.

func GetWorksetAllParamText

func GetWorksetAllParamText(dbConn *sql.DB, setId int, langCode string) ([]WorksetParamTxtRow, error)

GetWorksetAllParamText return all workset parameters value notes: workset_parameter_txt table rows.

If langCode not empty then only specified language selected else all languages

func GetWorksetParamText

func GetWorksetParamText(dbConn *sql.DB, setId int, paramHid int, langCode string) ([]WorksetParamTxtRow, error)

GetWorksetParamText return parameter value notes: workset_parameter_txt table rows.

If langCode not empty then only specified language selected else all languages

type WorksetPub

type WorksetPub struct {
	WorksetHdrPub
	Param []ParamRunSetPub // workset parameters: name and text (value notes by language)
}

WorksetPub is "public" workset metadata and parameter metadata for json import-export

func (*WorksetPub) FromPublic

func (pub *WorksetPub) FromPublic(dbConn *sql.DB, modelDef *ModelMeta) (*WorksetMeta, error)

FromPublic convert workset metadata from "public" format (coming from json import-export) into db rows.

type WorksetRow

type WorksetRow struct {
	SetId          int    // unique working set id
	BaseRunId      int    // if not NULL and positive then base run id (source run id)
	ModelId        int    // model_id     INT          NOT NULL
	Name           string // set_name     VARCHAR(255) NOT NULL
	IsReadonly     bool   // is_readonly  SMALLINT     NOT NULL
	UpdateDateTime string // update_dt    VARCHAR(32)  NOT NULL, -- last update date-time
}

WorksetRow is workset_lst table row.

func GetDefaultWorkset

func GetDefaultWorkset(dbConn *sql.DB, modelId int) (*WorksetRow, error)

GetDefaultWorkset return default working set for the model: workset_lst table row.

Default workset is a first workset for the model, each model must have default workset.

func GetWorkset

func GetWorkset(dbConn *sql.DB, setId int) (*WorksetRow, error)

GetWorkset return working set by id: workset_lst table row.

func GetWorksetByName

func GetWorksetByName(dbConn *sql.DB, modelId int, name string) (*WorksetRow, error)

GetWorksetByName return working set by name.

If model has multiple worksets with that name then return first set.

func GetWorksetList

func GetWorksetList(dbConn *sql.DB, modelId int) ([]WorksetRow, error)

GetWorksetList return list of model worksets: workset_lst rows.

type WorksetTxtRow

type WorksetTxtRow struct {
	SetId    int    // set_id    INT          NOT NULL
	LangCode string // lang_code VARCHAR(32)  NOT NULL
	Descr    string // descr     VARCHAR(255) NOT NULL
	Note     string // note      VARCHAR(32000)
}

WorksetTxtRow is db row of workset_txt

func GetWorksetText

func GetWorksetText(dbConn *sql.DB, setId int, langCode string) ([]WorksetTxtRow, error)

GetWorksetText return workset description and notes: workset_txt table rows.

If langCode not empty then only specified language selected else all languages

type WorksetValuePub

type WorksetValuePub struct {
	WorksetHdrPub
	Param []ParamValuePub // workset parameters: name, text (value notes by language) and value
}

WorksetValuePub is "public" workset metadata, parameter metadata and values for json import-export

type WriteLayout

type WriteLayout struct {
	Name string // parameter name or output table name
	ToId int    // run id or set id to write parameter or output table values
}

WriteLayout describes parameters or output tables values for insert or update.

Name is a parameter or output table name to read.

type WriteParamLayout

type WriteParamLayout struct {
	WriteLayout        // common write layout: parameter name, run or set id
	IsToRun     bool   // if true then write into into model run else into workset
	IsPage      bool   // if true then write only page of data else all parameter values
	SubCount    int    // parameter sub-values count
	DoubleFmt   string // used for float model types digest calculation
}

WriteParamLayout describes parameter values for insert or update. Double format string is used for digest calcultion if value type if float or double.

type WriteTableLayout

type WriteTableLayout struct {
	WriteLayout        // common write layout: output table name, run or set id
	DoubleFmt   string // used for float model types digest calculation
}

WriteTableLayout describes output table values for insert or update. Double format string is used for digest calcultion if value type if float or double.

Jump to

Keyboard shortcuts

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