Package: laboro-database
gitea: none
include_toc: truelaboro_databaseThis is theLaboro database module. Its purpose is to provide a simplified interface to all major relational database types.It supports:PostgreSQLSQLite3MySQLThis module is intended to be used by theLaborois aNO-Code / Low-Codeworkflow manager.ClassesPublic classes provided by this package:Class:DatabaseModule:laboro_databasePackage:laboro_databasePurpose:Thelaboro_database.Databaseclass provides a simplified interface to all major relational database types.Arguments:NameTypeRequiredImpliesExcludeSecretDefaultusernamestrFalse-serviceTrueNonepasswordstrFalse-serviceTrueNonehoststrFalse-serviceFalseNoneportintFalse-serviceTrueNonedatabasestrFalse-serviceFalseNoneservicestrFalse-host-port-username-password-databaseFalseNonedb_typestrTrueFalseNotes:Thedb_typeargument must be one ofpgsql,sqliteormysql.Theserviceargument is used forPostgesql servicescan be used only withdb_typeset topgsql(seePotsgreSQLconnection service filefor further  details).Whendb_typeis set tosqlite:username,password,host,portandserviceare not usedthedatabaseargument must be the full file path to theSqlite3database.Instantiation examples:Postgresqlpackages:-laboro_databaseinstances:-name:management_databasemodule:laboro_databaseclass:Databaseargs:username:$crypt$gAAAAABi6IOvYj8lRMA76rCafoRBwjUk1SyHdCI0avhUyGsSUMHWhQw--nmJZSabdiKoQW4Yb4il6xtpB1jGdGqaNwmP0Lfn4A==password:$crypt$gAAAAABi6IOcLbBd1eAENaz8akV7yOagHxKyxlDATAkgcLHucD-uEHaZm-P7Ox1EN-6pkbEjm5lDFbkd860-kwgo-qT_qjM1QA==host:pgsql.example.comport:5432database:managementdb_type:pgsqlSqlite3packages:-laboro_databaseinstances:-name:users_databasemodule:laboro_databaseclass:Databaseargs:database:/opt/laboro/workspaces/my_workflow/users.dbdb_type:sqliteMethods provided by classlaboro_database.Database:Name:queryPurpose:This method allow to query the database.Arguments:NameTypeRequiredImpliesExcludeSecretDefaultrequeststrTrueFalseparamsdictFalseFalsecommitboolFalseFalseverboseboolFalseFalseFalseexit_on_errorboolFalseFalseTrueNotes:Therequestargument is a string that support variable substitution with named parameters. The variable substitution syntax depends on the chosendb_type.Theparamsdictionary may contain more parameters than needed butmustat least contain all needed parameters to fullfil therequeststring.Thecommitargument should be set toTruewhen the specifiedrequestinsert, update, delete database records.Method call examples:Postgresqlactions:instances:-name:users_databasemodule:laboro_databaseclass:Databaseargs:service:users_databasedb_type:pgsqlmethods:-instance:users_databasename:queryargs:request:select lastname, givenname, password from managers where role = %(role)sparams:role:adminoutput:admins_infoSqlite3actions:instances:-name:users_databasemodule:laboro_databaseclass:Databaseargs:database:/opt/laboro/workspaces/my_workflow/users.dbdb_type:sqlitemethods:-instance:users_databasename:queryargs:request:select lastname, givenname, password from managers where role = :roleparams:role:adminoutput:admins_infoMysqlactions:instances:-name:users_databasemodule:laboro_databaseclass:Databaseargs:username:$crypt$gAAAAABi6IOvYj8lRMA76rCafoRBwjUk1SyHdCI0avhUyGsSUMHWhQw--nmJZSabdiKoQW4Yb4il6xtpB1jGdGqaNwmP0Lfn4A==password:$crypt$gAAAAABi6IOcLbBd1eAENaz8akV7yOagHxKyxlDATAkgcLHucD-uEHaZm-P7Ox1EN-6pkbEjm5lDFbkd860-kwgo-qT_qjM1QA==host:mysql.example.comport:3306database:usersdb_type:mysqlmethods:-instance:users_databasename:queryargs:request:select lastname, givenname, password from managers where role = %(role)sparams:role:adminoutput:admins_infoName:multi_queryPurpose:This method allow to execute a query multiple times with different parameters.Arguments:NameTypeRequiredImpliesExcludeSecretDefaultrequeststrTrueFalseparamlistlistFalseFalsecommitboolFalseFalseverboseboolFalseFalseexit_on_errorboolFalseFalseNotes:Therequestargument is a string that support variable substitution with named parameters. The variable substitution syntax depends on the chosendb_type.Theparamlistis a list of dictionaries. Each dictionary in the list will be used once at a time with therequeststring.  Each dictionary may contain more parameters than needed butmustat least contain all needed parameters to fullfil therequeststring.Thecommitargument should be set toTruewhen the specifiedrequestinsert, update, delete database records. When set toTrue, a commit statement is sent to the databaseafter each request.Method call examples:methods:-instance:users_databasename:multi_queryargs:request:select lastname, givenname, password from managers where role = %(role)sparamlist:-role:admin-role:useroutput:admins_and_users_infoName:transactionPurpose:Prepare and execute as a single transaction multiple queries on the database.Arguments:NameTypeRequiredImpliesExcludeSecretDefaultrequestslistTrueFalseverboseboolFalseFalseexit_on_errorboolFalseFalseNotes:Therequestsargument is a list of 2 keyed dictionaries specifying a single request string (query) and its parameters (params) as described at theDatabase.querymethod.If one of the queries defined in therequestsargument fail, all requests within the transaction are roll backed.Method call examples:methods:-instance:users_databasename:transactionargs:requests:-query:select lastname, givenname, password from managers where role = %(role)sparams:-role:admin-query:update role from managers set role = %(new_role)s where role = %(old_role)sparams:-old_role:user-new_role:admin