SQLAlchemy column types¶
-
class
coaster.sqlalchemy.columns.
JsonDict
(*args, **kwargs)[source]¶ Represents a JSON data structure. Usage:
column = Column(JsonDict)
The column will be represented to the database as a
JSONB
column if the server is PostgreSQL 9.4 or later,JSON
if PostgreSQL 9.2 or 9.3, andTEXT
for everything else. The column behaves like a JSON store regardless of the backing data type.-
impl
¶ alias of
sqlalchemy.sql.sqltypes.TEXT
-
load_dialect_impl
(dialect)[source]¶ Return a
TypeEngine
object corresponding to a dialect.This is an end-user override hook that can be used to provide differing types depending on the given dialect. It is used by the
TypeDecorator
implementation oftype_engine()
to help determine what type should ultimately be returned for a givenTypeDecorator
.By default returns
self.impl
.
-
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.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-
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.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-
-
class
coaster.sqlalchemy.columns.
UUIDType
(binary=True, native=True)[source]¶ Stores a UUID in the database natively when it can and falls back to a BINARY(16) or a CHAR(32) when it can’t.
from sqlalchemy_utils import UUIDType import uuid class User(Base): __tablename__ = 'user' # Pass `binary=False` to fallback to CHAR instead of BINARY id = sa.Column(UUIDType(binary=False), primary_key=True)
-
load_dialect_impl
(dialect)[source]¶ Return a
TypeEngine
object corresponding to a dialect.This is an end-user override hook that can be used to provide differing types depending on the given dialect. It is used by the
TypeDecorator
implementation oftype_engine()
to help determine what type should ultimately be returned for a givenTypeDecorator
.By default returns
self.impl
.
-
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.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-
process_literal_param
(value, dialect)[source]¶ Receive a literal parameter value to be rendered inline within a statement.
This method is used when the compiler renders a literal value without using binds, typically within DDL such as in the “server default” of a column or an expression within a CHECK constraint.
The returned string will be rendered into the output string.
New in version 0.9.0.
-
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.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-
-
class
coaster.sqlalchemy.columns.
UrlType
(schemes=('http', 'https'), optional_scheme=False, optional_host=False)[source]¶ Extension of URLType from SQLAlchemy-Utils that adds basic validation to ensure URLs are well formed. Parses the value into a
furl
object, allowing manipulation ofParameters: - schemes – Valid URL schemes. Use None to allow any scheme, () for no scheme
- optional_scheme – Schemes are optional (allows URLs starting with
//
) - optional_host – Allow URLs without a hostname (required for
mailto
andfile
schemes)
-
impl
¶ alias of
sqlalchemy.sql.sqltypes.UnicodeText
-
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.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-
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.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-
url_parser
¶ alias of
furl.furl.furl