| | |
- builtins.object
-
- FilterType
-
- FilterField
-
- FilterJoin
- FilterStage
- QueryBase
-
- DeleteQuery
- InsertQuery
- SelectQuery
-
- SelectGenericJoinQuery
- SelectInnerJoinQuery
- UpdateQuery
- builtins.str(builtins.object)
-
- QueryStr
class DeleteQuery(QueryBase) |
| |
DeleteQuery - Perform a delete |
| |
- Method resolution order:
- DeleteQuery
- QueryBase
- builtins.object
Methods defined here:
- __init__(self, model, filterStages=None)
- __init__ - Create a DeleteQuery
@param model - The model class
- execute(self, dbConn=None, doCommit=True)
- execute - Execute this action, generic method.
For SelectQuery, will call executeDelete
@param dbConn <DatabaseConnection/None> Default None - If None, start a new connection
using the global connection settings. Otherwise, use given connection.
@param doCommit <bool> Default True - If True, will commit right away. If False, you must commit.
A #dbConn must be specified if doCommit=False
- executeDelete(self, dbConn=None, doCommit=True)
- executeDelete - Perform the delete. (parameterized)
will NOT execute anything if conditionals are not set, to prevent accidently wiping the entire DB.
@param dbConn <DatabaseConnection> - Connect to use, like for transaction
@param doCommit <bool> default True - If True will perform the delete right away.
If False, you must manually commit the transaction and a #dbConn is required
- executeDeleteRaw(self, dbConn=None, doCommit=True)
- executeDelete - Perform the delete. (non-parameterized)
will NOT execute anything if conditionals are not set, to prevent accidently wiping the entire DB.
@param dbConn <DatabaseConnection/None> Default None - Connect to use, like for transaction.
If None, default settings will be used with a new connection
@param doCommit <bool> default True - If True will perform the delete right away.
If False, you must manually commit the transaction and a #dbConn is required
- getSql(self)
- getSql - Get the SQL to execute
- getSqlParameterizedValues(self)
- getSqlParameterizedValues - Get SQL with parameterized values
Methods inherited from QueryBase:
- addStage(self, _filter='AND')
- addStage - Add a "stage" to the WHERE condition. A stage is a collection of conditional expressions.
@param _filter:
<str> - Default WHERE_AND - WHERE_AND or WHERE_OR , this specifies the relation of the various
conditionals in this stage,
i.e. if it should be ( conA AND conB AND conC ) or ( conA OR conB OR conC )
<FilterStage> - Adds a FilterStage directly
@return - The FilterStage created by calling this method (just add to it, and it will automatically be linked),
or if a FilterStage was passed it will be returned
- getAllFieldNames(self)
- getAllFieldNames - Get a list of all the fields on this table
@return list<str> - List of all fields on model
- getTableName(self)
- getTableName - Get the name of the table associated with this model
@return <str> - Table Name
- getWhereClause(self, whereJoin='AND')
- getWhereClause - Gets the "WHERE" portion (including the string 'WHERE'), including all stages and sub-stages
@param whereJoin - If there are multiple top-level filter stages on this Query, this is how they should be related to eachother,
via AND or OR.
Generally, it makes more sense to just add a single filter stage at the top level, and append additional stages onto that.
@return <str> - The WHERE clause, or empty string if no conditions are present
- getWhereClauseParams(self, whereJoin='AND')
- getWhereClauseParams - Gets the "WHERE" portion (including the string 'WHERE'), parameterized and the parameters
@see getWhereClause
Static methods inherited from QueryBase:
- replaceSpecialValues(fieldValues)
- replaceSpecialValues - Replace special values (like NOW() ) with a fixed value.
They are supported as values in parameterized input, BUT they won't make it back onto the object
without some sort of special RETURNING clause (which isn't implemented.)
May be changed in the future.
Data descriptors inherited from QueryBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class FilterField(FilterType) |
| |
FilterField - A single condition on a field |
| |
- Method resolution order:
- FilterField
- FilterType
- builtins.object
Methods defined here:
- __init__(self, filterName, filterType, filterValue, operator=None)
- __init__ - Create a FilterField (conditional)
@param filterName <str> - Field name
@param filterType <str> - Operation ( like "=" )
@param filterValue <str> - The value to match
@param operator <str/None> default None - If provided, will use
this as the operator, otherwise will calculate from #filterType
- getFilterValue(self)
- getFilterValue - Get the value of this filter
@return <str> - Value of this filter
- toStr(self)
- toStr - Convert this into a single boolean expression for a SQL query.
Recommended to use #toStrParam for quoting / injection reasons
- toStrParam(self, paramName)
- toStrParam - Convert this into a single boolean expression for SQL query,
with using a parameterized value
@param paramName <str> - A unique name for this value
@return tuple( <str>, <dict> ) - A tuple of the param str (for appending to SQL query), and
a dict of the paramNames -> paramValues, for passing into parameterization
Data descriptors defined here:
- filterName
- filterType
- filterValue
- operator
Data descriptors inherited from FilterType:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class FilterJoin(FilterField) |
| |
FilterJoin - A filter expression which performs a join.
Does NOT quote, both sides are expected to be fields. |
| |
- Method resolution order:
- FilterJoin
- FilterField
- FilterType
- builtins.object
Methods defined here:
- toStr(self)
- toStr - Convert this into a single boolean expression for a SQL query
- toStrParam(self, paramName)
- toStrParam - Convert to a boolean expression for SQL query, parameterized
for FilterJoin this is the same as toStr, params will always be blank
Methods inherited from FilterField:
- __init__(self, filterName, filterType, filterValue, operator=None)
- __init__ - Create a FilterField (conditional)
@param filterName <str> - Field name
@param filterType <str> - Operation ( like "=" )
@param filterValue <str> - The value to match
@param operator <str/None> default None - If provided, will use
this as the operator, otherwise will calculate from #filterType
- getFilterValue(self)
- getFilterValue - Get the value of this filter
@return <str> - Value of this filter
Data descriptors inherited from FilterField:
- filterName
- filterType
- filterValue
- operator
Data descriptors inherited from FilterType:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class FilterStage(FilterType) |
| |
FilterStage - A filter stage, i.e. a grouping of conditions for the WHERE clause |
| |
- Method resolution order:
- FilterStage
- FilterType
- builtins.object
Methods defined here:
- __init__(self, whereType='AND', filters=None)
- __init__ - Create a FilterStage, defining a paticular "stage" of filtering
Surrounded in parenthesis, with the various parts being joined by #whereType.
@param whereType <str> , default "AND" [ WHERE_AND ] - This will join the various filter parts together
@param filters <None/list <FilterField/FilterStage>> - None, or a list of either FilterField's or FilterStage's
- __len__(self)
- add = addFilter(self, _filter)
- addCondition(self, filterName, filterType, filterValue)
- addCondition - Adds a filter, except takes the parameters of a FilterField as arguments
@return - The FilterField that was created and added
@see FilterField
- addFilter(self, _filter)
- addFilter/append/add - Add a filter.
@param _filter < FilterField > - A FilterField object which has a field name, comparison operation, and matching value
- addJoin(self, leftName, filterType, rightName)
- addJoin - Adds a FilterJoin, which is a condition which results in an inner join
@return - The FilterJoin that was created and added
@see FilterField
@see FilterJoin
- addStage(self, whereType='AND')
- addStage - Add a sub stage to this query (like to AND together sets of multi-field OR filters)
@param whereType <str> - AND or OR
- append = addFilter(self, _filter)
- index(self, val)
- index - Get the index of the first match of a given filter
@param val <FilterType obj> - Filter to search for
@return <int> - First index of given filter
- pop(self, idx)
- pop - Remove and return a filter by index
@param idx <int> - The index to pop
@return <FilterType obj> - The filter popped
- remove = removeFilter(self, _filter)
- removeFilter(self, _filter)
- removeFilter - Remove a filter from the list of filters.
@param _filter <FilterType obj> - The filter to remove
@return <None/FilterType obj> - The filter removed, or None if not found.
- rindex(self, val)
- rindex - Get the index of the last match of a given filter
@param val <FilterType obj> - Filter to search for
@return <int> - Last index of given filter
- toStr(self)
- toStr - Convert this stage into a grouped boolean expression, including any nested stages.
- toStrParam(self, paramPrefix)
- toStrParam - Convert to a parameterized string.
@return tuple ( <str>, <dict> ) - The SQL string, and parameter dict
Data descriptors defined here:
- filters
- whereType
Data descriptors inherited from FilterType:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class FilterType(builtins.object) |
| |
FilterType - Base class of filters |
| |
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class InsertQuery(QueryBase) |
| |
InsertQuery - A query for doing inserts |
| |
- Method resolution order:
- InsertQuery
- QueryBase
- builtins.object
Methods defined here:
- __init__(self, model, setFieldValues=None, filterStages=None)
- __init__ - Create an insert query
@param model - The model to use
@param setFieldValues - A dict of fieldName : fieldValue, or None to set later
- execute(self, dbConn=None, doCommit=True)
- execute - Execute this action, generic method.
For SelectQuery, will call executeInsert
@param dbConn <DatabaseConnection/None> Default None - If None, start a new connection
using the global connection settings. Otherwise, use given connection.
@param doCommit <bool> Default True - If True, will commit right away. If False, you must commit.
A #dbConn must be specified if doCommit=False
- executeInsert(self, dbConn=None, doCommit=True, replaceSpecialValues=True, returnPk=True)
- executeInsert - Insert records (parameterized)
May potentially use an existing DatabaseConnection (for transaction)
@param dbConn <None/DatabaseConnection> - If None, will use a fresh connection and auto-commit.
Otherwise, will use the provided connection (which may be linked to a transaction
@param doCommit <bool> default True - Whether to commit immediately
@param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() )
with their calculated value. @see QueryBase.replaceSpecialValues for more info.
@see executeInsert for the non-parameterized version.
- executeInsertRawValues(self, dbConn=None, doCommit=True, replaceSpecialValues=True)
- executeInsertRawValues - Insert records (non-parameterized)
May potentially use an existing DatabaseConnection (for transaction)
@param dbConn <None/DatabaseConnection> - If None, will use a fresh connection and auto-commit.
Otherwise, will use the provided connection (which may be linked to a transaction
@param doCommit <bool> default True - Whether to commit immediately
@param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() )
with their calculated value. @see QueryBase.replaceSpecialValues for more info.
@see executeInsertParameterized for the parameterized version.
- getInsertValuesStr(self, replaceSpecialValues=True)
- getInsertValuesStr - Get the portion following VALUES with values directly within (not parameterized)
@param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() )
with their calculated value. @see QueryBase.replaceSpecialValues for more info.
- getSql(self, replaceSpecialValues=True)
- getSql - Get the SQL to execute, non-parameterized
@param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() )
with their calculated value. @see QueryBase.replaceSpecialValues for more info.
@see getSqlParameterizedValues for parameterized version
- getSqlParameterizedValues(self, replaceSpecialValues=True)
- getSqlParameterizedValues - Get the SQL to execute, parameterized version
@param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() )
with their calculated value. @see QueryBase.replaceSpecialValues for more info.
- getTableFieldParamsAndValues(self, replaceSpecialValues=True)
- getTableFieldParamsAndValues - For parameterized values,
@param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() )
with their calculated value. @see QueryBase.replaceSpecialValues for more info.
This returns a tuple of two values, the first is the paramertized marker to be used in the query,
the second is a list of values which should be passed alongside
- getTableFields(self)
- getTableFields - Get a list of the fields that are going to be set
- getTableFieldsStr(self)
- getTableFieldsStr - Get the portion following the table name in an INSERT query which specifies
the fields that will be set
- setFieldValue(self, fieldName, newValue)
- setFieldValue - Set a field to a value to be inserted
- setNewFieldValues(self, setFieldValues)
- setNewFieldValues - Set the mapping of field names to values
Methods inherited from QueryBase:
- addStage(self, _filter='AND')
- addStage - Add a "stage" to the WHERE condition. A stage is a collection of conditional expressions.
@param _filter:
<str> - Default WHERE_AND - WHERE_AND or WHERE_OR , this specifies the relation of the various
conditionals in this stage,
i.e. if it should be ( conA AND conB AND conC ) or ( conA OR conB OR conC )
<FilterStage> - Adds a FilterStage directly
@return - The FilterStage created by calling this method (just add to it, and it will automatically be linked),
or if a FilterStage was passed it will be returned
- getAllFieldNames(self)
- getAllFieldNames - Get a list of all the fields on this table
@return list<str> - List of all fields on model
- getTableName(self)
- getTableName - Get the name of the table associated with this model
@return <str> - Table Name
- getWhereClause(self, whereJoin='AND')
- getWhereClause - Gets the "WHERE" portion (including the string 'WHERE'), including all stages and sub-stages
@param whereJoin - If there are multiple top-level filter stages on this Query, this is how they should be related to eachother,
via AND or OR.
Generally, it makes more sense to just add a single filter stage at the top level, and append additional stages onto that.
@return <str> - The WHERE clause, or empty string if no conditions are present
- getWhereClauseParams(self, whereJoin='AND')
- getWhereClauseParams - Gets the "WHERE" portion (including the string 'WHERE'), parameterized and the parameters
@see getWhereClause
Static methods inherited from QueryBase:
- replaceSpecialValues(fieldValues)
- replaceSpecialValues - Replace special values (like NOW() ) with a fixed value.
They are supported as values in parameterized input, BUT they won't make it back onto the object
without some sort of special RETURNING clause (which isn't implemented.)
May be changed in the future.
Data descriptors inherited from QueryBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class QueryBase(builtins.object) |
| |
QueryBase - Base object for constructing a query.
Should be extended and not used directly |
| |
Methods defined here:
- __init__(self, model, filterStages=None)
- __init__ - Create a QueryBase object
@param model <DatabaseModel> - The DatabaseModel to use for this query
@param filterStages <None/list<FilterType objs>> - Use this list of WHERE filter stages, or None to start
with an empty list. Call #addStage to add a stage to the WHERE
- addStage(self, _filter='AND')
- addStage - Add a "stage" to the WHERE condition. A stage is a collection of conditional expressions.
@param _filter:
<str> - Default WHERE_AND - WHERE_AND or WHERE_OR , this specifies the relation of the various
conditionals in this stage,
i.e. if it should be ( conA AND conB AND conC ) or ( conA OR conB OR conC )
<FilterStage> - Adds a FilterStage directly
@return - The FilterStage created by calling this method (just add to it, and it will automatically be linked),
or if a FilterStage was passed it will be returned
- execute(self, dbConn=None, doCommit=True)
- execute - Perform the action of this query, regardless of type
(useful for batching transactions into lists and iterating through)
@param dbConn <DatabaseConnection/None> Default None -
The postgresql connection to use, or None to
create a new one from global settings.
Must be defined if doCommit=False (so you can commit later)
- getAllFieldNames(self)
- getAllFieldNames - Get a list of all the fields on this table
@return list<str> - List of all fields on model
- getSql(self)
- getSql - Get the SQL for this query
@return <str> - The SQL string
- getTableName(self)
- getTableName - Get the name of the table associated with this model
@return <str> - Table Name
- getWhereClause(self, whereJoin='AND')
- getWhereClause - Gets the "WHERE" portion (including the string 'WHERE'), including all stages and sub-stages
@param whereJoin - If there are multiple top-level filter stages on this Query, this is how they should be related to eachother,
via AND or OR.
Generally, it makes more sense to just add a single filter stage at the top level, and append additional stages onto that.
@return <str> - The WHERE clause, or empty string if no conditions are present
- getWhereClauseParams(self, whereJoin='AND')
- getWhereClauseParams - Gets the "WHERE" portion (including the string 'WHERE'), parameterized and the parameters
@see getWhereClause
Static methods defined here:
- replaceSpecialValues(fieldValues)
- replaceSpecialValues - Replace special values (like NOW() ) with a fixed value.
They are supported as values in parameterized input, BUT they won't make it back onto the object
without some sort of special RETURNING clause (which isn't implemented.)
May be changed in the future.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class QueryStr(builtins.str) |
| |
QueryStr - A portion that should be treated like a raw string (Embedded sql),
and not a quoted value |
| |
- Method resolution order:
- QueryStr
- builtins.str
- builtins.object
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Methods inherited from builtins.str:
- __add__(self, value, /)
- Return self+value.
- __contains__(self, key, /)
- Return key in self.
- __eq__(self, value, /)
- Return self==value.
- __format__(...)
- S.__format__(format_spec) -> str
Return a formatted version of S as described by format_spec.
- __ge__(self, value, /)
- Return self>=value.
- __getattribute__(self, name, /)
- Return getattr(self, name).
- __getitem__(self, key, /)
- Return self[key].
- __getnewargs__(...)
- __gt__(self, value, /)
- Return self>value.
- __hash__(self, /)
- Return hash(self).
- __iter__(self, /)
- Implement iter(self).
- __le__(self, value, /)
- Return self<=value.
- __len__(self, /)
- Return len(self).
- __lt__(self, value, /)
- Return self<value.
- __mod__(self, value, /)
- Return self%value.
- __mul__(self, value, /)
- Return self*value.n
- __ne__(self, value, /)
- Return self!=value.
- __new__(*args, **kwargs) from builtins.type
- Create and return a new object. See help(type) for accurate signature.
- __repr__(self, /)
- Return repr(self).
- __rmod__(self, value, /)
- Return value%self.
- __rmul__(self, value, /)
- Return self*value.
- __sizeof__(...)
- S.__sizeof__() -> size of S in memory, in bytes
- __str__(self, /)
- Return str(self).
- capitalize(...)
- S.capitalize() -> str
Return a capitalized version of S, i.e. make the first character
have upper case and the rest lower case.
- casefold(...)
- S.casefold() -> str
Return a version of S suitable for caseless comparisons.
- center(...)
- S.center(width[, fillchar]) -> str
Return S centered in a string of length width. Padding is
done using the specified fill character (default is a space)
- count(...)
- S.count(sub[, start[, end]]) -> int
Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are
interpreted as in slice notation.
- encode(...)
- S.encode(encoding='utf-8', errors='strict') -> bytes
Encode S using the codec registered for encoding. Default encoding
is 'utf-8'. errors may be given to set a different error
handling scheme. Default is 'strict' meaning that encoding errors raise
a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
'xmlcharrefreplace' as well as any other name registered with
codecs.register_error that can handle UnicodeEncodeErrors.
- endswith(...)
- S.endswith(suffix[, start[, end]]) -> bool
Return True if S ends with the specified suffix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
suffix can also be a tuple of strings to try.
- expandtabs(...)
- S.expandtabs(tabsize=8) -> str
Return a copy of S where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find(...)
- S.find(sub[, start[, end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- format(...)
- S.format(*args, **kwargs) -> str
Return a formatted version of S, using substitutions from args and kwargs.
The substitutions are identified by braces ('{' and '}').
- format_map(...)
- S.format_map(mapping) -> str
Return a formatted version of S, using substitutions from mapping.
The substitutions are identified by braces ('{' and '}').
- index(...)
- S.index(sub[, start[, end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- isalnum(...)
- S.isalnum() -> bool
Return True if all characters in S are alphanumeric
and there is at least one character in S, False otherwise.
- isalpha(...)
- S.isalpha() -> bool
Return True if all characters in S are alphabetic
and there is at least one character in S, False otherwise.
- isdecimal(...)
- S.isdecimal() -> bool
Return True if there are only decimal characters in S,
False otherwise.
- isdigit(...)
- S.isdigit() -> bool
Return True if all characters in S are digits
and there is at least one character in S, False otherwise.
- isidentifier(...)
- S.isidentifier() -> bool
Return True if S is a valid identifier according
to the language definition.
Use keyword.iskeyword() to test for reserved identifiers
such as "def" and "class".
- islower(...)
- S.islower() -> bool
Return True if all cased characters in S are lowercase and there is
at least one cased character in S, False otherwise.
- isnumeric(...)
- S.isnumeric() -> bool
Return True if there are only numeric characters in S,
False otherwise.
- isprintable(...)
- S.isprintable() -> bool
Return True if all characters in S are considered
printable in repr() or S is empty, False otherwise.
- isspace(...)
- S.isspace() -> bool
Return True if all characters in S are whitespace
and there is at least one character in S, False otherwise.
- istitle(...)
- S.istitle() -> bool
Return True if S is a titlecased string and there is at least one
character in S, i.e. upper- and titlecase characters may only
follow uncased characters and lowercase characters only cased ones.
Return False otherwise.
- isupper(...)
- S.isupper() -> bool
Return True if all cased characters in S are uppercase and there is
at least one cased character in S, False otherwise.
- join(...)
- S.join(iterable) -> str
Return a string which is the concatenation of the strings in the
iterable. The separator between elements is S.
- ljust(...)
- S.ljust(width[, fillchar]) -> str
Return S left-justified in a Unicode string of length width. Padding is
done using the specified fill character (default is a space).
- lower(...)
- S.lower() -> str
Return a copy of the string S converted to lowercase.
- lstrip(...)
- S.lstrip([chars]) -> str
Return a copy of the string S with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(...)
- S.partition(sep) -> (head, sep, tail)
Search for the separator sep in S, and return the part before it,
the separator itself, and the part after it. If the separator is not
found, return S and two empty strings.
- replace(...)
- S.replace(old, new[, count]) -> str
Return a copy of S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.
- rfind(...)
- S.rfind(sub[, start[, end]]) -> int
Return the highest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- rindex(...)
- S.rindex(sub[, start[, end]]) -> int
Return the highest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- rjust(...)
- S.rjust(width[, fillchar]) -> str
Return S right-justified in a string of length width. Padding is
done using the specified fill character (default is a space).
- rpartition(...)
- S.rpartition(sep) -> (head, sep, tail)
Search for the separator sep in S, starting at the end of S, and return
the part before it, the separator itself, and the part after it. If the
separator is not found, return two empty strings and S.
- rsplit(...)
- S.rsplit(sep=None, maxsplit=-1) -> list of strings
Return a list of the words in S, using sep as the
delimiter string, starting at the end of the string and
working to the front. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified, any whitespace string
is a separator.
- rstrip(...)
- S.rstrip([chars]) -> str
Return a copy of the string S with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(...)
- S.split(sep=None, maxsplit=-1) -> list of strings
Return a list of the words in S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result.
- splitlines(...)
- S.splitlines([keepends]) -> list of strings
Return a list of the lines in S, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends
is given and true.
- startswith(...)
- S.startswith(prefix[, start[, end]]) -> bool
Return True if S starts with the specified prefix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
prefix can also be a tuple of strings to try.
- strip(...)
- S.strip([chars]) -> str
Return a copy of the string S with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase(...)
- S.swapcase() -> str
Return a copy of S with uppercase characters converted to lowercase
and vice versa.
- title(...)
- S.title() -> str
Return a titlecased version of S, i.e. words start with title case
characters, all remaining cased characters have lower case.
- translate(...)
- S.translate(table) -> str
Return a copy of the string S in which each character has been mapped
through the given translation table. The table must implement
lookup/indexing via __getitem__, for instance a dictionary or list,
mapping Unicode ordinals to Unicode ordinals, strings, or None. If
this operation raises LookupError, the character is left untouched.
Characters mapped to None are deleted.
- upper(...)
- S.upper() -> str
Return a copy of S converted to uppercase.
- zfill(...)
- S.zfill(width) -> str
Pad a numeric string S with zeros on the left, to fill a field
of the specified width. The string S is never truncated.
Static methods inherited from builtins.str:
- maketrans(x, y=None, z=None, /)
- Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode
ordinals (integers) or characters to Unicode ordinals, strings or None.
Character keys will be then converted to ordinals.
If there are two arguments, they must be strings of equal length, and
in the resulting dictionary, each character in x will be mapped to the
character at the same position in y. If there is a third argument, it
must be a string, whose characters will be mapped to None in the result.
|
class SelectGenericJoinQuery(SelectQuery) |
| |
SelectInnerJoinQuery - A SELECT query on multiple tables which supports inner join |
| |
- Method resolution order:
- SelectGenericJoinQuery
- SelectQuery
- QueryBase
- builtins.object
Methods defined here:
- __init__(self, primaryModel, selectFields='ALL', orderByField=None, orderByDir='', limitNum=None)
- __init__ - Create a SelectGenericJoinQuery
@param primaryModel - <DatabaseModel> - Primary Database model
@param selectFields <'ALL' or list<str>> - Default ALL for all fields, or a list of fields to SELECT on primary table
@param orderByField <None/str> - Default None, if provided ORDER BY this field
@param orderByDir <str> Default '', ASC or DESC for direction
@param limitNum <None/int> default None - If provided, return max this many records
- executeGetDictObjs(self, parameterized=True, dbConn=None)
- executeGetDictObjs - Execute this query, and map results to DictObjs by table.
I.e. if you have a table "MyTable" and a field "MyTable.MyField", you can access like:
rows = executeGetDictObjs()
result1 = rows[0]
myTableMyField = result1.MyTable.MyField
@param paramertized <bool> Default True - Whether to use parameterized query
@param dbConn <DatabaseConnection/None> - If None, start a new connection using the
global connection parameters.
Otherwise, use this provided connection
@return list<DictObjs> - List of rows, a DictObj for each row.
- executeGetMapping(self, parameterized=True, dbConn=None)
- executeGetMapping - Execute this query, and return the results as
a list of rows, where each list contains a map (OrderedDict) of the field name -> value
@param paramertized <bool> Default True - Whether to use parameterized query
@param dbConn <DatabaseConnection/None> - If None, start a new connection using the
global connection parameters.
Otherwise, use this provided connection
@return list<dict> - List of rows, each row as a dict with named columns
- executeGetObjs(self, parameterized=True, dbConn=None)
- executeGetObjs - Not supported on SelectInnerJoinQuery
- getAllFieldNames(self)
- getAllFieldNames - Get a list of all field names on the primary table
@return list<str> - TABLE_NAME.fieldName for each field
- getAllFieldNamesByTable(self)
- getAllFieldNamesByTable - Gets a dict of table name to list of all fields for that model
@return dict table name<str> -> list<str> fields
- getAllFieldNamesIncludingTable(self)
- getAllFieldNamesIncludingTable - Get a list of all the field names prefixed with "$tableName."
@return list<str> - List of all table names and fields
- getFields(self)
- getFields - Gets the fields to SELECT
@return list<str> - List of field names
- getJoinClauses(self)
- getJoinClauses - Get a string of all the JOIN clauses with other tables
@return <str> - Join clause
- getJoinClausesParams(self)
- getJoinClausesParams - Get the "join" clauses with paramertized parameters
- getSql(self)
- getSql - Gets the sql command to execute
- getSqlParameterizedValues(self)
- getSqlParameterizedValues - Get the SQL with parameterized values
@return tuple( sql<str>, params<list<str>>)
- getTableNames(self)
- getTableNames - Get a list of all table names in this query
@return list<str> - A list of table names
- getTableNamesStr(self)
- getTableNamesStr - Get a comma-joined string of table names in this query
@return <str> - comma-joined string of table names
- joinModel(self, model, joinType, conditionGrouping='AND')
- joinModel - Join to another model, using a join type and given condition grouping
@param model <DatabaseModel> - Database model to use
@param joinType <str> - A join type (see JOIN_* in constants.py)
@param conditionGrouping <str> default AND, either WHERE_AND or WHERE_OR
Methods inherited from SelectQuery:
- addOrderBy(self, fieldName, orderByDir='')
- addOrderBy - Add an additional "ORDER BY"
- clearOrderBy(self)
- execute(self, dbConn=None, doCommit=True)
- execute - Execute this action, generic method.
For SelectQuery, will call executeGetRows
@param dbConn <DatabaseConnection/None> Default None - If None, start a new connection
using the global connection settings. Otherwise, use given connection.
@param doCommit <bool> Default True - Ignored on SelectQuery
- executeGetRows(self, parameterized=True, dbConn=None)
- executeGetRows - Execute and return the raw data from postgres in rows of columns
@param paramertized <bool> Default True - Whether to use parameterized query
@param dbConn <DatabaseConnection/None> - If None, start a new connection using the
global connection parameters.
Otherwise, use this provided connection
@return list<list<str>> - Rows of columns
- getFieldsStr(self)
- getFieldsStr - Get comma-separated names of fields fit for going into a query
- getLimitStr(self)
- getLimitStr - Get the LIMIT N portion of the query string
- getOrderByStr(self)
- getOrderByStr - Gets the ORDER BY portion (or empty string if unset) of the query
- removeOrderBy(self, fieldName)
- removeOrderBy - Remove the 'ORDER BY' for a given field
@param fieldName <str> - Name of field ordered by
@return None or tuple ( fieldName<str>, orderByDirection<str> ) if found
- setLimitNum(self, limitNum)
- setSelectFields(self, selectFields)
- setSelectFields - Set the fields to select
@param selectFields list<str> - Field names
Methods inherited from QueryBase:
- addStage(self, _filter='AND')
- addStage - Add a "stage" to the WHERE condition. A stage is a collection of conditional expressions.
@param _filter:
<str> - Default WHERE_AND - WHERE_AND or WHERE_OR , this specifies the relation of the various
conditionals in this stage,
i.e. if it should be ( conA AND conB AND conC ) or ( conA OR conB OR conC )
<FilterStage> - Adds a FilterStage directly
@return - The FilterStage created by calling this method (just add to it, and it will automatically be linked),
or if a FilterStage was passed it will be returned
- getTableName(self)
- getTableName - Get the name of the table associated with this model
@return <str> - Table Name
- getWhereClause(self, whereJoin='AND')
- getWhereClause - Gets the "WHERE" portion (including the string 'WHERE'), including all stages and sub-stages
@param whereJoin - If there are multiple top-level filter stages on this Query, this is how they should be related to eachother,
via AND or OR.
Generally, it makes more sense to just add a single filter stage at the top level, and append additional stages onto that.
@return <str> - The WHERE clause, or empty string if no conditions are present
- getWhereClauseParams(self, whereJoin='AND')
- getWhereClauseParams - Gets the "WHERE" portion (including the string 'WHERE'), parameterized and the parameters
@see getWhereClause
Static methods inherited from QueryBase:
- replaceSpecialValues(fieldValues)
- replaceSpecialValues - Replace special values (like NOW() ) with a fixed value.
They are supported as values in parameterized input, BUT they won't make it back onto the object
without some sort of special RETURNING clause (which isn't implemented.)
May be changed in the future.
Data descriptors inherited from QueryBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class SelectInnerJoinQuery(SelectQuery) |
| |
SelectInnerJoinQuery - A SELECT query on multiple tables which supports inner join |
| |
- Method resolution order:
- SelectInnerJoinQuery
- SelectQuery
- QueryBase
- builtins.object
Methods defined here:
- __init__(self, models, selectFields='ALL', orderByField=None, orderByDir='', limitNum=None)
- __init__ - Create a SelectInnerJoinQuery
@param models - list<DatabaseModel> - List of models to use
@param selectFields < 'ALL' or list< fieldName<str>> Default "ALL" - ALL to do * or a list of field names to select.
Should be prefixed with table name, like "tableName.fieldName"
@param orderByField <None/str> Default None - Order by this field, if provided
@param orderByDir <str> Default '' - ASC or DESC for ascneding/descending
@param limitNum <int/None> default None - If provided, will return MAX this many results
- executeGetDictObjs(self, parameterized=True, dbConn=None)
- executeGetDictObjs - Execute this query, and map results to DictObjs by table.
I.e. if you have a table "MyTable" and a field "MyTable.MyField", you can access like:
rows = executeGetDictObjs()
result1 = rows[0]
myTableMyField = result1.MyTable.MyField
@param paramertized <bool> Default True - Whether to use parameterized query
@param dbConn <DatabaseConnection/None> - If None, start a new connection using the
global connection parameters.
Otherwise, use this provided connection
@return list<DictObjs> - List of rows, a DictObj for each row.
- executeGetMapping(self, parameterized=True, dbConn=None)
- executeGetMapping - Execute this query, and return the results as
a list of rows, where each list contains a map (OrderedDict) of the field name -> value
@param paramertized <bool> Default True - Whether to use parameterized query
@param dbConn <DatabaseConnection/None> - If None, start a new connection using the
global connection parameters.
Otherwise, use this provided connection
@return list<dict> - List of rows, each row as a dict with named columns
- executeGetObjs(self, parameterized=True, dbConn=None)
- executeGetObjs - Not supported for SelectInnerJoinQuery
- getAllFieldNames(self)
- getAllFieldNames - Not implemented on SelectInnerJoinQuery
- getAllFieldNamesByTable(self)
- getAllFieldNamesByTable - Get a map of table name : fields for all tables
@return dict <str> : list<str> - Table name as key, all fields as value
- getAllFieldNamesIncludingTable(self)
- getAllFieldNamesIncludingTable - Get a list of all fields prefixed with table name,
i.e. tableName.fieldName for each table and all fields
@return list<str> - List of tableName.fieldName for all tables and fields
- getFields(self)
- getFields - Get a string of the fields to use in SELECT
@return list<str> - List of fields to select
- getSql(self)
- getSql - Gets the sql command to execute
- getSqlParameterizedValues(self)
- getSqlParameterizedValues - Gets the SQL command to execute using parameterized values
@return tuple ( sql<str>, whereParams list<str> )
- getTableName(self)
- getTableName - Not implemented on SelectInnerJoinQuery
- getTableNames(self)
- getTableNames - Get a list of associated table names
@return list<str> - List of table names
- getTableNamesStr(self)
- getTableNamesStr - Get a comma-joined string of associated table names
@return <str> - comma-joined string of associated table names
Methods inherited from SelectQuery:
- addOrderBy(self, fieldName, orderByDir='')
- addOrderBy - Add an additional "ORDER BY"
- clearOrderBy(self)
- execute(self, dbConn=None, doCommit=True)
- execute - Execute this action, generic method.
For SelectQuery, will call executeGetRows
@param dbConn <DatabaseConnection/None> Default None - If None, start a new connection
using the global connection settings. Otherwise, use given connection.
@param doCommit <bool> Default True - Ignored on SelectQuery
- executeGetRows(self, parameterized=True, dbConn=None)
- executeGetRows - Execute and return the raw data from postgres in rows of columns
@param paramertized <bool> Default True - Whether to use parameterized query
@param dbConn <DatabaseConnection/None> - If None, start a new connection using the
global connection parameters.
Otherwise, use this provided connection
@return list<list<str>> - Rows of columns
- getFieldsStr(self)
- getFieldsStr - Get comma-separated names of fields fit for going into a query
- getLimitStr(self)
- getLimitStr - Get the LIMIT N portion of the query string
- getOrderByStr(self)
- getOrderByStr - Gets the ORDER BY portion (or empty string if unset) of the query
- removeOrderBy(self, fieldName)
- removeOrderBy - Remove the 'ORDER BY' for a given field
@param fieldName <str> - Name of field ordered by
@return None or tuple ( fieldName<str>, orderByDirection<str> ) if found
- setLimitNum(self, limitNum)
- setSelectFields(self, selectFields)
- setSelectFields - Set the fields to select
@param selectFields list<str> - Field names
Methods inherited from QueryBase:
- addStage(self, _filter='AND')
- addStage - Add a "stage" to the WHERE condition. A stage is a collection of conditional expressions.
@param _filter:
<str> - Default WHERE_AND - WHERE_AND or WHERE_OR , this specifies the relation of the various
conditionals in this stage,
i.e. if it should be ( conA AND conB AND conC ) or ( conA OR conB OR conC )
<FilterStage> - Adds a FilterStage directly
@return - The FilterStage created by calling this method (just add to it, and it will automatically be linked),
or if a FilterStage was passed it will be returned
- getWhereClause(self, whereJoin='AND')
- getWhereClause - Gets the "WHERE" portion (including the string 'WHERE'), including all stages and sub-stages
@param whereJoin - If there are multiple top-level filter stages on this Query, this is how they should be related to eachother,
via AND or OR.
Generally, it makes more sense to just add a single filter stage at the top level, and append additional stages onto that.
@return <str> - The WHERE clause, or empty string if no conditions are present
- getWhereClauseParams(self, whereJoin='AND')
- getWhereClauseParams - Gets the "WHERE" portion (including the string 'WHERE'), parameterized and the parameters
@see getWhereClause
Static methods inherited from QueryBase:
- replaceSpecialValues(fieldValues)
- replaceSpecialValues - Replace special values (like NOW() ) with a fixed value.
They are supported as values in parameterized input, BUT they won't make it back onto the object
without some sort of special RETURNING clause (which isn't implemented.)
May be changed in the future.
Data descriptors inherited from QueryBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class SelectQuery(QueryBase) |
| |
SelectQuery - A Query designed for "SELECT". |
| |
- Method resolution order:
- SelectQuery
- QueryBase
- builtins.object
Methods defined here:
- __init__(self, model, selectFields='ALL', filterStages=None, orderByField=None, orderByDir='', limitNum=None)
- __init__ - Create a SelectQuery
@param model <DatabaseModel> - The model associated with this query
@param selectFields <list/'ALL'> Defalult 'ALL' - The fields to select. Default 'ALL' will return all fields on this model
@param filterStages list<FilterStage> - A list of initial filter stages (can and should just be added later)
TODO: Refactor and remove "filterStages" from constructor. I thought maybe for copying it would be useful,
but forget it.
@param orderByField - If provided, the first "orderBy" for this query. Can be appended to or removed later. Should be a field name.
@param orderByDir <str> - If provided, the direction the "order by" will follow.
@param limitNum <None/int> default None, if provided integer, will return no more than N rows
- addOrderBy(self, fieldName, orderByDir='')
- addOrderBy - Add an additional "ORDER BY"
- clearOrderBy(self)
- execute(self, dbConn=None, doCommit=True)
- execute - Execute this action, generic method.
For SelectQuery, will call executeGetRows
@param dbConn <DatabaseConnection/None> Default None - If None, start a new connection
using the global connection settings. Otherwise, use given connection.
@param doCommit <bool> Default True - Ignored on SelectQuery
- executeGetObjs(self, parameterized=True, dbConn=None)
- executeGetObjs - Execute and transform the returned data into a series of objects, one per row returned.
@param paramertized <bool> Default True - Whether to use parameterized query
@param dbConn <DatabaseConnection/None> - If None, start a new connection using the
global connection parameters.
Otherwise, use this provided connection
@return list<model object> - A list of constructed model objects with the fields from this query filled
- executeGetRows(self, parameterized=True, dbConn=None)
- executeGetRows - Execute and return the raw data from postgres in rows of columns
@param paramertized <bool> Default True - Whether to use parameterized query
@param dbConn <DatabaseConnection/None> - If None, start a new connection using the
global connection parameters.
Otherwise, use this provided connection
@return list<list<str>> - Rows of columns
- getFields(self)
- getFields - Get a list of the fields to select (will unroll the special, "ALL")
- getFieldsStr(self)
- getFieldsStr - Get comma-separated names of fields fit for going into a query
- getLimitStr(self)
- getLimitStr - Get the LIMIT N portion of the query string
- getOrderByStr(self)
- getOrderByStr - Gets the ORDER BY portion (or empty string if unset) of the query
- getSql(self)
- getSql - Gets the sql command to execute
- getSqlParameterizedValues(self)
- getSqlParameterizedValues - Get the sql command parameterized
@return tuple< sql<str>, whereParams <list<FilterStage obj>> >
- removeOrderBy(self, fieldName)
- removeOrderBy - Remove the 'ORDER BY' for a given field
@param fieldName <str> - Name of field ordered by
@return None or tuple ( fieldName<str>, orderByDirection<str> ) if found
- setLimitNum(self, limitNum)
- setSelectFields(self, selectFields)
- setSelectFields - Set the fields to select
@param selectFields list<str> - Field names
Methods inherited from QueryBase:
- addStage(self, _filter='AND')
- addStage - Add a "stage" to the WHERE condition. A stage is a collection of conditional expressions.
@param _filter:
<str> - Default WHERE_AND - WHERE_AND or WHERE_OR , this specifies the relation of the various
conditionals in this stage,
i.e. if it should be ( conA AND conB AND conC ) or ( conA OR conB OR conC )
<FilterStage> - Adds a FilterStage directly
@return - The FilterStage created by calling this method (just add to it, and it will automatically be linked),
or if a FilterStage was passed it will be returned
- getAllFieldNames(self)
- getAllFieldNames - Get a list of all the fields on this table
@return list<str> - List of all fields on model
- getTableName(self)
- getTableName - Get the name of the table associated with this model
@return <str> - Table Name
- getWhereClause(self, whereJoin='AND')
- getWhereClause - Gets the "WHERE" portion (including the string 'WHERE'), including all stages and sub-stages
@param whereJoin - If there are multiple top-level filter stages on this Query, this is how they should be related to eachother,
via AND or OR.
Generally, it makes more sense to just add a single filter stage at the top level, and append additional stages onto that.
@return <str> - The WHERE clause, or empty string if no conditions are present
- getWhereClauseParams(self, whereJoin='AND')
- getWhereClauseParams - Gets the "WHERE" portion (including the string 'WHERE'), parameterized and the parameters
@see getWhereClause
Static methods inherited from QueryBase:
- replaceSpecialValues(fieldValues)
- replaceSpecialValues - Replace special values (like NOW() ) with a fixed value.
They are supported as values in parameterized input, BUT they won't make it back onto the object
without some sort of special RETURNING clause (which isn't implemented.)
May be changed in the future.
Data descriptors inherited from QueryBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class UpdateQuery(QueryBase) |
| |
UpdateQuery - Perform an update on a model |
| |
- Method resolution order:
- UpdateQuery
- QueryBase
- builtins.object
Methods defined here:
- __init__(self, model, newFieldValues=None, filterStages=None)
- __init__ - Create an update query
@param model - The model class
@param newFieldValues <dict/None> - Either a dict of field name : newValue, or None to set later
- execute(self, dbConn=None, doCommit=True)
- execute - Execute this action, generic method.
For SelectQuery, will call executeUpdate
@param dbConn <DatabaseConnection/None> Default None - If None, start a new connection
using the global connection settings. Otherwise, use given connection.
@param doCommit <bool> Default True - If True, will commit right away. If False, you must commit.
A #dbConn must be specified if doCommit=False
- executeUpdate(self, dbConn=None, doCommit=True, replaceSpecialValues=True)
- executeUpdate - Upate records (parameterized)
May potentially use an existing DatabaseConnection (for transaction)
@param dbConn <None/DatabaseConnection> - If None, will use a fresh connection and auto-commit.
Otherwise, will use the provided connection (which may be linked to a transaction
@param doCommit <bool> default True - Whether to commit immediately
@param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() )
with their calculated value. @see QueryBase.replaceSpecialValues for more info.
- executeUpdateRawValues(self, dbConn=None, doCommit=False, replaceSpecialValues=True)
- executeUpdate - Update some records
@param dbConn <None/DatabaseConnection> - If None, will get a new connection with autocmommit.
@param doCommit <bool> Default True - If True, will commit right away. If False, you must commit.
@param replaceSpecialValues <bool> - True to replace special values before sending to SQL
Nay be passed a transaction-connection, to do update within a transaction
- getSetFieldParamsAndValues(self, replaceSpecialValues=True)
- getSetFieldParamsAndValues - For parameterized values,
@param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() )
with their calculated value. @see QueryBase.replaceSpecialValues for more info.
This returns a tuple of two values, the first is the paramertized marker to be used in the query,
the second is a list of values which should be passed alongside
- getSetFieldsStr(self, replaceSpecialValues=True)
- getSetFieldsStr - Get the X = "VALUE" , Y = "OTHER" portion of the SQL query
- getSql(self, replaceSpecialValues=True)
- getSql - Get sql command to execute
- getSqlParameterizedValues(self, replaceSpecialValues=True)
- getSqlParameterizedValues - Get the SQL to execute, parameterized version
@param replaceSpecialValues <bool, default True> - If True, will replace special values ( like NOW() )
with their calculated value. @see QueryBase.replaceSpecialValues for more info.
- setFieldValue(self, fieldName, newValue)
- setFieldValue - Update a field to a new value
- setNewFieldValues(self, newFieldValues)
- setNewFieldValues - Set the dict of all field updates
Data descriptors defined here:
- hasAnyUpdates
Methods inherited from QueryBase:
- addStage(self, _filter='AND')
- addStage - Add a "stage" to the WHERE condition. A stage is a collection of conditional expressions.
@param _filter:
<str> - Default WHERE_AND - WHERE_AND or WHERE_OR , this specifies the relation of the various
conditionals in this stage,
i.e. if it should be ( conA AND conB AND conC ) or ( conA OR conB OR conC )
<FilterStage> - Adds a FilterStage directly
@return - The FilterStage created by calling this method (just add to it, and it will automatically be linked),
or if a FilterStage was passed it will be returned
- getAllFieldNames(self)
- getAllFieldNames - Get a list of all the fields on this table
@return list<str> - List of all fields on model
- getTableName(self)
- getTableName - Get the name of the table associated with this model
@return <str> - Table Name
- getWhereClause(self, whereJoin='AND')
- getWhereClause - Gets the "WHERE" portion (including the string 'WHERE'), including all stages and sub-stages
@param whereJoin - If there are multiple top-level filter stages on this Query, this is how they should be related to eachother,
via AND or OR.
Generally, it makes more sense to just add a single filter stage at the top level, and append additional stages onto that.
@return <str> - The WHERE clause, or empty string if no conditions are present
- getWhereClauseParams(self, whereJoin='AND')
- getWhereClauseParams - Gets the "WHERE" portion (including the string 'WHERE'), parameterized and the parameters
@see getWhereClause
Static methods inherited from QueryBase:
- replaceSpecialValues(fieldValues)
- replaceSpecialValues - Replace special values (like NOW() ) with a fixed value.
They are supported as values in parameterized input, BUT they won't make it back onto the object
without some sort of special RETURNING clause (which isn't implemented.)
May be changed in the future.
Data descriptors inherited from QueryBase:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |