json_serializable

Json serializable type.

class sqlalchemy_mate.types.json_serializable.JSONSerializableType(*args, **kwargs)[source]

This column store json serialized python object in form of

This column should be a json serializable python type such as combination of list, dict, string, int, float, bool.

Usage:

import jsonpickle

# a custom python class class ComputerDetails:

def __init__(self, …):

def to_json(self) -> str:

return jsonpickle.encode(self)

@classmethod def from_json(cls, json_str: str) -> ‘Computer’:

return cls(**jsonpickle.decode(json_str))

Base = declarative_base()

class Computer(Base):

id = Column(Integer, primary_key) details = Column(JSONSerializableType(factory_class=Computer)

computer = Computer(

id=1, details=ComputerDetails(…),

)

with Session(engine) as session:

session.add(computer) session.commit()

computer = session.get(Computer, 1) print(computer.details)

impl

alias of sqlalchemy.sql.sqltypes.UnicodeText

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 of type_engine() to help determine what type should ultimately be returned for a given TypeDecorator.

By default returns self.impl.

process_bind_param(value, dialect) Optional[str][source]

Receive a bound parameter value to be converted.

Custom subclasses of _types.TypeDecorator should override this method to provide custom behaviors for incoming data values. This method is called at statement execution time and is passed the literal Python data value which is to be associated with a bound parameter in the statement.

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.

See also

types_typedecorator

_types.TypeDecorator.process_result_value()

process_result_value(value: Optional[str], dialect)[source]

Receive a result-row column value to be converted.

Custom subclasses of _types.TypeDecorator should override this method to provide custom behaviors for data values being received in result rows coming from the database. This method is called at result fetching time and is passed the literal Python data value that’s extracted from a database result row.

The operation could be anything desired to perform custom behavior, such as transforming or deserializing data.

Parameters
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.

  • dialect – the Dialect in use.

See also

types_typedecorator

_types.TypeDecorator.process_bind_param()