fictive.sqlalchemy.types module¶
Custom SQLAlchemy column types
Classes
Emulates a Python |
-
class
fictive.sqlalchemy.types.SET(*args, **kwargs)[source]¶ Bases:
sqlalchemy.sql.type_api.TypeDecoratorEmulates a Python
settype using ansqlalchemy.types.JSONback endA set object is an unordered collection of distinct objects. SQL does not natively support guaranteed distinct collections, but this constraint can be enforced by the
sqlalchemy.types.TypeEnginewhen reading from and writing to the database, and usingsqlalchemy.eventhooks when assigning to an ORM attribute. E.g.:from sqlalchemy import Column, Integer from fictive.sqlalchemy.types import SET class Model(DeclarativeBase): __tablename__ = 'model' id = Column(Integer, primary_key=True) set_column = Column(SET) DeclarativeBase.metadata.create_all(engine)
>>> instance = Model(set_column=[1, 2, 2, 3, 4, 3]) >>> session.add(instance) >>> session.commit() >>> instance.set_column {1, 2, 3, 4}
-
impl¶ alias of
sqlalchemy.sql.sqltypes.JSON
-
process_bind_param(value, dialect)[source]¶ remove duplicate elements & convert to a JSON-compatible type (
list)
-
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.
-
property
python_type¶ Return the Python type object expected to be returned by instances of this type, if known.
Basically, for those types which enforce a return type, or are known across the board to do such for all common DBAPIs (like
intfor example), will return that type.If a return type is not defined, raises
NotImplementedError.Note that any type also accommodates NULL in SQL which means you can also get back
Nonefrom any type in practice.
-