Documentation ¶
Index ¶
- Constants
- Variables
- func AddParam(name, sqlName string, params map[string]any, conds []string, ...) ([]string, []interface{})
- func CastInt(val interface{}) (int, error)
- func CastInt64(val interface{}) (int64, error)
- func CastString(val interface{}) (string, error)
- func CleanStatement(stm string) string
- func ConvertFloat(val string) string
- func Date() int64
- func DecodeValidatorError(r, err interface{}) error
- func Error(err error, code int, msg, function string) error
- func GetChunks(vals []string, limit int) []string
- func GetID(tx *sql.Tx, table, id, attr string, val ...interface{}) (int64, error)
- func GetRecID(tx *sql.Tx, rec DBRecord, table, id, attr string, val ...interface{}) (int64, error)
- func GetTestData() error
- func HttpClient(tout int) *http.Client
- func IfExist(tx *sql.Tx, table, rid, attr string, val ...interface{}) bool
- func IfExistMulti(tx *sql.Tx, table, rid string, args []string, vals ...interface{}) bool
- func IncrementSequence(tx *sql.Tx, seq string) (int64, error)
- func IncrementSequences(tx *sql.Tx, seq string, n int) ([]int64, error)
- func LastInsertID(tx *sql.Tx, table, idName string) (int64, error)
- func ListFiles(dir string) []string
- func LoadSQL(owner string) map[string]any
- func LoadTemplateSQL(tmpl string, tmplData map[string]any) (string, error)
- func OperatorValue(arg string) (string, string)
- func ParseDBFile(dbfile string) (string, string, string)
- func ParseRuns(runs []string) ([]string, error)
- func ParseTmpl(tdir, tmpl string, data interface{}) (string, error)
- func PrintSQL(stm string, args []interface{}, msg string)
- func QueryRow(table, id, attr string, val interface{}) (int64, error)
- func ReplaceBinds(stm string) string
- func RunsConditions(runs []string, table string) (string, []string, []interface{}, error)
- func TokenCondition() string
- func TokenGenerator(runs []string, limit int, name string) (string, []string)
- func TokenGeneratorORACLE(runs []string, limit int, name string) (string, []string)
- func TokenGeneratorSQLite(runs []string, name string) (string, []string)
- func WhereClause(stm string, conds []string) string
- type API
- func (a *API) DeleteBucket() error
- func (a *API) DeleteDataset() error
- func (a *API) DeleteFile() error
- func (a *API) DeleteParent() error
- func (a *API) DeleteProcessing() error
- func (a *API) DeleteSite() error
- func (a *API) GetBucket() error
- func (a *API) GetDataset() error
- func (a *API) GetFile() error
- func (a *API) GetParent() error
- func (a *API) GetProcessing() error
- func (a *API) GetSite() error
- func (a *API) InsertBucket() error
- func (a *API) InsertDataset() error
- func (a *API) InsertFile() error
- func (a *API) InsertParent() error
- func (a *API) InsertProcessing() error
- func (a *API) InsertSite() error
- func (a *API) String() string
- func (a *API) UpdateBucket() error
- func (a *API) UpdateDataset() error
- func (a *API) UpdateFile() error
- func (a *API) UpdateParent() error
- func (a *API) UpdateProcessing() error
- func (a *API) UpdateSite() error
- type Buckets
- type DBRecord
- type DBSError
- type DatasetRecord
- type Datasets
- type Files
- type Parents
- type Processing
- type Sites
Constants ¶
const ( GenericErrorCode = iota + 100 // generic DBS error DatabaseErrorCode // 101 database error TransactionErrorCode // 102 transaction error QueryErrorCode // 103 query error RowsScanErrorCode // 104 row scan error SessionErrorCode // 105 db session error CommitErrorCode // 106 db commit error ParseErrorCode // 107 parser error LoadErrorCode // 108 loading error, e.g. load template GetIDErrorCode // 109 get id db error InsertErrorCode // 110 db insert error UpdateErrorCode // 111 update error LastInsertErrorCode // 112 db last insert error ValidateErrorCode // 113 validation error PatternErrorCode // 114 pattern error DecodeErrorCode // 115 decode error EncodeErrorCode // 116 encode error ContentTypeErrorCode // 117 content type error ParametersErrorCode // 118 parameters error NotImplementedApiCode // 119 not implemented API error ReaderErrorCode // 120 io reader error WriterErrorCode // 121 io writer error UnmarshalErrorCode // 122 json unmarshal error MarshalErrorCode // 123 marshal error HttpRequestErrorCode // 124 HTTP request error MigrationErrorCode // 125 Migration error RemoveErrorCode // 126 remove error InvalidRequestErrorCode // 127 invalid request error BlockAlreadyExists // 128 block xxx already exists in DBS FileDataTypesDoesNotExist // 129 FileDataTypes does not exist in DBS FileParentDoesNotExist // 130 FileParent does not exist in DBS DatasetParentDoesNotExist // 131 DatasetParent does not exist in DBS ProcessedDatasetDoesNotExist // 132 ProcessedDataset does not exist in DBS PrimaryDatasetTypeDoesNotExist // 133 PrimaryDatasetType does not exist in DBS PrimaryDatasetDoesNotExist // 134 PrimaryDataset does not exist in DBS ProcessingEraDoesNotExist // 135 ProcessingEra does not exist in DBS AcquisitionEraDoesNotExist // 136 AcquisitionEra does not exist in DBS DataTierDoesNotExist // 137 DataTier does not exist in DBS PhysicsGroupDoesNotExist // 138 PhysicsGroup does not exist in DBS DatasetAccessTypeDoesNotExist // 139 DatasetAccessType does not exist in DBS DatasetDoesNotExist // 140 Dataset does not exist in DBS LastAvailableErrorCode // last available DBS error code )
DBS Error codes provides static representation of DBS errors, they cover 1xx range
Variables ¶
var ConcurrencyErr = errors.New("concurrency error")
ConcurrencyErr represents generic concurrency error
var ConcurrentBulkBlocks bool
ConcurrentBulkBlocks defines if code should use concurrent bulkblocks API
var ContentTypeErr = errors.New("content-type error")
ContentTypeErr represents generic content-type error
var DB *sql.DB
DB represents sql DB pointer
var DBOWNER string
DBOWNER represents DBS DB owner
var DBSQL map[string]any
DBSQL represents DBS SQL record
var DBTYPE string
DBTYPE represents DBS DB type, e.g. ORACLE or SQLite
var DRYRUN bool
DRYRUN allows to skip query execution and printout DB statements along with passed parameters
var DatabaseErr = errors.New("database error")
DatabaseErr represents generic database error
var FileLumiChunkSize int
FileLumiChunkSize controls chunk size for FileLumi list insertion
var FileLumiInsertMethod string
FileLumiInsertMethod controls which method to use for insertion of FileLumi list
var FileLumiMaxSize int
FileLumiMaxSize controls max size for FileLumi list insertion
var GenericErr = errors.New("dbs error")
GenericErr represents generic dbs error
var InvalidParamErr = errors.New("invalid parameter(s)")
InvalidParamErr represents generic error for invalid input parameter
var InvalidRequestErr = errors.New("invalid request error")
InvalidRequestErr represents generic invalid request error
var NotImplementedApiErr = errors.New("not implemented api error")
NotImplementedApiErr represents generic not implemented api error
var RecordErr = errors.New("record error")
RecordErr represents generic record error
var RecordValidator *validator.Validate
RecordValidator pointer to validator Validate method
var StaticDir string
StaticDir provides location of static directory
var Timeout int
Timeout represents DBS timeout used by HttpClient
var ValidationErr = errors.New("validation error")
ValidationErr represents generic validation error
var Verbose int
Verbose controls verbosity level
Functions ¶
func AddParam ¶
func AddParam( name, sqlName string, params map[string]any, conds []string, args []interface{}) ([]string, []interface{})
AddParam adds single parameter to SQL statement
func CastString ¶
CastString function to check and cast interface{} to string data-type
func CleanStatement ¶
CleanStatement cleans the given SQL statement to remove empty strings, etc.
func ConvertFloat ¶
ConvertFloat converts string representation of float scientific number to string int
func DecodeValidatorError ¶
func DecodeValidatorError(r, err interface{}) error
DecodeValidatorError provides uniform error representation of DBRecord validation errors
func GetRecID ¶
GetRecID function fetches table primary id for a given value and insert it if necessary
func GetTestData ¶
func GetTestData() error
GetTestData executes simple query to ensure that connection to DB is valid. So far we can ask for a data tier id of specific tier since this table is very small and query execution will be really fast.
func HttpClient ¶
HttpClient is HTTP client for urlfetch server
func IfExistMulti ¶
IfExistMulti checks if given rid exists in given table for provided value conditions
func IncrementSequence ¶
IncrementSequence API returns single unique ID for a given sequence
func IncrementSequences ¶
IncrementSequences API provide a way to get N unique IDs for given sequence name
func LastInsertID ¶
LastInsertID returns last insert id of given table and idname parameter
func LoadTemplateSQL ¶
LoadTemplateSQL function loads DBS SQL templated statements
func OperatorValue ¶
OperatorValue function generates operator and value pair for a given argument
func ParseDBFile ¶
ParseDBFile function parses given file name and extracts from it dbtype and dburi file should contain the "dbtype dburi" string
func ReplaceBinds ¶
ReplaceBinds replaces given pattern in string
func RunsConditions ¶
RunsConditions function to handle runs conditions
func TokenCondition ¶
func TokenCondition() string
TokenCondition provides proper condition statement for TokenGenerator
func TokenGenerator ¶
TokenGenerator creates a SQL token generator statement
func TokenGeneratorORACLE ¶
TokenGeneratorORACLE creates a SQL token generator statement using ORACLE syntax https://betteratoracle.com/posts/20-how-do-i-bind-a-variable-in-list
func TokenGeneratorSQLite ¶
TokenGeneratorSQLite creates a SQL token generator statement using SQLite syntax https://stackoverflow.com/questions/67372811/what-is-equivalent-of-token-generator-oracle-sql-statement-in-sqlite
func WhereClause ¶
WhereClause function construct proper SQL statement from given statement and list of conditions
Types ¶
type API ¶
type API struct { Reader io.Reader // reader to read data payload Writer http.ResponseWriter // writer to write results back to client Context context.Context // HTTP context ContentType string // HTTP content-type Params map[string]any // HTTP parameters, i.e. map of any data type Separator string // string separator for ndjson format CreateBy string // create by value from run-time Api string // api name }
API structure represents DBS API. Each API has reader (to read HTTP POST payload), HTTP writer to write results back to client, HTTP context, input HTTP GET paramers, separator for writer, create by and api string values passed at run-time.
func (*API) DeleteBucket ¶
DeleteBucket deletes bucket record in DB
func (*API) DeleteDataset ¶
func (*API) DeleteFile ¶
func (*API) DeleteParent ¶
DeleteParent deletes parent record in DB
func (*API) DeleteProcessing ¶
DeleteProcessing deletes processing record in DB
func (*API) InsertBucket ¶
InsertBucket inserts bucket record into DB
func (*API) InsertDataset ¶
func (*API) InsertFile ¶
func (*API) InsertParent ¶
InsertParent inserts parent record into DB
func (*API) InsertProcessing ¶
InsertProcessing inserts processing record into DB
func (*API) UpdateBucket ¶
UpdateBucket inserts bucket record in DB
func (*API) UpdateDataset ¶
func (*API) UpdateFile ¶
func (*API) UpdateParent ¶
UpdateParent inserts parent record in DB
func (*API) UpdateProcessing ¶
UpdateProcessing inserts processing record in DB
type Buckets ¶
type Buckets struct { BUCKET_ID int64 `json:"bucket_id"` BUCKET string `json:"bucket" validate:"required"` DATASET_ID int64 `json:"dataset_id" validate:"required"` CREATE_AT int64 `json:"create_at"` CREATE_BY string `json:"create_by"` MODIFY_AT int64 `json:"modify_at"` MODIFY_BY string `json:"modify_by"` }
Buckets represents Buckets DBS DB table
func (*Buckets) SetDefaults ¶
func (r *Buckets) SetDefaults()
SetDefaults implements set defaults for Buckets
type DBRecord ¶
type DBRecord interface { Insert(tx *sql.Tx) error // used to insert given record to DB Update(tx *sql.Tx) error // used to update given record to DB Validate() error // used to validate given record SetDefaults() // used to set proper defaults for given record Decode(r io.Reader) error // used to decode given record }
DBRecord interface represents general DB record used by DBS APIs. Each DBS API represents specific Table in back-end DB. And, each individual DBS API implements logic for its own DB records
type DBSError ¶
type DBSError struct { Reason string `json:"reason"` // error string Message string `json:"message"` // additional message describing the issue Function string `json:"function"` // DBS function Code int `json:"code"` // DBS error code Stacktrace string `json:"stacktrace"` // Go stack trace }
DBSError represents common structure for DBS errors
func (*DBSError) ErrorStacktrace ¶
ErrorStacktrace function implements details of DBS error message and stacktrace
type DatasetRecord ¶
type DatasetRecord struct { Did string `json:"did" validate:"required"` Buckets []string `json:"buckets" validate:"required"` Site string `json:"site" validate:"required"` Processing string `json:"processing" validate:"required"` Parent string `json:"parent" validate:"required"` Files []string `json:"files" validate:"required"` }
DatasetRecord represents input dataset record from HTTP request
type Datasets ¶
type Datasets struct { DATASET_ID int64 `json:"dataset_id"` DID string `json:"did" validate:"required"` SITE_ID int64 `json:"site_id" validate:"required"` PROCESSING_ID int64 `json:"processing_id" validate:"required"` PARENT_ID int64 `json:"parent_id" validate:"required"` CREATE_AT int64 `json:"create_at" validate:"required,number"` CREATE_BY string `json:"create_by" validate:"required"` MODIFY_AT int64 `json:"modify_at" validate:"required,number"` MODIFY_BY string `json:"modify_by" validate:"required"` }
Datasets represents Datasets DBS DB table
func (*Datasets) SetDefaults ¶
func (r *Datasets) SetDefaults()
SetDefaults implements set defaults for Datasets
type Files ¶
type Files struct { FILE_ID int64 `json:"file_id"` FILE string `json:"file" validate:"required"` IS_FILE_VALID int64 `json:"is_file_valid" validate:"number"` DATASET_ID int64 `json:"dataset_id" validate:"number,gt=0"` CREATE_AT int64 `json:"create_at" validate:"required,number,gt=0"` CREATE_BY string `json:"create_by" validate:"required"` MODIFY_AT int64 `json:"modify_at" validate:"required,number,gt=0"` MODIFY_BY string `json:"modify_by" validate:"required"` }
Files represents Files DBS DB table
func (*Files) SetDefaults ¶
func (r *Files) SetDefaults()
SetDefaults implements set defaults for Files
type Parents ¶
type Parents struct { PARENT_ID int64 `json:"parent_id"` PARENT string `json:"parent" validate:"required"` CREATE_AT int64 `json:"create_at"` CREATE_BY string `json:"create_by"` MODIFY_AT int64 `json:"modify_at"` MODIFY_BY string `json:"modify_by"` }
Parents represents Parents DBS DB table
func (*Parents) SetDefaults ¶
func (r *Parents) SetDefaults()
SetDefaults implements set defaults for Parents
type Processing ¶
type Processing struct { PROCESSING_ID int64 `json:"processing_id"` PROCESSING string `json:"processing" validate:"required"` CREATE_AT int64 `json:"create_at"` CREATE_BY string `json:"create_by"` MODIFY_AT int64 `json:"modify_at"` MODIFY_BY string `json:"modify_by"` }
Processing represents Processing DBS DB table
func (*Processing) Decode ¶
func (r *Processing) Decode(reader io.Reader) error
Decode implementation for Processing
func (*Processing) Insert ¶
func (r *Processing) Insert(tx *sql.Tx) error
Insert implementation of Processing
func (*Processing) SetDefaults ¶
func (r *Processing) SetDefaults()
SetDefaults implements set defaults for Processing
func (*Processing) Update ¶ added in v0.0.3
func (r *Processing) Update(tx *sql.Tx) error
Update implementation of Processing
func (*Processing) Validate ¶
func (r *Processing) Validate() error
Validate implementation of Processing
type Sites ¶
type Sites struct { SITE_ID int64 `json:"site_id"` SITE string `json:"site" validate:"required"` CREATE_AT int64 `json:"create_at"` CREATE_BY string `json:"create_by"` MODIFY_AT int64 `json:"modify_at"` MODIFY_BY string `json:"modify_by"` }
Sites represents Sites DBS DB table
func (*Sites) SetDefaults ¶
func (r *Sites) SetDefaults()
SetDefaults implements set defaults for Sites