Python: package ichorORM

ichorORM (version 1.0.2) | index

`Copyright (c) 2016-2018 Timothy Savannah
Licensed under the terms of the Lesser GNU Lesser General Public License version 2.1
license can be found at https://raw.githubusercontent.com/kata198/ichorORM/master/LICENSE
ichorORM - An ORM and query-builder for postgresql / psycopg2 with a focus on performance`

Package Contents
`` |  |
WhereClause connection | constants model | objs query | utils

Classes
`` |  | builtins.Exception(builtins.BaseException) ichorORM.connection.DatabaseConnectionFailure builtins.object ichorORM.connection.DatabaseConnection ichorORM.model.DatabaseModel
class DatabaseConnection(builtins.object)
`` | `DatabaseConnection - Manages connections to the postgresql database`
| Methods defined here: __init__(self, host=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251240>, dbname=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251240>, user=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251240>, password=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251240>, isTransactionMode=False) `__init__ - Create a DatabaseConnection object @param host <str/None/UseGlobalSetting> Default UseGlobalSetting - IP or hostname to postgresql server. If left at default UseGlobalSetting, the global value will be used. Use "None" to not provide this element when connecting, otherwise give a value to use. @param dbname <str/None/UseGlobalSetting> Default UseGlobalSetting - Name of database to use If left at default UseGlobalSetting, the global value will be used. Use "None" to not provide this element when connecting, otherwise give a value to use. @param user <str/None/UseGlobalSetting> Default UseGlobalSetting - Username to use If left at default UseGlobalSetting, the global value will be used. Use "None" to not provide this element when connecting, otherwise give a value to use. @param password <str/None/UseGlobalSetting> Default UseGlobalSetting - Password to use If left at default UseGlobalSetting, the global value will be used. Use "None" to not provide this element when connecting, otherwise give a value to use. @param isTransactionMode <bool> default False, whether or not to default this connection to using transactions. If False, autocommit is enabled.` closeConnection(self) `closeConnection - Close the database connection` commit(self) `commit - Commit whatever is on the current connection` commitTransaction(self) `commitTransaction - Commit the current in-progress transaction. Requires transaction mode to be on, @see #startTransactionMode` doInsert(self, query, valueDicts, autoCommit=True, returnPk=True) `doInsert - Perform an INSERT query with a parameterized query @param query - Query string. For fields, e.x. "name" and "value": INSERT INTO mytable (name, number) VALUES ( %(name)s , %(value)s ) @param valueDicts - A list of dicts, where each dict key = column name and value = column value. So with above example select, valueDicts might be: [ { 'name' : 'Jimbo' , 'value' : 18 }, { 'name' : 'Timbob', 'value' : 3033 }, ] which would cause the insert line to be executed twice, once for each row to be inserted (element in the list) @param autoCommit - If True, will commit after this transaction. @param returnPk <bool> - If True, will return the primary key(s) inserted @return list<int> - if returnPk is True, otherwise None` doSelect(self, query) `doSelect - Perform a SELECT query and return all the rows. Results are ordered by SELECT order @param list<tuple> - List of rows, each tuple of cols` doSelectParams(self, query, params) endTransactionMode(self) `endTransactionMode - Disable transaction mode. This will enable autocommit on future connections, and closes current connection. @see #startTransactionMode to re-enable transaction mode` executeSql(self, query) `executeSql - Execute arbitrary SQL. @param query <str> - SQL query to execute No return. Maybe can guage number of rows returned etc` executeSqlParams(self, query, params) `executeSqlParams - Execute arbitary SQL with parameterized values @param query <str> - SQL Query @param params <dict> - Params to pass, %(name)s should have an entry "name"` getConnection(self, forceReconnect=False) `getConnection - Return a psycopg2 connection based on connection info on this object. Will reuse existing connection, if present. @param forceReconnect <bool> default False - If True, will force the connection to be re-established @return < None/ psycopg2.connection object> - Connection, if successful, otherwise None` getCursor(self, forceReconnect=False) `getCursor - Gets a psycopg cursor to the database @param forceReconnect <bool> - Default False, if True will force the connection to be re-established @return psycopg2.cursor object` rollback(self) `rollback - rollback whatever transaction is on the current connection` startTransactionMode(self) `startTransactionMode - Set transaction mode. This disables autocommit on future connection, and closes current connection. @see #commitTransaction to commit the current transaction @see #endTransactionMode to unset transaction mode` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class DatabaseConnectionFailure(builtins.Exception)
`` | `Common base class for all non-exit exceptions.`
| Method resolution order: DatabaseConnectionFailure builtins.Exception builtins.BaseException builtins.object Data descriptors defined here: __weakref__ `list of weak references to the object (if defined)` Methods inherited from builtins.Exception: __init__(self, /, *args, **kwargs) `Initialize self. See help(type(self)) for accurate signature.` __new__(*args, **kwargs) from builtins.type `Create and return a new object. See help(type) for accurate signature.` Methods inherited from builtins.BaseException: __delattr__(self, name, /) `Implement delattr(self, name).` __getattribute__(self, name, /) `Return getattr(self, name).` __reduce__(...) `helper for pickle` __repr__(self, /) `Return repr(self).` __setattr__(self, name, value, /) `Implement setattr(self, name, value).` __setstate__(...) __str__(self, /) `Return str(self).` with_traceback(...) `Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.` Data descriptors inherited from builtins.BaseException: __cause__ `exception cause` __context__ `exception context` __dict__ __suppress_context__ __traceback__ args
class DatabaseModel(builtins.object)
`` | `DatabaseModel - Models should extend this`
| Methods defined here: __init__(self, **kwargs) `__init__ - Create an object of this type. Arguments are in form of fieldName=fieldValue` __repr__(self) `__repr__ - Get object representation of this instance @return <str> - A descriptive string of this object` asDict(self, includePk=True) `asDict - Return a dict representation of this model` delete(self, dbConn=None) `delete - Delete current object. Should generally NOT be used, instead things should be "archived" to the best of ability. Will clear the primary key field on this object. If object is already deleted, this will return None @param dbConn <None/DatabaseConnection> Default None- A specific DatabaseConnection to use, if None generate a new connection with global settings @return - Old ID` insertObject(self, dbConn=None, doCommit=True) `insertObject - Inserts current object @param dbConn <None/DatabaseConnection> Default None- A specific DatabaseConnection to use, if None generate a new connection with global settings @param doCommit <bool> default True - If True, will commit upon insert. If False, you must call dbConn.commitTransaction yourself when ready. Primary key is set either way. If doCommit is False, dbConn must be specified (obviously, so you can commit later) Will raise exception if object is already saved, or a REQUIRED_FIELDS is not present.` updateObject(self, updateFieldNames, dbConn=None, doCommit=True) `updateObject - Performs an UPDATE on a given list of field names, based on value held on current object. @param updateFieldNames < list<str> > - A list of field names to update. @param dbConn <None/DatabaseConnection> Default None- A specific DatabaseConnection to use, if None generate a new connection with global settings @param doCommit <bool> default True - If True, will commit upon insert. If False, you must call dbConn.commitTransaction yourself when ready. Primary key is set either way. If doCommit is False, dbConn must be specified (obviously, so you can commit later) Will raise exception if current object is not saved.` Class methods defined here: all(orderByField=None, orderByDir='', dbConn=None) from builtins.type `all - Get all objects associated with this model @param orderByField <None/str> Default None, if provided the list returned will be ordered by this sql field @param orderByDir <str> Default empty string, if provided the list will be ordered in this direction (DESC or ASC) @param dbConn <None/DatabaseConnection> Default None- A specific DatabaseConnection to use, if None generate a new connection with global settings @return list<DatabaseModel> - A list of all objects in the database for this model` createAndSave(replaceSpecialValues=True, dbConn=None, **kwargs) from builtins.type `createAndSave - Creates an object of this type and saves it. Parameters are the fieldName=fieldValue for this model. At least all entries in REQUIRED_FIELDS must be present! @param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() ) with their calculated value. @see QueryBase.replaceSpecialValues for more info. @param dbConn <None/DatabaseConnection> Default None- A specific DatabaseConnection to use, if None generate a new connection with global settings @return - An object of this model's type` filter(whereType='AND', dbConn=None, **kwargs) from builtins.type `filter - Filter and return objects of this type @param whereType <WHERE_AND/WHERE_OR> - Whether filter criteria should be AND or OR'd together @param dbConn <DatabaseConnection/None> default None- If present and not None, will use this as the postgres connection. Otherwise, will start a new connection based on global settings Optionals: @param orderByField - If present, results will be ordered using this field @param orderByDir - If present, ordered results will follow this direction All other parameters should be in the form "fieldName=value" for equality comparison, otherwise fieldName should end with __OPERATION, e.x. fieldName__ne=value for not-equals, fieldName__like="Start%End" for like, etc. @return list<objs> - List of objects of this model type` get(_pk, dbConn=None) from builtins.type `get - Gets a single object of this model type by primary key (id) @param _pk <str/int> - Value of primary key" @param dbConn <None/DatabaseConnection> Default None- A specific DatabaseConnection to use, if None generate a new connection with global settings @return object of this type with all fields populated` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)` Data and other attributes defined here: DEFAULT_FIELD_VALUES = {} FIELDS = [] PRIMARY_KEY = 'id' REQUIRED_FIELDS = [] SERIAL_PRIMARY_KEY = True TABLE_NAME = None

Functions
`` |  | getDatabaseConnection(host=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251240>, dbname=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251240>, user=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251240>, password=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251240>, isTransactionMode=False) `getDatabaseConnection - Gets a database connection. Should use this instead of creating a DatabaseConnection manually, to ensure ease of refactoring (like if we introduce connection pooling, global connections, etc) @see DatabaseConnection.__init__ for arguments @return DatabaseConnection object` setGlobalConnectionParams(host=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251208>, dbname=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251208>, user=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251208>, password=<ichorORM.objs.IgnoreParameterType object at 0x7f201a251208>) `setGlobalConnectionParams - Sets the global connection parameters which will be used by default for connections to postgresql. Every parameter defaults to "IgnoreParameter" and will thus not be set unless specified to be something different. i.e. to change the database with which to connect, you can call just: setGlobalConnectionParams( dbname="blah" ) without upsetting the existing host, username, etc. @param host <str> default IgnoreParameter - The hostname/ip with which to connect @param dbname <str> default IgnoreParameter - The database name with which to USE @param user <str/None> default IgnoreParameter - The username with which to use. Use None (the default state) to not provide a username. @param password <str> default IgnoreParameter - The password with which to use Use None (the default state) to not provide a password.`

Data
`` |  | __all__ = ('setGlobalConnectionParams', 'getDatabaseConnection', 'DatabaseConnection', 'DatabaseConnectionFailure', 'DatabaseModel') __version_int_tuple__ = (1, 0, 2) __version_tuple__ = ('1', '0', '2')