Python sqlalchemy.schema.CreateColumn() Examples

The following are 14 code examples of sqlalchemy.schema.CreateColumn(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.schema , or try the search function .
Example #1
Source File: ddl.py    From jbox with MIT License 6 votes vote down vote up
def __init__(
            self, element, on=None, bind=None,
            include_foreign_key_constraints=None):
        """Create a :class:`.CreateTable` construct.

        :param element: a :class:`.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.
        :param include_foreign_key_constraints: optional sequence of
         :class:`.ForeignKeyConstraint` objects that will be included
         inline within the CREATE construct; if omitted, all foreign key
         constraints that do not specify use_alter=True are included.

         .. versionadded:: 1.0.0

        """
        super(CreateTable, self).__init__(element, on=on, bind=bind)
        self.columns = [CreateColumn(column)
                        for column in element.columns
                        ]
        self.include_foreign_key_constraints = include_foreign_key_constraints 
Example #2
Source File: create.py    From spectrify with MIT License 6 votes vote down vote up
def get_table_columns_ddl(self):
        col_descriptors = []
        cols = list(self.sa_table.columns)
        for col in cols:
            # We only want the column name and type.
            # There are no NOT NULL, DEFAULT, etc. clauses in Spectrum
            # Also, we need to replace some types.
            rs_col_cls = col.type.__class__
            if rs_col_cls in type_map:
                spectrum_col_type = type_map[rs_col_cls]()
            else:
                spectrum_col_type = col.type
            spectrum_col = Column(col.description, spectrum_col_type)

            # OK, now get the actual SQL snippet for the column
            statement = CreateColumn(spectrum_col).compile().statement

            col_descriptors.append(str(statement))

        return ',\n    '.join(col_descriptors) 
Example #3
Source File: ddl.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def __init__(
            self, element, on=None, bind=None,
            include_foreign_key_constraints=None):
        """Create a :class:`.CreateTable` construct.

        :param element: a :class:`.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.
        :param include_foreign_key_constraints: optional sequence of
         :class:`.ForeignKeyConstraint` objects that will be included
         inline within the CREATE construct; if omitted, all foreign key
         constraints that do not specify use_alter=True are included.

         .. versionadded:: 1.0.0

        """
        super(CreateTable, self).__init__(element, on=on, bind=bind)
        self.columns = [CreateColumn(column)
                        for column in element.columns
                        ]
        self.include_foreign_key_constraints = include_foreign_key_constraints 
Example #4
Source File: ddl.py    From planespotter with MIT License 6 votes vote down vote up
def __init__(
            self, element, on=None, bind=None,
            include_foreign_key_constraints=None):
        """Create a :class:`.CreateTable` construct.

        :param element: a :class:`.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.
        :param include_foreign_key_constraints: optional sequence of
         :class:`.ForeignKeyConstraint` objects that will be included
         inline within the CREATE construct; if omitted, all foreign key
         constraints that do not specify use_alter=True are included.

         .. versionadded:: 1.0.0

        """
        super(CreateTable, self).__init__(element, on=on, bind=bind)
        self.columns = [CreateColumn(column)
                        for column in element.columns
                        ]
        self.include_foreign_key_constraints = include_foreign_key_constraints 
Example #5
Source File: ddl.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
def __init__(
            self, element, on=None, bind=None,
            include_foreign_key_constraints=None):
        """Create a :class:`.CreateTable` construct.

        :param element: a :class:`.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.
        :param include_foreign_key_constraints: optional sequence of
         :class:`.ForeignKeyConstraint` objects that will be included
         inline within the CREATE construct; if omitted, all foreign key
         constraints that do not specify use_alter=True are included.

         .. versionadded:: 1.0.0

        """
        super(CreateTable, self).__init__(element, on=on, bind=bind)
        self.columns = [CreateColumn(column)
                        for column in element.columns
                        ]
        self.include_foreign_key_constraints = include_foreign_key_constraints 
Example #6
Source File: ddl.py    From sqlalchemy with MIT License 6 votes vote down vote up
def __init__(
        self, element, bind=None, include_foreign_key_constraints=None
    ):
        """Create a :class:`.CreateTable` construct.

        :param element: a :class:`_schema.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.
        :param include_foreign_key_constraints: optional sequence of
         :class:`_schema.ForeignKeyConstraint` objects that will be included
         inline within the CREATE construct; if omitted, all foreign key
         constraints that do not specify use_alter=True are included.

         .. versionadded:: 1.0.0

        """
        super(CreateTable, self).__init__(element, bind=bind)
        self.columns = [CreateColumn(column) for column in element.columns]
        self.include_foreign_key_constraints = include_foreign_key_constraints 
Example #7
Source File: ddl.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
def __init__(
            self, element, on=None, bind=None,
            include_foreign_key_constraints=None):
        """Create a :class:`.CreateTable` construct.

        :param element: a :class:`.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.
        :param include_foreign_key_constraints: optional sequence of
         :class:`.ForeignKeyConstraint` objects that will be included
         inline within the CREATE construct; if omitted, all foreign key
         constraints that do not specify use_alter=True are included.

         .. versionadded:: 1.0.0

        """
        super(CreateTable, self).__init__(element, on=on, bind=bind)
        self.columns = [CreateColumn(column)
                        for column in element.columns
                        ]
        self.include_foreign_key_constraints = include_foreign_key_constraints 
Example #8
Source File: ddl.py    From android_universal with MIT License 6 votes vote down vote up
def __init__(
            self, element, on=None, bind=None,
            include_foreign_key_constraints=None):
        """Create a :class:`.CreateTable` construct.

        :param element: a :class:`.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.
        :param include_foreign_key_constraints: optional sequence of
         :class:`.ForeignKeyConstraint` objects that will be included
         inline within the CREATE construct; if omitted, all foreign key
         constraints that do not specify use_alter=True are included.

         .. versionadded:: 1.0.0

        """
        super(CreateTable, self).__init__(element, on=on, bind=bind)
        self.columns = [CreateColumn(column)
                        for column in element.columns
                        ]
        self.include_foreign_key_constraints = include_foreign_key_constraints 
Example #9
Source File: ddl.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, element, on=None, bind=None):
        """Create a :class:`.CreateTable` construct.

        :param element: a :class:`.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.

        """
        super(CreateTable, self).__init__(element, on=on, bind=bind)
        self.columns = [CreateColumn(column)
                        for column in element.columns
                        ] 
Example #10
Source File: test_sqlite.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_on_conflict_clause_column_not_null(self):
        c = Column(
            "test", Integer, nullable=False, sqlite_on_conflict_not_null="FAIL"
        )

        self.assert_compile(
            schema.CreateColumn(c),
            "test INTEGER NOT NULL " "ON CONFLICT FAIL",
            dialect=sqlite.dialect(),
        ) 
Example #11
Source File: test_types.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_timestamp_defaults(self, spec, kw, expected):
        """Exercise funky TIMESTAMP default syntax when used in columns."""

        c = Column("t", *spec, **kw)
        Table("t", MetaData(), c)
        self.assert_compile(schema.CreateColumn(c), "t %s" % expected) 
Example #12
Source File: test_constraints.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_render_check_constraint_inline_sql_literal(self):
        t, t2 = self._constraint_create_fixture()

        m = MetaData()
        t = Table(
            "t",
            m,
            Column("a", Integer, CheckConstraint(Column("a", Integer) > 5)),
        )

        self.assert_compile(
            schema.CreateColumn(t.c.a), "a INTEGER CHECK (a > 5)"
        ) 
Example #13
Source File: test_metadata.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_custom_create(self):
        from sqlalchemy.ext.compiler import compiles, deregister

        @compiles(schema.CreateColumn)
        def compile_(element, compiler, **kw):
            column = element.element

            if "special" not in column.info:
                return compiler.visit_create_column(element, **kw)

            text = "%s SPECIAL DIRECTIVE %s" % (
                column.name,
                compiler.type_compiler.process(column.type),
            )
            default = compiler.get_column_default_string(column)
            if default is not None:
                text += " DEFAULT " + default

            if not column.nullable:
                text += " NOT NULL"

            if column.constraints:
                text += " ".join(
                    compiler.process(const) for const in column.constraints
                )
            return text

        t = Table(
            "mytable",
            MetaData(),
            Column("x", Integer, info={"special": True}, primary_key=True),
            Column("y", String(50)),
            Column("z", String(20), info={"special": True}),
        )

        self.assert_compile(
            schema.CreateTable(t),
            "CREATE TABLE mytable (x SPECIAL DIRECTIVE INTEGER "
            "NOT NULL, y VARCHAR(50), "
            "z SPECIAL DIRECTIVE VARCHAR(20), PRIMARY KEY (x))",
        )

        deregister(schema.CreateColumn) 
Example #14
Source File: ddl.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, element, on=None, bind=None):
        """Create a :class:`.CreateTable` construct.

        :param element: a :class:`.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.

        """
        super(CreateTable, self).__init__(element, on=on, bind=bind)
        self.columns = [CreateColumn(column)
            for column in element.columns
        ]