gino.bakery module

class gino.bakery.BakedQuery(elem, metadata, hash_=None)

Bases: gino.api.GinoExecutor

Represents a pre-compiled and possibly prepared query for faster execution.

BakedQuery is created by Bakery.bake(), and can be executed by GinoEngine or GinoConnection. If there is a proper bind in the baked query, contextual execution APIs inherited from GinoExecutor can also be used.

New in version 1.1.

property bind

Internal API to provide a proper bind if found.

property compiled_sql

Internal API to get the SQLAlchemy compiled sql context.

execution_options(**kwargs)

Set execution options on a shadow query of this baked query.

The execution options set in this method won’t affect the execution options in the baked query.

Read execution_options() for more information.

Parameters

options – Multiple execution options.

Returns

A shadow of the baked query with new execution options but still functions as a baked query.

get(_)

Internal API to get the compiled_sql.

Parameters

_ – Ignored.

property query

Internal API to get the query instance before compilation.

property sql

Internal API to get the compiled raw SQL.

class gino.bakery.Bakery

Bases: object

Factory and warehouse of baked queries.

You may provide a bakery to a GinoEngine during creation as the bakery keyword argument, and the engine will bake the queries and create corresponding prepared statements for each of the connections in the pool.

A Gino instance has a built-in bakery, it’s automatically given to the engine during set_bind() or with_bind().

New in version 1.1.

bake(func_or_elem=None, **execution_options)

Bake a query.

You can bake raw SQL strings or SQLAlchemy Core query instances. This method adds the given query into a queue in the bakery, and bakes it only when the bakery is set to an GinoEngine from which the bakery could learn about the SQL dialect and compile the queries into SQL. Once done, the bakery is “closed”, you can neither give it to another engine, nor use it to bake more queries.

Parameters
  • func_or_elem – A str or a SQLAlchemy Core query instance, or a function that returns such results.

  • execution_options – Shortcut to add SQLAlchemy execution options to the query.

Returns

A BakedQuery instance.

query_cls

alias of BakedQuery