Operations

Sometimes there is a need to execute raw SQL statements, unfortunately different ORMs provide different APIs to work with raw SQL. This feature creates an abstraction layer to execute raw SQL statements which will work with any supported ORM. It is used by all other Architect features internally and usually doesn’t need to be installed separately. However, if this is the only feature that will be used in the model it can be installed like this:

import architect

@architect.install('operation')
class Model(object):
    pass

API

After the installation operation feature can be accessed via Model.architect.operation. It provides the following methods:

execute(sql, autocommit=True)

Executes raw SQL for write operations.

Parameters:
  • sql (string) – (required). SQL statement to execute.
  • autocommit (boolean) – (optional). Turns autocommit on/off.
select_one(sql)

Executes raw SQL for read operations and returns a single result.

Parameters:sql (string) – (required). SQL statement to execute.
select_all(sql, as_dict=False)

Executes raw SQL for read operations and returns all results.

Parameters:
  • sql (string) – (required). SQL statement to execute.
  • as_dict (boolean) – (optional). Whether to return result as dict or as a list of tuples.