zask.ext.sqlalchemy package¶
Module contents¶
zask.ext.sqlalchemy¶
Adds basic SQLAlchemy support to your application. I have not add all the feature, bacause zask is not for web, The other reason is i can’t handle all the features right now :P
Differents between Flask-SQLAlchemy:
- No default
scopefuncit means that you need define how to separate sessions your self - No signal session
- No query record
- No pagination and HTTP headers, e.g.
get_or_404 - No difference between app bound and not bound
| copyright: |
|
|---|---|
| license: | BSD, see LICENSE for more details. |
| copyright: |
|
| license: | BSD, see LICENSE for more details. |
-
class
zask.ext.sqlalchemy.BindSession(db, autocommit=False, autoflush=True, **options)[source]¶ Bases:
sqlalchemy.orm.session.SessionThe BindSession is the default session that Zask-SQLAlchemy uses. It extends the default session system with bind selection. If you want to use a different session you can override the
SQLAlchemy.create_session()function.-
app= None¶ The application that this session belongs to.
-
-
class
zask.ext.sqlalchemy.Model[source]¶ Bases:
objectBaseclass for custom user models.
-
query= None¶ an instance of
query_class. Can be used to query the database for instances of this model.
-
-
class
zask.ext.sqlalchemy.SQLAlchemy(app=None, use_native_unicode=True, session_options=None)[source]¶ Bases:
objectThis class is used to control the SQLAlchemy integration to one or more Zask applications.
There are two usage modes which work very similarly. One is binding the instance to a very specific Zask application:
app = Zask(__name__) db = SQLAlchemy(app)
The second possibility is to create the object once and configure the application later to support it:
db = SQLAlchemy() def create_app(): app = Zask(__name__) db.init_app(app) return app
This class also provides access to all the SQLAlchemy functions and classes from the
sqlalchemyandsqlalchemy.ormmodules. So you can declare models like this:class User(db.Model): username = db.Column(db.String(80), unique=True) pw_hash = db.Column(db.String(80))
-
apply_driver_hacks(app, info, options)[source]¶ This method is called before engine creation and used to inject driver specific hacks into the options. The options parameter is a dictionary of keyword arguments that will then be used to call the
sqlalchemy.create_engine()function.The default implementation provides some saner defaults for things like pool sizes for MySQL and sqlite. Also it injects the setting of SQLALCHEMY_NATIVE_UNICODE.
-
create_scoped_session(options=None)[source]¶ Helper factory method that creates a scoped session. It internally calls
create_session().
-
create_session(options)[source]¶ Creates the session. The default implementation returns a
BindSession.
-
engine¶ Gives access to the engine. If the database configuration is bound to a specific application (initialized with an application) this will always return a database connection. If however the current application is used this might raise a
RuntimeErrorif no application is active at the moment.
-
get_app(reference_app=None)[source]¶ Helper method that implements the logic to look up an application.
-
get_binds(app=None)[source]¶ Returns a dictionary with a table->engine mapping.
This is suitable for use of sessionmaker(binds=db.get_binds(app)).
-
init_app(app)[source]¶ This callback can be used to initialize an application for the use with this database setup. Never use a database in the context of an application not initialized that way or connections will leak.
-
metadata¶ Returns the metadata
-