10.5. Module db

The cerebro.db module provides access to remote database for SQL queries execution.


class cerebro.db.Db(db_timeout=5, db_reconn_count=3)[source]

The class of access to remote Cerebro database.


You can work with Cerebro database directly, executing SQL read/write queries.

The access to the data is provided by means of procedures stored on the database side. See more detailed info on the procedures in the Memoria database SQL API chapter.

db = cerebro.db.Db()
res = db.execute('select "listProjects_01"(%s,%s)', false, true) # executing a query to get a list of projects
print('The list of projects', res) # printing the result
execute(query, *parameters)[source]
  • query (string) – SQL query string.
  • parameters – query parameters.

query result.

Return type:


Executes the query and returns the result as a list of tuples.

The query arguments have the format %s.

db = cerebro.db.Db()
projects = db.execute('select "listProjects_01"(%s,%s)', false, true) # executing a query to get a list of projects
print('Список проектов', projects) # printing the result        
db = cerebro.db.Db()
# executing a query to set task progress to 50%
projects = db.execute('select "taskSetProgress_a"(%s,%s)', {task_id,}, 50)                      
execute_rpc(read_only, query, *parameters)[source]
  • read_only (bool) – check if query only reads data from DB.
  • query (string) – query text.
  • parameters – query parameters list.

Executes the query and returns the result. The result has a form of a table (list pf tuples).

Returns:True, if connection to database is established.
Return type:bool
Returns:string locator of a remote database.
Return type:string

json serializer for unsupported by default types.