Ejemplo n.º 1
0
 def create_column(column_dict, table):
     name = column_dict["name"]
     type_ = column_dict["type"]
     available_attrs = [
         "autoincrement",
         "default",
         "doc",
         "key",
         "index",
         "info",
         "nullable",
         "onupdate",
         "primary_key",
         "server_default",
         "server_onupdate",
         "quote",
         "unique",
         "system",
         "comment",
     ]
     column_extras = {k: v for k, v in column_dict.items() if k in available_attrs}
     column = Column(name, type_, **column_extras)
     column.constraints = column_dict["constraints"]
     column.foreign_keys = column_dict["foreign_keys"]
     column.is_literal = column_dict["is_literal"]
     column.table = table
     return column
Ejemplo n.º 2
0
 def visit(self, clause=None):
     from sqlalchemy import Table, Column, MetaData
     if clause:
         return clause.columns[self.name]
     if self.name:
         column = Column(self.name)
     else:
         column = '*'
     if self.table:
         column.table = Table(self.table, MetaData())
     return column
Ejemplo n.º 3
0
    def column(self, column, table=None):
        from copy import deepcopy
        from sqlalchemy import text, Column
        from sqlalchemy.sql.functions import Function

        if hasattr(column, 'copy'):
            column = column.copy()
        else:
            column = deepcopy(column)
        is_null = table is None
        if isinstance(column, Column) and is_null:
            column.table = self.table
            return text(str(column))
        if isinstance(column, Function) and is_null:
            params = self.params(column)
            for param in params:
                self.column(param)
            return column
        if isinstance(column, Column) and not is_null:
            column.table = table
        if isinstance(column, Function) and not is_null:
            column = Column(hash_str(column))
            column.table = table
        return column