...

go.openmpp.org - OpenM++ Go Library and Tools

Package db

import "go.openmpp.org/ompp/db"
Overview
Index

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
func DeleteModel(dbConn *sql.DB, modelId int) error
func DeleteRun(dbConn *sql.DB, runId int) error
func DeleteTask(dbConn *sql.DB, taskId int) error
func DeleteWorkset(dbConn *sql.DB, setId int) error
func DeleteWorksetParameter(dbConn *sql.DB, modelId int, setName, paramName string) (int, error)
func GetModelId(dbConn *sql.DB, name, digest string) (bool, int, error)
func GetModelList(dbConn *sql.DB) ([]ModelDicRow, error)
func GetModelTextById(dbConn *sql.DB, modelId int, langCode string) ([]ModelTxtRow, error)
func GetProfileList(dbConn *sql.DB) ([]string, error)
func GetRunAllParamText(dbConn *sql.DB, runId int, langCode string) ([]RunParamTxtRow, error)
func GetRunFullList(dbConn *sql.DB, modelId int, isSuccess bool, langCode string) ([]RunMeta, error)
func GetRunList(dbConn *sql.DB, modelId int) ([]RunRow, error)
func GetRunListText(dbConn *sql.DB, modelId int, langCode string) ([]RunRow, []RunTxtRow, error)
func GetRunOptions(dbConn *sql.DB, runId int) (map[string]string, error)
func GetRunParamText(dbConn *sql.DB, runId int, paramHid int, langCode string) ([]RunParamTxtRow, error)
func GetRunText(dbConn *sql.DB, runId int, langCode string) ([]RunTxtRow, error)
func GetTaskByModelId(dbConn *sql.DB, modelId int, langCode string) ([]TaskRow, []TaskTxtRow, error)
func GetTaskFullList(dbConn *sql.DB, modelId int, isSuccess bool, langCode string) ([]TaskMeta, error)
func GetTaskRunByTaskId(dbConn *sql.DB, taskId int) ([]TaskRunRow, error)
func GetTaskSetIds(dbConn *sql.DB, taskId int) ([]int, error)
func GetTaskText(dbConn *sql.DB, taskId int, langCode string) ([]TaskTxtRow, error)
func GetWorksetAllParamText(dbConn *sql.DB, setId int, langCode string) ([]WorksetParamTxtRow, error)
func GetWorksetFullList(dbConn *sql.DB, modelId int, isReadonly bool, langCode string) ([]WorksetMeta, error)
func GetWorksetList(dbConn *sql.DB, modelId int) ([]WorksetRow, error)
func GetWorksetListText(dbConn *sql.DB, modelId int, langCode string) ([]WorksetRow, []WorksetTxtRow, error)
func GetWorksetParamList(dbConn *sql.DB, setId int) ([]int, []int, error)
func GetWorksetParamText(dbConn *sql.DB, setId int, paramHid int, langCode string) ([]WorksetParamTxtRow, error)
func GetWorksetRunIds(dbConn *sql.DB, setId int) ([]int, error)
func GetWorksetText(dbConn *sql.DB, setId int, langCode string) ([]WorksetTxtRow, error)
func IfEmptyMakeDefault(modelName, dbConnStr, dbDriver string) (string, string)
func IsRunCompleted(status string) bool
func MakeSqliteDefault(modelSqlitePath string) string
func Open(dbConnStr, dbDriver string, isFacetRequired bool) (*sql.DB, Facet, error)
func OpenmppSchemaVersion(dbConn *sql.DB) (int, error)
func ReadOutputTable(dbConn *sql.DB, modelDef *ModelMeta, layout *ReadTableLayout) (*list.List, *ReadPageLayout, error)
func ReadParameter(dbConn *sql.DB, modelDef *ModelMeta, layout *ReadParamLayout) (*list.List, *ReadPageLayout, error)
func SelectFirst(dbConn *sql.DB, query string, cvt func(row *sql.Row) error) error
func SelectRows(dbConn *sql.DB, query string, cvt func(rows *sql.Rows) error) error
func SelectToList(dbConn *sql.DB, query string, layout ReadPageLayout, cvt func(rows *sql.Rows) (interface{}, error)) (*list.List, *ReadPageLayout, error)
func TrxSelectFirst(dbTrx *sql.Tx, query string, cvt func(row *sql.Row) error) error
func TrxSelectRows(dbTrx *sql.Tx, query string, cvt func(rows *sql.Rows) error) error
func TrxUpdate(dbTrx *sql.Tx, query string) error
func TrxUpdateStatement(dbTrx *sql.Tx, query string, put func() (bool, []interface{}, error)) error
func Update(dbConn *sql.DB, query string) error
func UpdateLanguage(dbConn *sql.DB, langDef *LangMeta) error
func UpdateModel(dbConn *sql.DB, dbFacet Facet, modelDef *ModelMeta) error
func UpdateModelGroup(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta, modelGroup *GroupMeta) error
func UpdateModelText(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta, modelTxt *ModelTxtMeta) error
func UpdateModelWord(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta, mwDef *ModelWordMeta) error
func UpdateProfile(dbConn *sql.DB, profile *ProfileMeta) error
func UpdateRunDigest(dbConn *sql.DB, runId int) (string, error)
func UpdateRunText(dbConn *sql.DB, runId int, txt []RunTxtRow, langDef *LangMeta) error
func UpdateWorksetReadonly(dbConn *sql.DB, setId int, isReadonly bool) error
func UpdateWorksetReadonlyByName(dbConn *sql.DB, modelId int, name string, isReadonly bool) error
func WriteOutputTable(dbConn *sql.DB, modelDef *ModelMeta, layout *WriteTableLayout, accCellLst *list.List, exprCellLst *list.List) error
func WriteParameter(dbConn *sql.DB, modelDef *ModelMeta, layout *WriteParamLayout, cellLst *list.List) error
type CellAcc
    func (CellAcc) CsvFileName(modelDef *ModelMeta, name string) (string, error)
    func (CellAcc) CsvHeader(modelDef *ModelMeta, name string, isIdHeader bool, valueName string) ([]string, error)
    func (CellAcc) CsvToCell(modelDef *ModelMeta, name string, subCount int, valueName string) (func(row []string) (interface{}, error), error)
    func (CellAcc) CsvToIdRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (func(interface{}, []string) error, error)
    func (CellAcc) CsvToRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (func(interface{}, []string) error, error)
    func (CellAcc) IdToCodeCell(modelDef *ModelMeta, name string) (func(interface{}) (interface{}, error), error)
type CellAllAcc
    func (CellAllAcc) CsvFileName(modelDef *ModelMeta, name string) (string, error)
    func (CellAllAcc) CsvHeader(modelDef *ModelMeta, name string, isIdHeader bool, valueName string) ([]string, error)
    func (CellAllAcc) CsvToCell(modelDef *ModelMeta, name string, subCount int, valueName string) (func(row []string) (interface{}, error), error)
    func (CellAllAcc) CsvToIdRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (func(interface{}, []string) error, error)
    func (CellAllAcc) CsvToRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (func(interface{}, []string) error, error)
    func (CellAllAcc) IdToCodeCell(modelDef *ModelMeta, name string) (func(interface{}) (interface{}, error), error)
type CellCodeAcc
type CellCodeAllAcc
type CellCodeExpr
type CellCodeParam
    func (CellCodeParam) CodeToIdCell(modelDef *ModelMeta, name string) (func(interface{}) (interface{}, error), error)
type CellExpr
    func (CellExpr) CsvFileName(modelDef *ModelMeta, name string) (string, error)
    func (CellExpr) CsvHeader(modelDef *ModelMeta, name string, isIdHeader bool, valueName string) ([]string, error)
    func (CellExpr) CsvToCell(modelDef *ModelMeta, name string, subCount int, valueName string) (func(row []string) (interface{}, error), error)
    func (CellExpr) CsvToIdRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (func(interface{}, []string) error, error)
    func (CellExpr) CsvToRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (func(interface{}, []string) error, error)
    func (CellExpr) IdToCodeCell(modelDef *ModelMeta, name string) (func(interface{}) (interface{}, error), error)
type CellParam
    func (CellParam) CsvFileName(modelDef *ModelMeta, name string) (string, error)
    func (CellParam) CsvHeader(modelDef *ModelMeta, name string, isIdHeader bool, valueName string) ([]string, error)
    func (CellParam) CsvToCell(modelDef *ModelMeta, name string, subCount int, valueName string) (func(row []string) (interface{}, error), error)
    func (CellParam) CsvToIdRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (func(interface{}, []string) error, error)
    func (CellParam) CsvToRow(modelDef *ModelMeta, name string, doubleFmt string, valueName string) (func(interface{}, []string) error, error)
    func (CellParam) IdToCodeCell(modelDef *ModelMeta, name string) (func(interface{}) (interface{}, error), error)
type CellToCodeConverter
type CellToIdConverter
type CsvConverter
type DescrNote
type Facet
    func (facet Facet) String() string
type FilterColumn
type FilterIdColumn
type FilterOp
type GroupLstPub
type GroupLstRow
type GroupMeta
    func GetModelGroup(dbConn *sql.DB, modelId int, langCode string) (*GroupMeta, error)
    func (meta *GroupMeta) ToPublic(dbConn *sql.DB, modelDef *ModelMeta) (*GroupLstPub, error)
type GroupPcPub
type GroupPcRow
type GroupPub
type GroupTxtRow
type LangLstRow
type LangMeta
    func GetLanguages(dbConn *sql.DB) (*LangMeta, error)
    func (src *LangMeta) Clone() (*LangMeta, error)
    func (langDef *LangMeta) CodeById(langId int) (string, bool)
    func (dst *LangMeta) FromJson(srcJson []byte) (bool, error)
    func (langDef *LangMeta) IdByCode(langCode string) (int, bool)
type LangNote
type ModelDicRow
type ModelMeta
    func GetModel(dbConn *sql.DB, name, digest string) (*ModelMeta, error)
    func GetModelById(dbConn *sql.DB, modelId int) (*ModelMeta, error)
    func (src *ModelMeta) Clone() (*ModelMeta, error)
    func (dst *ModelMeta) FromJson(srcJson []byte) (bool, error)
    func (meta *ModelMeta) OutTableByDigest(digest string) (int, bool)
    func (meta *ModelMeta) OutTableByHid(tableHid int) (int, bool)
    func (meta *ModelMeta) OutTableByKey(tableId int) (int, bool)
    func (meta *ModelMeta) OutTableByName(name string) (int, bool)
    func (meta *ModelMeta) OutTableHidById(tableId int) int
    func (meta *ModelMeta) OutTableIdByHid(tableHid int) int
    func (meta *ModelMeta) ParamByDigest(digest string) (int, bool)
    func (meta *ModelMeta) ParamByHid(paramHid int) (int, bool)
    func (meta *ModelMeta) ParamByKey(paramId int) (int, bool)
    func (meta *ModelMeta) ParamByName(name string) (int, bool)
    func (meta *ModelMeta) ParamHidById(paramId int) int
    func (meta *ModelMeta) ParamIdByHid(paramHid int) int
    func (meta *ModelMeta) TypeByKey(typeId int) (int, bool)
type ModelTxtMeta
    func GetModelText(dbConn *sql.DB, modelId int, langCode string) (*ModelTxtMeta, error)
type ModelTxtRow
type ModelWordMeta
    func GetModelWord(dbConn *sql.DB, modelId int, langCode string) (*ModelWordMeta, error)
type OrderByColumn
type ParamDicRow
type ParamDimsRow
type ParamDimsTxtRow
type ParamMeta
    func (param *ParamMeta) DimByKey(dimId int) (int, bool)
type ParamRunSetPub
type ParamTxtRow
type ProfileMeta
    func GetProfile(dbConn *sql.DB, name string) (*ProfileMeta, error)
type ReadLayout
type ReadPageLayout
type ReadParamLayout
type ReadTableLayout
type RunMeta
    func GetRunFull(dbConn *sql.DB, runRow *RunRow, langCode string) (*RunMeta, error)
    func (meta *RunMeta) ToPublic(dbConn *sql.DB, modelDef *ModelMeta) (*RunPub, error)
    func (meta *RunMeta) UpdateRun(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta) (bool, error)
type RunParamTxtRow
type RunPub
    func (pub *RunPub) FromPublic(dbConn *sql.DB, modelDef *ModelMeta) (*RunMeta, error)
type RunRow
    func GetFirstRun(dbConn *sql.DB, modelId int) (*RunRow, error)
    func GetLastCompletedRun(dbConn *sql.DB, modelId int) (*RunRow, error)
    func GetLastRun(dbConn *sql.DB, modelId int) (*RunRow, error)
    func GetRun(dbConn *sql.DB, runId int) (*RunRow, error)
    func GetRunByDigest(dbConn *sql.DB, digest string) (*RunRow, error)
    func GetRunByName(dbConn *sql.DB, modelId int, name string) (*RunRow, error)
type RunTxtRow
type TableAccRow
type TableAccTxtRow
type TableDicRow
type TableDimsRow
type TableDimsTxtRow
type TableExprRow
type TableExprTxtRow
type TableMeta
    func (table *TableMeta) DimByKey(dimId int) (int, bool)
type TableTxtRow
type TaskMeta
    func GetTaskFull(dbConn *sql.DB, taskRow *TaskRow, langCode string) (*TaskMeta, error)
    func (meta *TaskMeta) ToPublic(dbConn *sql.DB, modelDef *ModelMeta) (*TaskPub, error)
    func (meta *TaskMeta) UpdateTask(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta) error
type TaskPub
    func (pub *TaskPub) FromPublic(dbConn *sql.DB, modelDef *ModelMeta) (*TaskMeta, bool, bool, error)
type TaskRow
    func GetTask(dbConn *sql.DB, taskId int) (*TaskRow, error)
    func GetTaskByName(dbConn *sql.DB, modelId int, name string) (*TaskRow, error)
type TaskRunRow
    func GetTaskFirstRun(dbConn *sql.DB, taskId int) (*TaskRunRow, error)
    func GetTaskLastCompletedRun(dbConn *sql.DB, taskId int) (*TaskRunRow, error)
    func GetTaskLastRun(dbConn *sql.DB, taskId int) (*TaskRunRow, error)
    func GetTaskRun(dbConn *sql.DB, taskRunId int) (*TaskRunRow, []TaskRunSetRow, error)
type TaskRunSetRow
type TaskTxtRow
type TypeDicRow
    func (typeRow *TypeDicRow) IsBool() bool
    func (typeRow *TypeDicRow) IsBuiltIn() bool
    func (typeRow *TypeDicRow) IsFloat() bool
    func (typeRow *TypeDicRow) IsInt() bool
    func (typeRow *TypeDicRow) IsString() bool
type TypeEnumRow
type TypeEnumTxtRow
type TypeMeta
type TypeTxtRow
type WorksetMeta
    func GetWorksetFull(dbConn *sql.DB, setRow *WorksetRow, langCode string) (*WorksetMeta, error)
    func (meta *WorksetMeta) ToPublic(dbConn *sql.DB, modelDef *ModelMeta) (*WorksetPub, error)
    func (meta *WorksetMeta) UpdateWorkset(dbConn *sql.DB, modelDef *ModelMeta, isReplace bool, langDef *LangMeta) error
    func (meta *WorksetMeta) UpdateWorksetParameter(dbConn *sql.DB, modelDef *ModelMeta, isReplaceMeta bool, param *ParamRunSetPub, cellLst *list.List, langDef *LangMeta) (int, error)
type WorksetParamTxtRow
type WorksetPub
    func (pub *WorksetPub) FromPublic(dbConn *sql.DB, modelDef *ModelMeta) (*WorksetMeta, error)
type WorksetRow
    func GetDefaultWorkset(dbConn *sql.DB, modelId int) (*WorksetRow, error)
    func GetWorkset(dbConn *sql.DB, setId int) (*WorksetRow, error)
    func GetWorksetByName(dbConn *sql.DB, modelId int, name string) (*WorksetRow, error)
type WorksetTxtRow
type WriteLayout
type WriteParamLayout
type WriteTableLayout

Package files

cellAcc.go cellAllAcc.go cellExpr.go cellParam.go cellValue.go db.go dbFacet.go dbModel.go dbModelCommon.go dbModelInternal.go dbModelRunSet.go deleteModel.go deleteRun.go deleteTask.go deleteWorkset.go getCommon.go getGroup.go getLanguage.go getModel.go getModelText.go getRun.go getTask.go getWorkset.go publicRun.go publicWorkset.go readOutputTable.go readParameter.go readWriteLayout.go updateCommon.go updateGroup.go updateLanguage.go updateModel.go updateModelText.go updateProfile.go updateRun.go updateTask.go updateWorkset.go updateWorksetParameter.go writeOutputTable.go writeParameter.go

Constants

Database connection values

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
)

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
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
)
const MinSchemaVersion = 100 // min compatible db schema version

TotalEnumCode is predefined enum code for "total" enum

const TotalEnumCode = "all"

func DeleteModel

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

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

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 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", "20120817_1604590148") if digest is empty then first model with min(model_id) is used

func GetModelList

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

GetModelList return list of the models: model_dic table rows.

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.

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 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 GetRunFullList

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

GetRunFullList return list of full metadata for completed model runs: run_lst, run_txt, run_option, run_parameter, run_parameter_txt 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 GetRunList

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

GetRunList return list of model runs: run_lst rows.

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 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

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

func GetTaskByModelId

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

GetTaskByModelId 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 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 GetTaskRunByTaskId

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

GetTaskRunByTaskId return list of modeling task runs by task id: task_run_lst table rows.

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 GetTaskText

func GetTaskText(dbConn *sql.DB, taskId int, langCode string) ([]TaskTxtRow, error)

GetTaskText return modeling task description and notes: task_txt table rows.

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

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 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 GetWorksetList

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

GetWorksetList return list of model worksets: workset_lst rows.

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 GetWorksetParamList

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

GetWorksetParamList return Hid and sub-values count of all parameters included in that workset (parameter_hid, sub_count).

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

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 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

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 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 OpenmppSchemaVersion

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

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

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 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 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.

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) error

UpdateModel insert new model metadata in database.

If model with same digest already exist then call simply 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 UpdateModelGroup

func UpdateModelGroup(dbConn *sql.DB, modelDef *ModelMeta, langDef *LangMeta, modelGroup *GroupMeta) error

UpdateModelGroup insert new or update existing model groups and groups text (description, notes) in group_lst, group_pc, group_txt.

If modelGroup contains all non-empty GroupLst slice then all 3 tables (group_lst, group_pc, group_txt) erased and new values inserted. If only text slice GroupTxt non-empty then only group_txt rows updated or inserted (not deleted). Model id and language id updated with id's from modelDef (assuming it contains actual db id's)

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, update existing or delete existing profile in profile_lst and profile_option tables.

It always delete from profile_lst and profile_option rows where profile_name = profile.Name If profile.Opts is not empty then new rows inserted into profile_lst and profile_option.

func UpdateRunDigest

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

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

func UpdateRunText

func UpdateRunText(dbConn *sql.DB, runId int, txt []RunTxtRow, langDef *LangMeta) error

UpdateRunText update run_txt table of existing run_id.

Run id of the input txt db rows updated with runId value. If run not exist or status is not completed (success, exit, error) then function does nothing.

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

type CellAcc

CellAcc is value of output table accumulator.

type CellAcc struct {
    IsNull bool // if true then value is NULL
    AccId  int  // output table accumulator id
    SubId  int  // output table subvalue id
    // contains filtered or unexported fields
}

func (CellAcc) CsvFileName

func (CellAcc) CsvFileName(modelDef *ModelMeta, name string) (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

CellAllAcc is value of multiple output table accumulators.

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)
}

func (CellAllAcc) CsvFileName

func (CellAllAcc) CsvFileName(modelDef *ModelMeta, name string) (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

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

type CellCodeAcc struct {
    IsNull bool // if true then value is NULL
    AccId  int  // output table accumulator id
    SubId  int  // output table subvalue id
    // contains filtered or unexported fields
}

type CellCodeAllAcc

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

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)
}

type CellCodeExpr

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

type CellCodeExpr struct {
    IsNull bool // if true then value is NULL
    ExprId int  // output table expression id
    // contains filtered or unexported fields
}

type CellCodeParam

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

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

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

CellExpr is value of output table expression.

type CellExpr struct {
    IsNull bool // if true then value is NULL
    ExprId int  // output table expression id
    // contains filtered or unexported fields
}

func (CellExpr) CsvFileName

func (CellExpr) CsvFileName(modelDef *ModelMeta, name string) (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

CellParam is value of input parameter.

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

func (CellParam) CsvFileName

func (CellParam) CsvFileName(modelDef *ModelMeta, name string) (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 cell value is enum id and csv row value is enum code.

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 cell value is enum id and csv row value is enum code.

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

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 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)
}

type CellToIdConverter

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 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)
}

type CsvConverter

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 CsvConverter interface {
    // return file name of csv file to store parameter or output table rows
    CsvFileName(modelDef *ModelMeta, name string) (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 cell (dimensions and value)
    CsvToCell(modelDef *ModelMeta, name string, subCount int, valueName string) (
        func(row []string) (interface{}, error), error)
}

type DescrNote

DescrNote is a holder for language code, descripriton and notes

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

type Facet

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

type Facet uint8
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 (Facet) String

func (facet Facet) String() string

String is default printable value of db facet, Stringer implementation

type FilterColumn

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

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
}

type FilterIdColumn

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

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
}

type FilterOp

FilterOp is enum type for filter operators in select where conditions

type FilterOp string

Select filter operators for dimension enum ids.

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

type GroupLstPub

GroupLstPub is "public" model groups metadata for json import-export

type GroupLstPub struct {
    ModelName   string       // model name for that run
    ModelDigest string       // model digest for that run
    Group       []GroupPub   // group and group text: group_lst row and and group_txt rows
    Pc          []GroupPcPub // groups parent-child hierarchy
}

type GroupLstRow

GroupLstRow is db row of group_lst table

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
}

type GroupMeta

GroupMeta is db rows to describe parent-child groups of model parameters and output tables.

type GroupMeta struct {
    ModelName   string        // model name for group metadata
    ModelDigest string        // model digest for group metadata
    GroupLst    []GroupLstRow // parameters or output tables group rows: group_lst
    GroupPc     []GroupPcRow  // group parent-child relationship rows: group_pc
    GroupTxt    []GroupTxtRow // group text rows: group_txt
}

func GetModelGroup

func GetModelGroup(dbConn *sql.DB, modelId int, langCode string) (*GroupMeta, error)

GetModelGroup return db rows of model parent-child groups of parameters and output tables. If langCode not empty then only specified language selected else all languages.

func (*GroupMeta) ToPublic

func (meta *GroupMeta) ToPublic(dbConn *sql.DB, modelDef *ModelMeta) (*GroupLstPub, error)

ToPublic convert model groups metadata into "public" format for json import-export.

type GroupPcPub

GroupPcPub is "public" part of group_pc db row

type GroupPcPub struct {
    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
}

type GroupPcRow

GroupPcRow is db row of group_pc table

type GroupPcRow struct {
    ModelId    int // model_id       INT NOT NULL
    GroupPcPub     // "public" part of group_pc db row
}

type GroupPub

GroupPub is "public" model groups metadata for json import-export

type GroupPub struct {
    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
    Txt      []DescrNote // group text: description and notes by language
}

type GroupTxtRow

GroupTxtRow is db row of group_txt table

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

type LangLstRow

LangLstRow is db row of lang_lst table.

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

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

type LangMeta

LangMeta is language and words in that language

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

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

LangNote is a holder for language code and notes

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

type ModelDicRow

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.

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
}

type ModelMeta

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).

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
}

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", "20120817_1604590148") 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

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

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
}

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

ModelTxtRow is db row of model_dic_txt join to model_dic

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)
}

type ModelWordMeta

ModelWordMeta is language-specific model_word db rows.

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
}

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

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

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

type ParamDicRow

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 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
    DbRunTable   string // db_run_table       VARCHAR(64)  NOT NULL
    DbSetTable   string // db_set_table       VARCHAR(64)  NOT NULL
    Rank         int    // parameter_rank     INT          NOT NULL
    TypeId       int    // model_type_id      INT          NOT NULL
    IsHidden     bool   // is_hidden          SMALLINT     NOT NULL
    NumCumulated int    // num_cumulated      INT          NOT NULL
}

type ParamDimsRow

ParamDimsRow is db row of parameter_dims join to model_parameter_dic table

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
}

type ParamDimsTxtRow

ParamDimsTxtRow is db row of parameter_dims_txt join to model_parameter_dic table

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)
}

type ParamMeta

ParamMeta is parameter metadata: parameter name, type, dimensions

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
    // contains filtered or unexported fields
}

func (*ParamMeta) DimByKey

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

DimByKey return index of parameter dimension by key: dimId

type ParamRunSetPub

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

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

type ParamTxtRow

ParamTxtRow is db row of parameter_dic_txt join to model_parameter_dic table

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)
}

type ProfileMeta

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.

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

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

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,

parameters:

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 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
}

type ReadPageLayout

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.

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
}

type ReadParamLayout

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 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)
}

type ReadTableLayout

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 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
}

type RunMeta

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

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
}

func GetRunFull

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

GetRunFull return full metadata for completed model run: run_lst, run_txt, run_option, run_parameter, run_parameter_txt rows.

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) (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 metadate updated with actual run id. Following is used to find existing model run: if digest not "" empty then by run digest; else if status is error then by run_name, sub_count, sub_completed, status, create_dt.

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

type RunParamTxtRow

RunParamTxtRow is db row of run_parameter_txt

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)
}

type RunPub

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

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
    Digest         string            // run_digest    VARCHAR(32)  NULL,     -- digest of the run
    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
}

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

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)

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
    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
    Digest         string // run_digest    VARCHAR(32)  NULL,     -- digest of the run
}

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 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 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

type RunTxtRow

RunTxtRow is db row of run_txt

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)
}

type TableAccRow

TableAccRow is db row of table_acc join to model_table_dic table

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
}

type TableAccTxtRow

TableAccTxtRow is db row of table_acc_txt join to model_table_dic table

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)
}

type TableDicRow

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 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
}

type TableDimsRow

TableDimsRow is db row of table_dims join to model_table_dic table

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
}

type TableDimsTxtRow

TableDimsTxtRow is db row of table_dims_txt join to model_table_dic table

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)
}

type TableExprRow

TableExprRow is db row of table_expr join to model_table_dic table

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
}

type TableExprTxtRow

TableExprTxtRow is db row of table_expr_txt join to model_table_dic table

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)
}

type TableMeta

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

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
}

func (*TableMeta) DimByKey

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

DimByKey return index of output table dimension by key: dimId

type TableTxtRow

TableTxtRow is db row of table_dic_txt join to model_table_dic table

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)
}

type TaskMeta

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.

type TaskMeta 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
    TaskRun []taskRunItem // task run history: task_run_lst and task_run_set rows
}

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 (*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) UpdateTask

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

UpdateTask insert new or update existing modeling task and task run history in database.

Model id, task id, run id, set id updated with actual database id's. Remove non-existing worksets and model runs from task

type TaskPub

TaskPub is "public" modeling task metadata for json import-export

type TaskPub 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
    TaskRun     []taskRunPub // task run history: task_run_lst
}

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 serached by: if run digest not empty then by digest; else if run status is error then by run_name, sub_count, sub_completed, status, create_dt.

type TaskRow

TaskRow is db row of task_lst.

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
}

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

type TaskRunRow

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
type TaskRunRow struct {
    TaskRunId      int    // task_run_id INT         NOT NULL, -- unique task run id
    TaskId         int    // task_id     INT         NOT NULL
    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
}

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, []TaskRunSetRow, error)

GetTaskRun return modeling task run status and result: task_run_lst and task_run_set table rows.

type TaskRunSetRow

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

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
}

type TaskTxtRow

TaskTxtRow is db row of task_txt

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)
}

type TypeDicRow

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.

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
}

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

TypeEnumRow is db row of type_enum_lst join to model_type_dic table

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
}

type TypeEnumTxtRow

TypeEnumTxtRow is db row of type_enum_txt join to model_type_dic table

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)
}

type TypeMeta

TypeMeta is type metadata: type name and enums

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
}

type TypeTxtRow

TypeTxtRow is db row of type_dic_txt join to model_type_dic table

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)
}

type WorksetMeta

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

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
}

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 (*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

WorksetParamTxtRow is workset_parameter_txt table row.

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
}

type WorksetPub

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

type WorksetPub 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
    Param          []ParamRunSetPub // workset parameters: name and text (value notes by language)
}

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

WorksetRow is workset_lst table row.

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
}

func GetDefaultWorkset

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

GetDefaultWorkset return default working set for the model.

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.

type WorksetTxtRow

WorksetTxtRow is db row of workset_txt

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)
}

type WriteLayout

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

Name is a parameter or output table name to read.

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
}

type WriteParamLayout

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

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
}

type WriteTableLayout

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

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