SQLAlchemyLiteProxy
ClassSource
db_proxy = SQLAlchemyLiteProxy[_SQLAlchemyDB_co](
db: _SQLAlchemyLiteDB_co,
)
Proxy class of flask_sqlalchemy_lite.SQLAlchemy
.
This class is a wrapper of the regular SQLAlchemy. By adjusting the behavior of
the flask_sqlalchemy.SQLAlchemy
, it can mimic the usage of
flask_sqlalchemy_lite.SQLAlchemy
.
Note that not all the functionalities of this proxy can be
exactly the same as the those of flask_sqlalchemy_lite.SQLAlchemy
. In specific,
this proxy will do the following things:
- Provide a regular session like that of
flask_sqlalchemy_lite.SQLAlchemy
. This regular session is managed by the instance of this proxy class. - Provide other basic methods in
flask_sqlalchemy_lite.SQLAlchemy
. The usages would be equivalent but the implmentation is based onflask_sqlalchemy
. - Any functionality that cannot be used will raise a
NotImplementedError
.
Aliases
This class can be acquired by
import flask_sqlalchemy_compat as fsc
fsc.SQLAlchemyLiteProxy
fsc.flask_sa_lite_api.SQLAlchemyLiteProxy
Arguments
Argument | Type | Required | |
---|---|---|---|
db | _SQLAlchemyDB_co | The database instance exporting the session and engine instances. It is provided by the Flask extensions like |
- where
_SQLAlchemyDB_co
is aTypeVar
offsc.protocols.SQLAlchemyProtocol
.
Methods
init_app
db_proxy.init_app(
app: Flask,
)
Register the extension on an application, creating engines from its
Flask.config
.
Requires
Argument | Type | Required | |
---|---|---|---|
app | Flask | The application to register. |
get_engine
db_proxy.get_engine(
name: str = "default"
)
Get a specific engine associated with the current application.
The engine
attribute is a shortcut for calling this without an
argument to get the default engine.
Requires
Argument | Type | Required | |
---|---|---|---|
name | str | The name associated with the engine. |
Returns
Argument | Type | |
---|---|---|
engine | sa.engine.Engine | The engine gotten by the name. |
get_session
sess: sa.orm.Session = db_proxy.get_session(
name: str = "default"
)
Create a sa.orm.Session
that will be closed at the end of the application
context. Repeated calls with the same name within the same application context
will return the same session.
The session
attribute is a shortcut for calling this without an argument to
get the default session.
Requires
Argument | Type | Required | |
---|---|---|---|
name | str | A unique name for caching the session. |
Returns
Argument | Type | |
---|---|---|
sess | sa.orm.Session | The session gotten by the name. |
get_async_engines
db_proxy.get_async_engines(*args: Any, **kwargs: Any)
This method is not implemented by the proxy.
get_async_session
db_proxy.get_async_session(*args: Any, **kwargs: Any)
This method is not implemented by the proxy.
Properties
db
db: _SQLAlchemyDB_co = db_proxy.db
The db
instance provided by the Flask SQLAlchemy extension.
sessionmaker
sessionmaker: sa.orm.sessionmaker[sa.orm.Session] = db_proxy.sessionmaker
The same as flask_sqlalchemy_lite.SQLAlchemy().sessionmaker
.
The session factory configured for the current application. This can
be used to create sessions directly, but they will not be closed
automatically at the end of the application context. Use session
and get_session
for that.
This can also be used to update the session options after
self.init_app
, by calling its sa.orm.sessionmaker.configure
method.
session
sess: sa.orm.Session = db_proxy.session
The same as flask_sqlalchemy_lite.SQLAlchemy().session
.
The default session for the current application context. It will be closed when the context ends.
engines
engines: dict[str, sa.engine.Engine] = db_proxy.engines
The same as flask_sqlalchemy_lite.SQLAlchemy().engines
.
The dictionary of named engines registered to this extension.
engine
engine: sa.engine.Engine = db_proxy.engine
The same as flask_sqlalchemy_lite.SQLAlchemy().engine
.
The default engine associated with the current application.
async_engines
db_proxy.async_engines
This property is not implemented by the proxy.
async_engine
db_proxy.async_engine
This property is not implemented by the proxy.
async_sessionmaker
db_proxy.async_sessionmaker
This property is not implemented by the proxy.
async_session
db_proxy.async_session
This property is not implemented by the proxy.