| | |
- builtins.object
-
- CBWrapper
- threading.Thread(builtins.object)
-
- DBAPI
- _DBAPIManager
class CBWrapper(builtins.object) |
| |
Wrapper class just in case DB callback occurs after the script is unloaded. To use just create an object of this class and set unloaded to True upon unload. |
| |
Methods defined here:
- __init__(self)
- cb(self, cb)
- Use this function to wrap a class.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class DBAPI(threading.Thread) |
| | |
- Method resolution order:
- DBAPI
- threading.Thread
- builtins.object
Methods defined here:
- __init__(self, driver=None, sleep=1, traise=False, loglevel=40, logfile=None, on_connect_queries=(), debug=1, *args, **kwargs)
- Creates a threaded MySQL helper class.
@driver - DBAPI Driver to use. (Default: auto)
Supported drivers (others might work too):
sqlite3
pymysql
@sleep - How often it should check whether new queries were added to the queue in seconds. (Default: 1)
@traise - If false, don't raise exceptions in threads but send the error to the console. (Default: False)
@loglevel - Errorlevel to use
@on_connect_queries - Iterable of queries to execute when connected to the server
@debug - Extended error checking
Raises ImportError if no valid driver is detected.
- change_logfile(self, newfile)
- connect(self, *args, **kwargs)
- Connects to the MySQL server.
This function will directly pass any arguments or keyword arguments to the driver's connect function.
See help on pymysql.connect or MySQLdb.connect for more info.
- disconnect(self)
- Disconnects from the database.
This will continue executing any remaining queries in the queue before actually closing the connection.
- execute(self, query, *args)
- Executes a query.
This is NOT threaded.
@query - The SQL query to execute
@args - Arguments to insert into the query
- get_connection(self)
- get_cursor(self)
- get_driver(self)
- # Intended for public use
- run(self)
- Do not call this function
- texecute(self, query, args=(), callback=None, params=(), kwparams={})
- Appends a query to the query queue. This is threaded and will not halt the server.
Does extensive type checks with debug enabled. Otherwise make sure the params are of the correct type or
the queue might break.
@query - The SQL query to execute
@args - Arguments to insert into the query (Default: empty list)
@callback - Function to be called once the query was successful.
The function must have at least 1 paramater in which the results of the query will be stored (as received by fetchall()).
(Default: None)
@params - Additional function parameters (Default: empty list)
@kwparams - Additional keyword function parameters (Default: empty dictionary)
Methods inherited from threading.Thread:
- __repr__(self)
- getName(self)
- isAlive = is_alive(self)
- isDaemon(self)
- is_alive(self)
- join(self, timeout=None)
- setDaemon(self, daemonic)
- setName(self, name)
- start(self)
Data descriptors inherited from threading.Thread:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- daemon
- ident
- name
|
class _DBAPIManager(threading.Thread) |
| |
Don't call any of the thread methods. It may cause unexpected behaviour. |
| |
- Method resolution order:
- _DBAPIManager
- threading.Thread
- builtins.object
Methods defined here:
- __init__(self)
- create_object(self, name, *args, **kwargs)
- Creates a named DBAPI object.
Creating a named DBAPI object is useful to retrive it upon script reloading and if running 2 sperate threads is an issue. For example, upon reload your script might rely on properly writing the old data to the database, however if 2 threads are running you might end up writing and getting data from the db at the same time.
To circumvent this issue you can a named object; at a later point you can retrive the object as long it is still alive and executing SQL queries.
@name - internal name of the DBAPI object, must be unique
Raises KeyError if the object already exists
- delete_object(self, name)
- Reduces the refcount to the specified DBAPI object by one.
If the refcount hits 0 it will be deleleted automatically once all commands are executed and the connection will be seperated
@name - internal name of the DBAPI object
Raises KeyError if the object is not found
- get_object(self, name)
- Increases the refcount to the specified DBAPI object by one.
@name - internal name of the DBAPI object
Returns the sql object if found
Returns False if the sql object is dead
Returns False otherwise
- run(self)
- DO NOT CALL THIS METHOD!
Removes dead MySQL objects.
Sets MySQL objects inactive / disconnects them if ref count reaches 0.
Methods inherited from threading.Thread:
- __repr__(self)
- getName(self)
- isAlive = is_alive(self)
- isDaemon(self)
- is_alive(self)
- join(self, timeout=None)
- setDaemon(self, daemonic)
- setName(self, name)
- start(self)
Data descriptors inherited from threading.Thread:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- daemon
- ident
- name
| |