labpack/databases/sql.py
def _extract_columns(self, table_name):
        
        ''' a method to extract the column properties of an existing table '''
        
        import re
        from sqlalchemy import MetaData, VARCHAR, INTEGER, BLOB, BOOLEAN, FLOAT
        from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION, BIT, BYTEA, BIGINT
    
    # retrieve list of tables
        metadata_object = MetaData()
        table_list = self.engine.table_names()
    
    # determine columns
        prior_columns = {}
        if table_name in table_list:
            metadata_object.reflect(self.engine)
            existing_table = metadata_object.tables[table_name]
            for column in existing_table.columns:
                column_type = None
                column_length = None
                if column.type.__class__ == FLOAT().__class__:
                    column_type = 'float'
                elif column.type.__class__ == DOUBLE_PRECISION().__class__: # Postgres
                    column_type = 'float'
                elif column.type.__class__ == INTEGER().__class__:
                    column_type = 'integer'
                elif column.type.__class__ == BIGINT().__class__:
                    column_type = 'integer'
                elif column.type.__class__ == VARCHAR().__class__:
                    column_length = getattr(column.type, 'length', None)
                    if column_length == 1:
                        if column.primary_key:
                            column_length = None
                    column_type = 'string'
                elif column.type.__class__ == BLOB().__class__:
                    column_type = 'list'
                elif column.type.__class__ in (BIT().__class__, BYTEA().__class__):
                    column_type = 'list'
                elif column.type.__class__ == BOOLEAN().__class__:
                    column_type = 'boolean'
                prior_columns[column.key] = (column.key, column_type, '', column_length)
        
        return prior_columns
 a method to extract the column properties of an existing table 
a method to extract the column properties of an existing table
a method to extract the column properties of an existing table
def _extract_columns(self, table_name):
        import re
        from sqlalchemy import MetaData, VARCHAR, INTEGER, BLOB, BOOLEAN, FLOAT
        from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION, BIT, BYTEA, BIGINT
        metadata_object = MetaData()
        table_list = self.engine.table_names()
        prior_columns = {}
        if table_name in table_list:
            metadata_object.reflect(self.engine)
            existing_table = metadata_object.tables[table_name]
            for column in existing_table.columns:
                column_type = None
                column_length = None
                if column.type.__class__ == FLOAT().__class__:
                    column_type = 'float'
                elif column.type.__class__ == DOUBLE_PRECISION().__class__: 
                    column_type = 'float'
                elif column.type.__class__ == INTEGER().__class__:
                    column_type = 'integer'
                elif column.type.__class__ == BIGINT().__class__:
                    column_type = 'integer'
                elif column.type.__class__ == VARCHAR().__class__:
                    column_length = getattr(column.type, 'length', None)
                    if column_length == 1:
                        if column.primary_key:
                            column_length = None
                    column_type = 'string'
                elif column.type.__class__ == BLOB().__class__:
                    column_type = 'list'
                elif column.type.__class__ in (BIT().__class__, BYTEA().__class__):
                    column_type = 'list'
                elif column.type.__class__ == BOOLEAN().__class__:
                    column_type = 'boolean'
                prior_columns[column.key] = (column.key, column_type, '', column_length)
        return prior_columns
def _extract_columns ( self , table_name ) : import re from sqlalchemy import MetaData , VARCHAR , INTEGER , BLOB , BOOLEAN , FLOAT from sqlalchemy . dialects . postgresql import DOUBLE_PRECISION , BIT , BYTEA , BIGINT metadata_object = MetaData ( ) table_list = self . engine . table_names ( ) prior_columns = { } if table_name in table_list : metadata_object . reflect ( self . engine ) existing_table = metadata_object . tables [ table_name ] for column in existing_table . columns : column_type = None column_length = None if column . type . __class__ == FLOAT ( ) . __class__ : column_type = 'float' elif column . type . __class__ == DOUBLE_PRECISION ( ) . __class__ : column_type = 'float' elif column . type . __class__ == INTEGER ( ) . __class__ : column_type = 'integer' elif column . type . __class__ == BIGINT ( ) . __class__ : column_type = 'integer' elif column . type . __class__ == VARCHAR ( ) . __class__ : column_length = getattr ( column . type , 'length' , None ) if column_length == 1 : if column . primary_key : column_length = None column_type = 'string' elif column . type . __class__ == BLOB ( ) . __class__ : column_type = 'list' elif column . type . __class__ in ( BIT ( ) . __class__ , BYTEA ( ) . __class__ ) : column_type = 'list' elif column . type . __class__ == BOOLEAN ( ) . __class__ : column_type = 'boolean' prior_columns [ column . key ] = ( column . key , column_type , '' , column_length ) return prior_columns
a method to extract the column properties of an existing table
a method to extract the column properties of an existing table
''' a method to extract the column properties of an existing table ''' # retrieve list of tables # determine columns # Postgres
self
table_name