sqlalchemy Package

sqlalchemy Package

compiler Module

class crate.client.sqlalchemy.compiler.CrateCompiler(dialect, statement, column_keys=None, inline=False, **kwargs)

Bases: sqlalchemy.sql.compiler.SQLCompiler

visit_getitem_binary(binary, operator, **kw)
visit_update(update_stmt, **kw)

used to compile <sql.expression.Update> expressions

only implements a subset of the SQLCompiler.visit_update method e.g. updating multiple tables is not supported.

crate.client.sqlalchemy.compiler.crate_before_execute(conn, clauseelement, multiparams, params)
crate.client.sqlalchemy.compiler.rewrite_update(clauseelement, multiparams, params)

change the params to enable partial updates

sqlalchemy by default only supports updates of complex types in the form of

“col = ?”, ({“x”: 1, “y”: 2}

but crate supports

“col[‘x’] = ?, col[‘y’] = ?”, (1, 2)

by using the Craty (MutableDict) type. The update statement is only rewritten if a item of the MutableDict was changed.

dialect Module

class crate.client.sqlalchemy.dialect.CrateDialect(*args, **kwargs)

Bases: sqlalchemy.engine.default.DefaultDialect

colspecs = {<class 'sqlalchemy.types.DateTime'>: <class 'crate.client.sqlalchemy.dialect.DateTime'>, <class 'sqlalchemy.types.Date'>: <class 'crate.client.sqlalchemy.dialect.Date'>}
connect(host=None, port=None, *args, **kwargs)
classmethod dbapi()
do_rollback(connection)
initialize(connection)
name = 'crate'
statement_compiler

alias of CrateCompiler

class crate.client.sqlalchemy.dialect.Date(*args, **kwargs)

Bases: sqlalchemy.types.Date

bind_processor(dialect)
result_processor(dialect, coltype)
class crate.client.sqlalchemy.dialect.DateTime(timezone=False)

Bases: sqlalchemy.types.DateTime

bind_processor(dialect)
result_processor(dialect, coltype)

test Module

class crate.client.sqlalchemy.test.SqlAlchemyConnectionTest(methodName='runTest')

Bases: unittest.case.TestCase

setUp()
test_connection_multiple_server()
test_connection_server()
test_default_connection()
class crate.client.sqlalchemy.test.SqlAlchemyDateAndDateTimeTest(methodName='runTest')

Bases: unittest.case.TestCase

setUp()
test_date_can_handle_datetime(*args, **keywargs)

date type should also be able to handle iso datetime strings.

this verifies that the fallback in the Date result_processor works.

class crate.client.sqlalchemy.test.SqlAlchemyDictTypeTest(methodName='runTest')

Bases: unittest.case.TestCase

assertSQL(expected_str, actual_expr)
setUp()
set_up_character_and_cursor(return_value=None)
test_assign_to_craty_type_after_commit(*args, **keywargs)
test_change_tracking(*args, **keywargs)
test_partial_dict_update(*args, **keywargs)
test_partial_dict_update_only_one_key_changed(*args, **keywargs)

if only one attribute of Craty is changed the update should only update that attribute not all attributes of Craty

test_partial_dict_update_with_delitem(*args, **keywargs)
test_partial_dict_update_with_delitem_setitem(*args, **keywargs)

test that the change tracking doesn’t get messed up

delitem -> setitem

test_partial_dict_update_with_regular_column(*args, **keywargs)
test_partial_dict_update_with_setitem_delitem(*args, **keywargs)

test that the change tracking doesn’t get messed up

setitem -> delitem

test_partial_dict_update_with_setitem_delitem_setitem(*args, **keywargs)

test that the change tracking doesn’t get messed up

setitem -> delitem -> setitem

test_select_with_dict_column()
test_select_with_dict_column_nested_where()
test_select_with_dict_column_where_clause()
test_select_with_dict_column_where_clause_gt()
test_select_with_dict_column_where_clause_other_col()
test_update_with_dict_column()

types Module

class crate.client.sqlalchemy.types.MutableDict(initval=None)

Bases: sqlalchemy.ext.mutable.Mutable, dict

classmethod coerce(key, value)

Convert plain dictionaries to MutableDict.