Module taos.sqlalchemy

Expand source code
from sqlalchemy import types as sqltypes
from sqlalchemy.engine import default, reflection

TYPES_MAP = {
    "bool": sqltypes.Boolean,
    "timestamp": sqltypes.DATETIME,
    "tinyint": sqltypes.SmallInteger,
    "smallint": sqltypes.SmallInteger,
    "int": sqltypes.Integer,
    "bigint": sqltypes.BigInteger,
    "tinyint unsigned": sqltypes.SmallInteger,
    "smallint unsigned": sqltypes.SmallInteger,
    "int unsigned": sqltypes.Integer,
    "bigint unsigned": sqltypes.BigInteger,
    "float": sqltypes.FLOAT,
    "double": sqltypes.DECIMAL,
    "nchar": sqltypes.String,
    "binary": sqltypes.String,
}


class TaosDialect(default.DefaultDialect):
    name = "taos"
    driver = "taos"
    supports_native_boolean = True
    implicit_returning = True

    def do_rollback(self, connection):
        pass

    def _get_server_version_info(self, connection):
        return tuple(connection.connection.server_info)

    @classmethod
    def dbapi(cls):
        import taos

        return taos

    def has_schema(self, connection, schema):
        return False

    def has_table(self, connection, table_name, schema=None):
        try:
            connection.execute("describe {}" % table_name)
            return True
        except:
            return False

    @reflection.cache
    def get_indexes(self, connection, table_name, schema=None, **kw):
        """
        Gets all indexes
        """
        # no index is supported by TDengine
        return []

    def get_columns(self, connection, table_name, schema=None, **kw):
        try:
            cursor = connection.execute("describe {}" % table_name)
            return [row[0] for row in cursor.fetchall()]
        except:
            return []

    def _resolve_type(self, type_):
        return TYPES_MAP.get(type_, sqltypes.UserDefinedType)

Classes

class TaosDialect (convert_unicode=False, encoding='utf-8', paramstyle=None, dbapi=None, implicit_returning=None, case_sensitive=True, supports_native_boolean=None, max_identifier_length=None, label_length=None, compiler_linting=0, server_side_cursors=False, **kwargs)

Default implementation of Dialect

Expand source code
class TaosDialect(default.DefaultDialect):
    name = "taos"
    driver = "taos"
    supports_native_boolean = True
    implicit_returning = True

    def do_rollback(self, connection):
        pass

    def _get_server_version_info(self, connection):
        return tuple(connection.connection.server_info)

    @classmethod
    def dbapi(cls):
        import taos

        return taos

    def has_schema(self, connection, schema):
        return False

    def has_table(self, connection, table_name, schema=None):
        try:
            connection.execute("describe {}" % table_name)
            return True
        except:
            return False

    @reflection.cache
    def get_indexes(self, connection, table_name, schema=None, **kw):
        """
        Gets all indexes
        """
        # no index is supported by TDengine
        return []

    def get_columns(self, connection, table_name, schema=None, **kw):
        try:
            cursor = connection.execute("describe {}" % table_name)
            return [row[0] for row in cursor.fetchall()]
        except:
            return []

    def _resolve_type(self, type_):
        return TYPES_MAP.get(type_, sqltypes.UserDefinedType)

Ancestors

  • sqlalchemy.engine.default.DefaultDialect
  • sqlalchemy.engine.interfaces.Dialect

Class variables

var driver
var implicit_returning
var name
var supports_native_boolean

Static methods

def dbapi()
Expand source code
@classmethod
def dbapi(cls):
    import taos

    return taos

Methods

def do_rollback(self, connection)

Provide an implementation of connection.rollback(), given a DB-API connection.

:param dbapi_connection: a DBAPI connection, typically proxied within a :class:.ConnectionFairy.

Expand source code
def do_rollback(self, connection):
    pass
def get_columns(self, connection, table_name, schema=None, **kw)

Return information about columns in table_name.

Given a :class:_engine.Connection, a string table_name, and an optional string schema, return column information as a list of dictionaries with these keys:

name the column's name

type [sqlalchemy.types#TypeEngine]

nullable boolean

default the column's default value

autoincrement boolean

sequence a dictionary of the form {'name' : str, 'start' :int, 'increment': int, 'minvalue': int, 'maxvalue': int, 'nominvalue': bool, 'nomaxvalue': bool, 'cycle': bool, 'cache': int, 'order': bool}

Additional column attributes may be present.

Expand source code
def get_columns(self, connection, table_name, schema=None, **kw):
    try:
        cursor = connection.execute("describe {}" % table_name)
        return [row[0] for row in cursor.fetchall()]
    except:
        return []
def get_indexes(self, connection, table_name, schema=None, **kw)

Gets all indexes

Expand source code
@reflection.cache
def get_indexes(self, connection, table_name, schema=None, **kw):
    """
    Gets all indexes
    """
    # no index is supported by TDengine
    return []
def has_schema(self, connection, schema)
Expand source code
def has_schema(self, connection, schema):
    return False
def has_table(self, connection, table_name, schema=None)

For internal dialect use, check the existence of a particular table in the database.

Given a :class:_engine.Connection object, a string table_name and optional schema name, return True if the given table exists in the database, False otherwise.

This method serves as the underlying implementation of the public facing :meth:.Inspector.has_table method, and is also used internally to implement the "checkfirst" behavior for methods like :meth:_schema.Table.create and :meth:_schema.MetaData.create_all.

Note: This method is used internally by SQLAlchemy, and is

published so that third-party dialects may provide an implementation. It is not the public API for checking for table presence. Please use the :meth:.Inspector.has_table method. Alternatively, for legacy cross-compatibility, the :meth:_engine.Engine.has_table method may be used.

Expand source code
def has_table(self, connection, table_name, schema=None):
    try:
        connection.execute("describe {}" % table_name)
        return True
    except:
        return False