go: github.com/openmpp/go/ompp/db Index | Files

package db

import "github.com/openmpp/go/ompp/db"

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

Package Files

cellAcc.go cellAllAcc.go cellExpr.go cellParam.go cellValue.go copyParameter.go db.go dbFacet.go dbModel.go dbModelCommon.go dbModelInternal.go dbModelRunSetTask.go db_no_odbc.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 publicTask.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

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

Database connection values

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

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

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

Select filter operators for dimension enum ids.

const IsOdbcSupported = false

IsOdbcSupported indicate support of ODBC connections built-in

const MinSchemaVersion = 100

MinSchemaVersion is a minimal compatible db schema version

const TotalEnumCode = "all"

TotalEnumCode is predefined enum code for "total" enum

func CopyParameterFromRun Uses

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

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

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

func CopyParameterFromWorkset Uses

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

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

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

func DeleteModel Uses

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

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

func DeleteProfile Uses

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

DeleteProfile delete rows from profile in profile_lst and profile_option tables.

func DeleteProfileOption Uses

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

DeleteProfileOption delete row from profile_option table.

func DeleteRun Uses

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 Uses

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

DeleteTask delete modeling task and task run history from database.

func DeleteWorkset Uses

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

DeleteWorkset delete workset metadata and workset parameter values from database.

func DeleteWorksetParameter Uses

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 Uses

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

GetModelId return model id if exists.

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

func GetProfileList Uses

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

GetProfileList return profile names: profile_lst table rows.

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

func GetRunListText Uses

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 Uses

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

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

func GetTaskListText Uses

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

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

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

func GetTaskSetIds Uses

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

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

func GetWorksetListText Uses

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 Uses

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

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

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

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

func IfEmptyMakeDefault Uses

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 Uses

func IsRunCompleted(status string) bool

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

func MakeSqliteDefault Uses

func MakeSqliteDefault(modelSqlitePath string) string

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

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

func OpenmppSchemaVersion Uses

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

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

func SelectFirst Uses

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 Uses

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

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

func TrxSelectFirst Uses

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 Uses

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 Uses

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

TrxUpdate execute sql query in transaction scope

func TrxUpdateStatement Uses

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 Uses

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

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

func UpdateLanguage Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

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

func UpdateProfileOption Uses

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

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

func UpdateRunDigest Uses

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

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

UpdateWorksetReadonly update workset readonly status.

func UpdateWorksetReadonlyByName Uses

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

UpdateWorksetReadonlyByName update workset readonly status by workset name.

func WriteOutputTable Uses

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 Uses

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 Uses

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

CellAcc is value of output table accumulator.

func (CellAcc) CsvFileName Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

CellAllAcc is value of multiple output table accumulators.

func (CellAllAcc) CsvFileName Uses

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

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

func (CellAllAcc) CsvHeader Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

type CellCodeAllAcc Uses

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

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

type CellCodeExpr Uses

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

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

type CellCodeParam Uses

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

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

func (CellCodeParam) CodeToIdCell Uses

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 Uses

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

CellExpr is value of output table expression.

func (CellExpr) CsvFileName Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

CellParam is value of input parameter.

func (CellParam) CsvFileName Uses

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

CsvFileName return file name of csv file to store parameter rows

func (CellParam) CsvHeader Uses

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 Uses

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

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

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

func (CellParam) CsvToIdRow Uses

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 Uses

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

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

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

func (CellParam) IdToCodeCell Uses

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 Uses

type CellToCodeConverter interface {

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

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

type CellToIdConverter Uses

type CellToIdConverter interface {

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

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

type CsvConverter Uses

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 or output table cell (dimensions and value)
    CsvToCell(modelDef *ModelMeta, name string, subCount int, valueName string) (
        func(row []string) (interface{}, error), error)
}

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

type DescrNote Uses

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

DescrNote is a holder for language code, descripriton and notes

type Facet Uses

type Facet uint8

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

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

func Open Uses

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

Open database connection.

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

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

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

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

If isFacetRequired is true then database facet determined

func (Facet) String Uses

func (facet Facet) String() string

String is default printable value of db facet, Stringer implementation

type FilterColumn Uses

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

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

type FilterIdColumn Uses

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

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

type FilterOp Uses

type FilterOp string

FilterOp is enum type for filter operators in select where conditions

type GroupLstPub Uses

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
}

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

type GroupLstRow Uses

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

GroupLstRow is db row of group_lst table

type GroupMeta Uses

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
}

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

func GetModelGroup Uses

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 Uses

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 Uses

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
}

GroupPcPub is "public" part of group_pc db row

type GroupPcRow Uses

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

GroupPcRow is db row of group_pc table

type GroupPub Uses

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
}

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

type GroupTxtRow Uses

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

GroupTxtRow is db row of group_txt table

type LangLstRow Uses

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

LangLstRow is db row of lang_lst table.

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

type LangMeta Uses

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

LangMeta is language and words in that language

func GetLanguages Uses

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 Uses

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

Clone return deep copy of source language metadata

func (*LangMeta) CodeById Uses

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 Uses

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

FromJson restore language list from json string bytes

func (*LangMeta) IdByCode Uses

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

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

type LangNote Uses

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

LangNote is a holder for language code and notes

type ModelDicRow Uses

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

ModelDicRow is db row of model_dic table.

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

func GetModelList Uses

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

GetModelList return list of the models: model_dic table rows.

type ModelMeta Uses

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
}

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

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

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

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

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

func GetModel Uses

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

GetModel return model metadata: parameters and output tables definition.

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

func GetModelById Uses

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 Uses

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

Clone return deep copy of source model metadata

func (*ModelMeta) FromJson Uses

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

FromJson restore model metadata list from json string bytes

func (*ModelMeta) OutTableByDigest Uses

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

OutTableByDigest return index of output table by digest

func (*ModelMeta) OutTableByHid Uses

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

OutTableByHid return index of output table by table Hid

func (*ModelMeta) OutTableByKey Uses

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

OutTableByKey return index of output table by key: tableId

func (*ModelMeta) OutTableByName Uses

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

OutTableByName return index of output table by name

func (*ModelMeta) OutTableHidById Uses

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

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

func (*ModelMeta) OutTableIdByHid Uses

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

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

func (*ModelMeta) ParamByDigest Uses

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

ParamByDigest return index of parameter by parameter digest

func (*ModelMeta) ParamByHid Uses

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

ParamByHid return index of parameter by parameter Hid

func (*ModelMeta) ParamByKey Uses

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

ParamByKey return index of parameter by key: paramId

func (*ModelMeta) ParamByName Uses

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

ParamByName return index of parameter by name

func (*ModelMeta) ParamHidById Uses

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

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

func (*ModelMeta) ParamIdByHid Uses

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

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

func (*ModelMeta) TypeByKey Uses

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

TypeByKey return index of type by key: typeId

type ModelTxtMeta Uses

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
}

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

func GetModelText Uses

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 Uses

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

ModelTxtRow is db row of model_dic_txt join to model_dic

func GetModelTextById Uses

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

GetModelTextById return model_dic_txt table rows by model id.

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

type ModelWordMeta Uses

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

ModelWordMeta is language-specific model_word db rows.

func GetModelWord Uses

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 Uses

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

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

type ParamDicRow Uses

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

ParamDicRow is db row of parameter_dic join to model_parameter_dic table

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

type ParamDimsRow Uses

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

ParamDimsRow is db row of parameter_dims join to model_parameter_dic table

type ParamDimsTxtRow Uses

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

ParamDimsTxtRow is db row of parameter_dims_txt join to model_parameter_dic table

type ParamMeta Uses

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
}

ParamMeta is parameter metadata: parameter name, type, dimensions

func (*ParamMeta) DimByKey Uses

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

DimByKey return index of parameter dimension by key: dimId

type ParamRunSetPub Uses

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

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

type ParamTxtRow Uses

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

ParamTxtRow is db row of parameter_dic_txt join to model_parameter_dic table

type ParamValuePub Uses

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

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

type ProfileMeta Uses

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

ProfileMeta is rows from profile_option table.

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

func GetProfile Uses

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 Uses

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

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

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

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

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

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

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

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

func ReadOutputTable Uses

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 Uses

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

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

func SelectToList Uses

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

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

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

type ReadParamLayout Uses

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

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

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

type ReadTableLayout Uses

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

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

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

type RunMeta Uses

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
    Progress []RunProgress     // run progress by sub-values: run_progress table rows
}

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

func GetRunFull Uses

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, run_progress rows.

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

func GetRunFullList Uses

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, run_progress rows.

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

func (*RunMeta) ToPublic Uses

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 Uses

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

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

Run status must be completed (success, exit or error) otherwise error returned. If this run already exist then nothing is updated in database, only metadata updated with actual run id. 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, run_stamp.

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

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

func (*RunMeta) UpdateRunText Uses

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

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

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

type RunParamTxtRow Uses

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

RunParamTxtRow is db row of run_parameter_txt

func GetRunAllParamText Uses

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

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

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

func GetRunParamText Uses

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

GetRunParamText return run parameter value notes: run_parameter_txt table rows.

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

type RunProgress Uses

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

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

func GetRunProgress Uses

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

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

type RunPub Uses

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
    RunStamp       string            // run_stamp     VARCHAR(32)  NOT NULL, -- process run stamp, by default is log time stamp
    Txt            []DescrNote       // run text: description and notes by language
    Opts           map[string]string // options used to run the model: run_option
    Param          []ParamRunSetPub  // run parameters: name, sub-value count and value notes by language
    Progress       []RunProgress     // run progress by sub-values: run_progress table rows
}

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

func (*RunPub) FromPublic Uses

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 Uses

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

RunRow is model run row: run_lst table row.

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

func GetFirstRun Uses

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

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

func GetLastCompletedRun Uses

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 Uses

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

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

func GetRun Uses

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

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

func GetRunByDigest Uses

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

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

func GetRunByDigestOrStampOrName Uses

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

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

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

func GetRunByName Uses

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

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

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

func GetRunByStamp Uses

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

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

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

func GetRunList Uses

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

GetRunList return list of model runs: run_lst rows.

type RunTxtRow Uses

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

RunTxtRow is db row of run_txt

func GetRunText Uses

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

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

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

type TableAccRow Uses

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

TableAccRow is db row of table_acc join to model_table_dic table

type TableAccTxtRow Uses

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

TableAccTxtRow is db row of table_acc_txt join to model_table_dic table

type TableDicRow Uses

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
}

TableDicRow is db row of table_dic join to model_table_dic table.

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

type TableDimsRow Uses

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

TableDimsRow is db row of table_dims join to model_table_dic table

type TableDimsTxtRow Uses

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

TableDimsTxtRow is db row of table_dims_txt join to model_table_dic table

type TableExprRow Uses

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

TableExprRow is db row of table_expr join to model_table_dic table

type TableExprTxtRow Uses

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

TableExprTxtRow is db row of table_expr_txt join to model_table_dic table

type TableMeta Uses

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

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

func (*TableMeta) DimByKey Uses

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

DimByKey return index of output table dimension by key: dimId

type TableTxtRow Uses

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

TableTxtRow is db row of table_dic_txt join to model_table_dic table

type TaskDef Uses

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

TaskDef is modeling task definition: metadata and input worksets

type TaskDefPub Uses

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

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

type TaskMeta Uses

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

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

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

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

func GetTaskFull Uses

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

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

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

func GetTaskFullList Uses

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

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

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

func GetTaskRunList Uses

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

GetTaskRunList return model run history: master row from task_lst and task_run_lst, task_run_set rows.

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

func (*TaskMeta) MergeTaskDef Uses

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

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

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

func (*TaskMeta) ReplaceTaskDef Uses

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

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

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

func (*TaskMeta) ToPublic Uses

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

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

func (*TaskMeta) UpdateTaskFull Uses

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

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

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

type TaskPub Uses

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

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

func (*TaskPub) FromPublic Uses

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 Uses

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

TaskRow is db row of task_lst.

func GetTask Uses

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 Uses

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

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

func GetTaskList Uses

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

GetTaskList return list of model tasks: task_lst rows.

type TaskRunRow Uses

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

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

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

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

func GetTaskFirstRun Uses

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

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

func GetTaskLastCompletedRun Uses

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 Uses

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

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

func GetTaskRun Uses

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

GetTaskRun return modeling task run status: task_run_lst table row.

func GetTaskRunByName Uses

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

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

func GetTaskRunByStamp Uses

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

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

func GetTaskRunByStampOrName Uses

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

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

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

type TaskRunSetRow Uses

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

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

type TaskRunSetTxt Uses

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

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

func GetTaskRunSetText Uses

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

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

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

type TaskTxtRow Uses

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

TaskTxtRow is db row of task_txt

type TypeDicRow Uses

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

TypeDicRow is db row of type_dic join to model_type_dic table.

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

func (*TypeDicRow) IsBool Uses

func (typeRow *TypeDicRow) IsBool() bool

IsBool return true if model type is boolean.

func (*TypeDicRow) IsBuiltIn Uses

func (typeRow *TypeDicRow) IsBuiltIn() bool

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

func (*TypeDicRow) IsFloat Uses

func (typeRow *TypeDicRow) IsFloat() bool

IsFloat return true if model type is float.

func (*TypeDicRow) IsInt Uses

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 Uses

func (typeRow *TypeDicRow) IsString() bool

IsString return true if model type is string.

type TypeEnumRow Uses

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

TypeEnumRow is db row of type_enum_lst join to model_type_dic table

type TypeEnumTxtRow Uses

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

TypeEnumTxtRow is db row of type_enum_txt join to model_type_dic table

type TypeMeta Uses

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

TypeMeta is type metadata: type name and enums

type TypeTxtRow Uses

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

TypeTxtRow is db row of type_dic_txt join to model_type_dic table

type WorksetHdrPub Uses

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

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

type WorksetMeta Uses

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

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

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

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

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

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

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

func GetWorksetFull Uses

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

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

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

func GetWorksetFullList Uses

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

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

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

func (*WorksetMeta) ToPublic Uses

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 Uses

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 Uses

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 Uses

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

WorksetParamTxtRow is workset_parameter_txt table row.

func GetWorksetAllParamText Uses

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

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

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

func GetWorksetParamText Uses

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

GetWorksetParamText return parameter value notes: workset_parameter_txt table rows.

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

type WorksetPub Uses

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

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

func (*WorksetPub) FromPublic Uses

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 Uses

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

WorksetRow is workset_lst table row.

func GetDefaultWorkset Uses

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 Uses

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

GetWorkset return working set by id: workset_lst table row.

func GetWorksetByName Uses

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

GetWorksetByName return working set by name.

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

func GetWorksetList Uses

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

GetWorksetList return list of model worksets: workset_lst rows.

type WorksetTxtRow Uses

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

WorksetTxtRow is db row of workset_txt

func GetWorksetText Uses

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

GetWorksetText return workset description and notes: workset_txt table rows.

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

type WorksetValuePub Uses

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

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

type WriteLayout Uses

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

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

Name is a parameter or output table name to read.

type WriteParamLayout Uses

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

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

type WriteTableLayout Uses

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

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

Package db imports 14 packages (graph) and is imported by 2 packages. Updated 2019-10-16. Refresh now. Tools for package owners.