fictive.transform.ext.sqlalchemy package

Module contents

Integrating Transform with SQLAlchemy

class fictive.transform.ext.sqlalchemy.TransformColumnType(base_type, transform, *args, pass_null=True, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

A TypeDecorator (i.e., SQLAlchemy column type) that automatically applies a transform

__init__(base_type, transform, *args, pass_null=True, **kwargs)[source]

Construct a TypeDecorator.

Arguments sent here are passed to the constructor of the class assigned to the impl class level attribute, assuming the impl is a callable, and the resulting object is assigned to the self.impl instance attribute (thus overriding the class attribute of the same name).

If the class level impl is not a callable (the unusual case), it will be assigned to the same instance attribute ‘as-is’, ignoring those arguments passed to the constructor.

Subclasses can override this to customize the generation of self.impl entirely.

impl

alias of sqlalchemy.sql.type_api.TypeEngine

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)[source]

reverse transform of external value to database value

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]

transform database value to external value

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 int for 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 None from any type in practice.