Class s.d.AccessBroker(object):

Part of sasync.database View In Hierarchy

Known subclasses: sasync.items.Transactor, sasync.parray.Transactor, sasync.search.Search, sasync.test.test_database.AutoSetupBroker, sasync.test.test_database.MyBroker, sasync.test.test_orm.ObjectBroker

I manage asynchronous access to a database.

Before you use any instance of me, you must specify the parameters for creating an SQLAlchemy database engine. A single argument is used, which specifies a connection to a database via an RFC-1738 url. In addition, the following keyword options can be employed, which are listed below with their default values.

You can set an engine globally, for all instances of me via the sasync.engine package-level function, or via my engine class method. Alternatively, you can specify an engine for one particular instance by supplying the parameters to the constructor.

SQLAlchemy has excellent documentation, which describes the engine parameters in plenty of detail. See http://www.sqlalchemy.org/docs/dbengine.myt.
Instance VariablesdtA property-generated reference to a deferred tracker that you can use to wait for database writes. See misc.DeferredTracker.
qA property-generated reference to a threaded task queue that is dedicated to my database connection.
connectionThe current SQLAlchemy connection object, if any yet exists. Generated by my connect method.
Method __init__ Constructs an instance of me, optionally specifying parameters for an
Class Method engine Sets default connection parameters for all instances of me.
Method _getDeferredTracker Returns an instance of misc.DeferredTracker that is dedicated to the
Method _getQueue Returns a threaded task queue that is dedicated to my database
Method connect Generates and returns a singleton connection object.
Method _sessionClose Replacement close method for session objects.
Method getSession Get a commitable session object
Method table Instantiates a new table object, creating it in the transaction thread
Method startup This method runs before the first transaction to start my synchronous
Method userStartup If this method is defined and startup is not overridden in your
Method first This method automatically runs as the first transaction after
Method shutdown Shuts down my database transaction functionality and threaded task
Method s Polymorphic method for working with select instances within a cached
Method queryToList Executes my current select object with the bind parameters supplied as
Method deferToQueue Dispatches callable(*args, **kw) as a task via the like-named method
def __init__(self, *url, **kw):
Constructs an instance of me, optionally specifying parameters for an SQLAlchemy engine object that serves this instance only.
@classmethod
def engine(cls, url, **kw):
Sets default connection parameters for all instances of me.
def _getDeferredTracker(self):
Returns an instance of misc.DeferredTracker that is dedicated to the bound method's instance of me. Creates the deferred tracker the first time this method is called for a given instance of me.
def _getQueue(self):
Returns a threaded task queue that is dedicated to my database connection. Creates the queue the first time the property is accessed.
def connect(self, forceNew=False):
Generates and returns a singleton connection object.
def _sessionClose(self):
Replacement close method for session objects.
def getSession(self):
Get a commitable session object
def table(self, name, *cols, **kw):

Instantiates a new table object, creating it in the transaction thread as needed.

One or more indexes other than the primary key can be defined via a keyword prefixed with index_ or unique_ and having the index name as the suffix. Use the unique_ prefix if the index is to be a unique one. The value of the keyword is a list or tuple containing the names of all columns in the index.
def startup(self):

This method runs before the first transaction to start my synchronous task queue. Override it to get whatever pre-transaction stuff you have run.

Alternatively, with legacy support for the old API, your pre-transaction code can reside in a userStartup method of your subclass.
def userStartup(self):
overridden in sasync.search.Search

If this method is defined and startup is not overridden in your subclass, however, this method will be run as the first callback in the deferred processing chain, after my synchronous task queue is safely underway.

The method should return either an immediate result or a deferred to an eventual result.

Deprecated: Instead of defining this method, your subclass should simply override startup with your custom startup stuff.
def first(self):

This method automatically runs as the first transaction after completion of startup (or userStartup). Override it to define table contents or whatever else you want as a first transaction that immediately follows your pre-transaction stuff.

You don't need to decorate the method with @transact, but it doesn't break anything if you do.
def shutdown(self, *null):
Shuts down my database transaction functionality and threaded task queue, returning a deferred that fires when all queued tasks are done and the shutdown is complete.
def s(self, *args, **kw):
Polymorphic method for working with select instances within a cached selection subcontext.
  • When called with a single argument (the select object's name as a string) and no keywords, this method indicates if the named select object already exists and sets its selection subcontext to name.
  • With multiple arguments or any keywords, the method acts like a call to sqlalchemy.select(...).compile(), except that nothing is returned. Instead, the resulting select object is stored in the current selection subcontext.
  • With no arguments or keywords, the method returns the select object for the current selection subcontext.
def queryToList(self, **kw):
Executes my current select object with the bind parameters supplied as keywords, returning a list containing the first element of each row in the result.
def deferToQueue(self, func, *args, **kw):

Dispatches callable(*args, **kw) as a task via the like-named method of my synchronous queue, returning a deferred to its eventual result.

Scheduling of the task is impacted by the niceness keyword that can be included in **kw. As with UNIX niceness, the value should be an integer where 0 is normal scheduling, negative numbers are higher priority, and positive numbers are lower priority.
Unknown Field: keywordnicenessScheduling niceness, an integer between -20 and 20, with lower numbers having higher scheduling priority as in UNIX nice and renice.
API Documentation for sAsync, generated by pydoctor.