gino.bakery module

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

基类: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.

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.

参数

options -- Multiple execution options.

返回

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.

参数

_ -- 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

基类: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().

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.

参数
  • 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.

返回

A BakedQuery instance.

query_cls

alias of gino.bakery.BakedQuery