SQLAlchemy 0.5 Documentation

Multiple Pages | One Page
Version: 0.5.0rc3 Last Updated: 11/07/08 13:55:35

module sqlalchemy.types

defines genericized SQL types, each represented by a subclass of AbstractType. Dialects define further subclasses of these types.

For more information see the SQLAlchemy documentation on types.

class AbstractType(object)

def __init__(self, *args, **kwargs)

Construct a new AbstractType.

def adapt_operator(self, op)

given an operator from the sqlalchemy.sql.operators package, translate it to a new operator based on the semantics of this type.

By default, returns the operator unchanged.

def bind_processor(self, dialect)

Defines a bind parameter processing function.

def compare_values(self, x, y)

compare two values for equality.

def copy_value(self, value)
def get_dbapi_type(self, dbapi)

Return the corresponding type object from the underlying DB-API, if any.

This can be useful for calling setinputsizes(), for example.

def is_mutable(self)

return True if the target Python type is 'mutable'.

This allows systems like the ORM to know if an object can be considered 'not changed' by identity alone.

def result_processor(self, dialect)

Defines a result-column processing function.

back to section top

class BLOB(Binary)

The SQL BLOB type.

back to section top

class BOOLEAN(Boolean)

The SQL BOOLEAN type.

back to section top

class Binary(TypeEngine)

def __init__(self, length=None)

Construct a new Binary.

def adapt(self, impltype)
def bind_processor(self, dialect)
def get_dbapi_type(self, dbapi)
back to section top

class Boolean(TypeEngine)

back to section top

class CHAR(String)

The SQL CHAR type.

back to section top

class CLOB(Text)

The SQL CLOB type.

back to section top

class Concatenable(object)

marks a type as supporting 'concatenation'

def adapt_operator(self, op)
back to section top

class DATE(Date)

The SQL DATE type.

back to section top

class DATETIME(DateTime)

The SQL DATETIME type.

back to section top

class DECIMAL(Numeric)

The SQL DECIMAL type.

back to section top

class Date(TypeEngine)

Implement a type for datetime.date() objects.

def get_dbapi_type(self, dbapi)
back to section top

class DateTime(TypeEngine)

Implement a type for datetime.datetime() objects.

def __init__(self, timezone=False)

Construct a new DateTime.

def adapt(self, impltype)
def get_dbapi_type(self, dbapi)
back to section top

class FLOAT(Float)

The SQL FLOAT type.

back to section top

class Float(Numeric)

def __init__(self, precision=10, asdecimal=False, **kwargs)

Construct a new Float.

def adapt(self, impltype)
back to section top

class INT(Integer)

The SQL INT or INTEGER type.

back to section top

class Integer(TypeEngine)

Integer datatype.

def get_dbapi_type(self, dbapi)
back to section top

class Interval(TypeDecorator)

Type to be used in Column statements to store python timedeltas.

If it's possible it uses native engine features to store timedeltas (now it's only PostgreSQL Interval type), if there is no such it fallbacks to DateTime storage with converting from/to timedelta on the fly

Converting is very simple - just use epoch(zero timestamp, 01.01.1970) as base, so if we need to store timedelta = 1 day (24 hours) in database it will be stored as DateTime = '2nd Jan 1970 00:00', see bind_processor and result_processor to actual conversion code

def __init__(self)

Construct a new Interval.

def load_dialect_impl(self, dialect)
def process_bind_param(self, value, dialect)
def process_result_value(self, value, dialect)
back to section top

class MutableType(object)

A mixin that marks a Type as holding a mutable object.

def compare_values(self, x, y)
def copy_value(self, value)
def is_mutable(self)
back to section top

class NCHAR(Unicode)

The SQL NCHAR type.

back to section top

class NUMERIC(Numeric)

The SQL NUMERIC type.

back to section top

class Numeric(TypeEngine)

Numeric datatype, usually resolves to DECIMAL or NUMERIC.

def __init__(self, precision=10, scale=2, asdecimal=True, length=None)

Construct a new Numeric.

def adapt(self, impltype)
def bind_processor(self, dialect)
def get_dbapi_type(self, dbapi)
def result_processor(self, dialect)
back to section top

class PickleType(MutableType,TypeDecorator)

def __init__(self, protocol=2, pickler=None, mutable=True, comparator=None)

Construct a new PickleType.

def compare_values(self, x, y)
def copy_value(self, value)
def is_mutable(self)
def process_bind_param(self, value, dialect)
def process_result_value(self, value, dialect)
back to section top

class SMALLINT(SmallInteger)

The SQL SMALLINT type.

back to section top

class SmallInteger(Integer)

Smallint datatype.

back to section top

class String(Concatenable,TypeEngine)

A sized string type.

In SQL, corresponds to VARCHAR. Can also take Python unicode objects and encode to the database's encoding in bind params (and the reverse for result sets.)

The length field is usually required when the String type is used within a CREATE TABLE statement, since VARCHAR requires a length on most databases. Currently SQLite is an exception to this.

def __init__(self, length=None, convert_unicode=False, assert_unicode=None)

Construct a new String.

def adapt(self, impltype)
def bind_processor(self, dialect)
def get_dbapi_type(self, dbapi)
def result_processor(self, dialect)
back to section top

class TIME(Time)

The SQL TIME type.

back to section top

class TIMESTAMP(DateTime)

The SQL TIMESTAMP type.

back to section top

class Text(String)

def dialect_impl(self, dialect, **kwargs)
back to section top

class Time(TypeEngine)

Implement a type for datetime.time() objects.

def __init__(self, timezone=False)

Construct a new Time.

def adapt(self, impltype)
def get_dbapi_type(self, dbapi)
back to section top

class TypeDecorator(AbstractType)

Allows the creation of types which add additional functionality to an existing type. Typical usage:

class MyCustomType(TypeDecorator):
    impl = String

    def process_bind_param(self, value, dialect):
        return value + "incoming string"

    def process_result_value(self, value, dialect):
        return value[0:-16]

The class-level "impl" variable is required, and can reference any TypeEngine class. Alternatively, the load_dialect_impl() method can be used to provide different type classes based on the dialect given; in this case, the "impl" variable can reference TypeEngine as a placeholder.

def __init__(self, *args, **kwargs)

Construct a new TypeDecorator.

def bind_processor(self, dialect)
def compare_values(self, x, y)
def copy(self)
def copy_value(self, value)
def dialect_impl(self, dialect, **kwargs)
def get_col_spec(self)
def get_dbapi_type(self, dbapi)
def is_mutable(self)
def load_dialect_impl(self, dialect)

loads the dialect-specific implementation of this type.

by default calls dialect.type_descriptor(self.impl), but can be overridden to provide different behavior.

def process_bind_param(self, value, dialect)
def process_result_value(self, value, dialect)
def result_processor(self, dialect)
def __getattr__(self, key)

Proxy all other undefined accessors to the underlying implementation.

back to section top

class TypeEngine(AbstractType)

def adapt(self, cls)
def bind_processor(self, dialect)
def dialect_impl(self, dialect, **kwargs)
def get_col_spec(self)
def get_search_list(self)

return a list of classes to test for a match when adapting this type to a dialect-specific type.

def result_processor(self, dialect)
back to section top

class Unicode(String)

A synonym for String(length, convert_unicode=True, assert_unicode='warn').

def __init__(self, length=None, **kwargs)

Construct a new Unicode.

back to section top

class UnicodeText(Text)

A synonym for Text(convert_unicode=True, assert_unicode='warn').

def __init__(self, length=None, **kwargs)

Construct a new UnicodeText.

back to section top

class VARCHAR(String)

The SQL VARCHAR type.

back to section top
Up: API Documentation | Previous: module sqlalchemy.sql.expression | Next: module sqlalchemy.orm