10.5. Module db

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

Classes

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

The class of access to remote Cerebro database.

Methods

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]
Parameters:
  • query (string) – SQL query string.
  • parameters – query parameters.
Returns:

query result.

Return type:

list(tuple,)

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]
Parameters:
  • 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).

is_connected()[source]
Returns:True, if connection to database is established.
Return type:bool
url()[source]
Returns:string locator of a remote database.
Return type:string
cerebro.db.json_serial(obj)[source]

json serializer for unsupported by default types.