Support for the Drizzle database.
SQLAlchemy supports the Drizzle database starting with 2010.08. with capabilities increasing with more modern servers.
Most available DBAPI drivers are supported; see below.
Feature | Minimum Version |
---|---|
sqlalchemy.orm | 2010.08 |
Table Reflection | 2010.08 |
DDL Generation | 2010.08 |
utf8/Full Unicode Connections | 2010.08 |
Transactions | 2010.08 |
Two-Phase Transactions | 2010.08 |
Nested Transactions | 2010.08 |
See the official Drizzle documentation for detailed information about features supported in any given server release.
See the API documentation on individual drivers for details on connecting.
Drizzle features an automatic connection close behavior, for connections that have been idle for eight hours or more. To circumvent having this issue, use the pool_recycle option which controls the maximum age of any connection:
engine = create_engine('drizzle+mysqldb://...', pool_recycle=3600)
Drizzle defaults to the InnoDB storage engine, which is transactional.
Storage engines can be elected when creating tables in SQLAlchemy by supplying a drizzle_engine='whatever' to the Table constructor. Any Drizzle table creation option can be specified in this syntax:
Table('mytable', metadata,
Column('data', String(32)),
drizzle_engine='InnoDB',
)
Not all Drizzle storage engines support foreign keys. For BlitzDB and similar engines, the information loaded by table reflection will not include foreign keys. For these tables, you may supply a ForeignKeyConstraint at reflection time:
Table('mytable', metadata,
ForeignKeyConstraint(['other_id'], ['othertable.other_id']),
autoload=True
)
When creating tables, SQLAlchemy will automatically set AUTO_INCREMENT on an integer primary key column:
>>> t = Table('mytable', metadata,
... Column('mytable_id', Integer, primary_key=True)
... )
>>> t.create()
CREATE TABLE mytable (
id INTEGER NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
)
You can disable this behavior by supplying autoincrement=False to the Column. This flag can also be used to enable auto-increment on a secondary column in a multi-column key for some storage engines:
Table('mytable', metadata,
Column('gid', Integer, primary_key=True, autoincrement=False),
Column('id', Integer, primary_key=True)
)
Many of the Drizzle SQL extensions are handled through SQLAlchemy’s generic function and operator support:
table.select(table.c.password==func.md5('plaintext'))
table.select(table.c.username.op('regexp')('^[a-d]'))
And of course any valid Drizzle statement can be executed as a string as well.
Some limited direct support for Drizzle extensions to SQL is currently available.
SELECT pragma:
select(..., prefixes=['HIGH_PRIORITY', 'SQL_SMALL_RESULT'])
UPDATE with LIMIT:
update(..., drizzle_limit=10)
As with all SQLAlchemy dialects, all UPPERCASE types that are known to be valid with Drizzle are importable from the top level dialect:
from sqlalchemy.dialects.drizzle import \
BIGINT, BINARY, BLOB, BOOLEAN, CHAR, DATE, DATETIME,
DECIMAL, DOUBLE, ENUM, FLOAT, INT, INTEGER,
NUMERIC, TEXT, TIME, TIMESTAMP, VARBINARY, VARCHAR
Types which are specific to Drizzle, or have Drizzle-specific construction arguments, are as follows:
Bases: sqlalchemy.types.BIGINT
Drizzle BIGINTEGER type.
Construct a BIGINTEGER.
Bases: sqlalchemy.dialects.drizzle.base._StringType, sqlalchemy.types.CHAR
Drizzle CHAR type, for fixed-length character data.
Construct a CHAR.
Parameters: |
|
---|
Bases: sqlalchemy.dialects.drizzle.base._NumericType, sqlalchemy.types.DECIMAL
Drizzle DECIMAL type.
Construct a DECIMAL.
Parameters: |
|
---|
Bases: sqlalchemy.dialects.drizzle.base._FloatType
Drizzle DOUBLE type.
Construct a DOUBLE.
Parameters: |
|
---|
Bases: sqlalchemy.dialects.mysql.base.ENUM
Drizzle ENUM type.
Construct an ENUM.
Example:
Column(‘myenum’, ENUM(“foo”, “bar”, “baz”))
Parameters: |
|
---|
Bases: sqlalchemy.dialects.drizzle.base._FloatType, sqlalchemy.types.FLOAT
Drizzle FLOAT type.
Construct a FLOAT.
Parameters: |
|
---|
Bases: sqlalchemy.types.INTEGER
Drizzle INTEGER type.
Construct an INTEGER.
Bases: sqlalchemy.dialects.drizzle.base._NumericType, sqlalchemy.types.NUMERIC
Drizzle NUMERIC type.
Construct a NUMERIC.
Parameters: |
|
---|
Bases: sqlalchemy.dialects.drizzle.base._FloatType, sqlalchemy.types.REAL
Drizzle REAL type.
Construct a REAL.
Parameters: |
|
---|
Bases: sqlalchemy.dialects.drizzle.base._StringType, sqlalchemy.types.TEXT
Drizzle TEXT type, for text up to 2^16 characters.
Construct a TEXT.
Parameters: |
|
---|
Bases: sqlalchemy.types.TIMESTAMP
Drizzle TIMESTAMP type.
Bases: sqlalchemy.dialects.drizzle.base._StringType, sqlalchemy.types.VARCHAR
Drizzle VARCHAR type, for variable-length character data.
Construct a VARCHAR.
Parameters: |
|
---|
Support for the Drizzle database via the Drizzle-python adapter.
Drizzle-Python is available at:
At least version 1.2.1 or 1.2.2 should be used.
Drizzle is all utf8 all the time.
Drizzle-python at least as of version 1.2.2 has a serious memory leak related to unicode conversion, a feature which is disabled via use_unicode=0. The recommended connection form with SQLAlchemy is:
engine = create_engine('mysql://scott:tiger@localhost/test?charset=utf8&use_unicode=0', pool_recycle=3600)