keystone.common.sql.core module¶
SQL backends for the various services.
Before using this module, call initialize(). This has to be done before CONF() because it sets up configuration options.
-
class
keystone.common.sql.core.
DateTimeInt
(*args, **kwargs)[source]¶ Bases:
sqlalchemy.sql.type_api.TypeDecorator
A column that automatically converts a datetime object to an Int.
Keystone relies on accurate (sub-second) datetime objects. In some cases the RDBMS drop sub-second accuracy (some versions of MySQL). This field automatically converts the value to an INT when storing the data and back to a datetime object when it is loaded from the database.
- NOTE: Any datetime object that has timezone data will be converted to UTC.
Any datetime object that has no timezone data will be assumed to be UTC and loaded from the DB as such.
-
epoch
= datetime.datetime(1970, 1, 1, 0, 0, tzinfo=<UTC>)¶
-
impl
¶ alias of
sqlalchemy.sql.sqltypes.BigInteger
-
process_bind_param
(value, dialect)[source]¶ Receive a bound parameter value to be converted.
Subclasses override this method to return the value that should be passed along to the underlying
TypeEngine
object, and from there to the DBAPIexecute()
method.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
- Parameters
value – Data to operate upon, of any type expected by this method in the subclass. Can be
None
.dialect – the
Dialect
in use.
-
process_result_value
(value, dialect)[source]¶ Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying
TypeEngine
object, originally from the DBAPI cursor methodfetchone()
or similar.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
- Parameters
value – Data to operate upon, of any type expected by this method in the subclass. Can be
None
.dialect – the
Dialect
in use.
This operation should be designed to be reversible by the “process_bind_param” method of this class.
-
class
keystone.common.sql.core.
JsonBlob
(*args, **kwargs)[source]¶ Bases:
sqlalchemy.sql.type_api.TypeDecorator
-
impl
¶ alias of
sqlalchemy.sql.sqltypes.Text
-
process_bind_param
(value, dialect)[source]¶ Receive a bound parameter value to be converted.
Subclasses override this method to return the value that should be passed along to the underlying
TypeEngine
object, and from there to the DBAPIexecute()
method.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
- Parameters
value – Data to operate upon, of any type expected by this method in the subclass. Can be
None
.dialect – the
Dialect
in use.
-
process_result_value
(value, dialect)[source]¶ Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying
TypeEngine
object, originally from the DBAPI cursor methodfetchone()
or similar.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
- Parameters
value – Data to operate upon, of any type expected by this method in the subclass. Can be
None
.dialect – the
Dialect
in use.
This operation should be designed to be reversible by the “process_bind_param” method of this class.
-
-
class
keystone.common.sql.core.
ModelDictMixinWithExtras
[source]¶ Bases:
oslo_db.sqlalchemy.models.ModelBase
Mixin making model behave with dict-like interfaces includes extras.
- NOTE: DO NOT USE THIS FOR FUTURE SQL MODELS. “Extra” column is a legacy
concept that should not be carried forward with new SQL models as the concept of “arbitrary” properties is not in line with the design philosophy of Keystone.
-
attributes
= []¶
-
keystone.common.sql.core.
filter_limit_query
(model, query, hints)[source]¶ Apply filtering and limit to a query.
- Parameters
model – table model
query – query to apply filters to
hints – contains the list of filters and limit details. This may be None, indicating that there are no filters or limits to be applied. If it’s not None, then any filters satisfied here will be removed so that the caller will know if any filters remain.
- Returns
query updated with any filters and limits satisfied
-
keystone.common.sql.core.
handle_conflicts
(conflict_type='object')[source]¶ Convert select sqlalchemy exceptions into HTTP 409 Conflict.
-
keystone.common.sql.core.
initialize_decorator
(init)[source]¶ Ensure that the length of string field do not exceed the limit.
This decorator check the initialize arguments, to make sure the length of string field do not exceed the length limit, or raise a ‘StringLengthExceeded’ exception.
Use decorator instead of inheritance, because the metaclass will check the __tablename__, primary key columns, etc. at the class definition.