当前位置: 首页>>代码示例>>Python>>正文


Python sqlalchemy.DDL属性代码示例

本文整理汇总了Python中sqlalchemy.DDL属性的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.DDL属性的具体用法?Python sqlalchemy.DDL怎么用?Python sqlalchemy.DDL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在sqlalchemy的用法示例。


在下文中一共展示了sqlalchemy.DDL属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
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 
开发者ID:jpush,项目名称:jbox,代码行数:24,代码来源:ddl.py

示例2: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def upgrade():
    conn = op.get_bind()
    func = sa.DDL("""CREATE FUNCTION set_meta_updated()
                      RETURNS TRIGGER
                      LANGUAGE plpgsql
                    AS $$
                    BEGIN
                      NEW.meta_updated := now();
                      RETURN NEW;
                    END;
                    $$;""")
    conn.execute(func)

    for table in updatable_tables:
        trigger_params = {'trigger': ('%s_set_meta_updated' % table), 'table': table}
        trigger = ("""CREATE TRIGGER %(trigger)s
                    BEFORE UPDATE ON %(table)s
                    FOR EACH ROW EXECUTE PROCEDURE set_meta_updated();""" % trigger_params)
        conn.execute(trigger) 
开发者ID:opentrials,项目名称:collectors,代码行数:21,代码来源:20170123151655_add_trigger_for_meta_updated.py

示例3: add_new_photo_to_session

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def add_new_photo_to_session(session, *, id, **kwargs):
    """Create a new Photo and update the referenced PhotoAnswer."""
    try:
        answer = (
            session
            .query(PhotoAnswer)
            .filter_by(main_answer=id)
            .one()
        )
    except NoResultFound:
        raise PhotoIdDoesNotExistError(id)
    with session.begin():
        answer.photo = Photo(id=id, **kwargs)
        answer.actual_photo_id = answer.main_answer
    return answer.photo


# sa.event.listen(
#     Photo.__table__,
#     'after_create',
#     sa.DDL(
#         'CREATE TRIGGER t_image BEFORE UPDATE OR DELETE ON photo'
#         ' FOR EACH ROW EXECUTE PROCEDURE lo_manage(image)'
#     ),
# ) 
开发者ID:SEL-Columbia,项目名称:dokomoforms,代码行数:27,代码来源:answer.py

示例4: __init__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
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 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:ddl.py

示例5: define_tables

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def define_tables(cls, metadata):
        # the actual function isn't reflected yet
        dv = Table(
            "data_values",
            metadata,
            Column("modulus", Integer, nullable=False),
            Column("data", String(30)),
            Column("q", Integer),
            postgresql_partition_by="range(modulus)",
        )

        # looks like this is reflected prior to #4237
        sa.event.listen(
            dv,
            "after_create",
            sa.DDL(
                "CREATE TABLE data_values_4_10 PARTITION OF data_values "
                "FOR VALUES FROM (4) TO (10)"
            ),
        )

        if testing.against("postgresql >= 11"):
            Index("my_index", dv.c.q) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_reflection.py

示例6: execute

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def execute(self, bind=None, target=None):
        """Execute this DDL immediately.

        Executes the DDL statement in isolation using the supplied
        :class:`.Connectable` or
        :class:`.Connectable` assigned to the ``.bind``
        property, if not supplied. If the DDL has a conditional ``on``
        criteria, it will be invoked with None as the event.

        :param bind:
          Optional, an ``Engine`` or ``Connection``. If not supplied, a valid
          :class:`.Connectable` must be present in the
          ``.bind`` property.

        :param target:
          Optional, defaults to None.  The target SchemaItem for the
          execute call.  Will be passed to the ``on`` callable if any,
          and may also provide string expansion data for the
          statement. See ``execute_at`` for more information.

        """

        if bind is None:
            bind = _bind_or_error(self)

        if self._should_execute(target, bind):
            return bind.execute(self.against(target))
        else:
            bind.engine.logger.info(
                "DDL execution skipped, criteria not met.") 
开发者ID:jpush,项目名称:jbox,代码行数:32,代码来源:ddl.py

示例7: execute_at

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def execute_at(self, event_name, target):
        """Link execution of this DDL to the DDL lifecycle of a SchemaItem.

        Links this ``DDLElement`` to a ``Table`` or ``MetaData`` instance,
        executing it when that schema item is created or dropped. The DDL
        statement will be executed using the same Connection and transactional
        context as the Table create/drop itself. The ``.bind`` property of
        this statement is ignored.

        :param event:
          One of the events defined in the schema item's ``.ddl_events``;
          e.g. 'before-create', 'after-create', 'before-drop' or 'after-drop'

        :param target:
          The Table or MetaData instance for which this DDLElement will
          be associated with.

        A DDLElement instance can be linked to any number of schema items.

        ``execute_at`` builds on the ``append_ddl_listener`` interface of
        :class:`.MetaData` and :class:`.Table` objects.

        Caveat: Creating or dropping a Table in isolation will also trigger
        any DDL set to ``execute_at`` that Table's MetaData.  This may change
        in a future release.

        """

        def call_event(target, connection, **kw):
            if self._should_execute_deprecated(event_name,
                                               target, connection, **kw):
                return connection.execute(self.against(target))

        event.listen(target, "" + event_name.replace('-', '_'), call_event) 
开发者ID:jpush,项目名称:jbox,代码行数:36,代码来源:ddl.py

示例8: against

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def against(self, target):
        """Return a copy of this DDL against a specific schema item."""

        self.target = target 
开发者ID:jpush,项目名称:jbox,代码行数:6,代码来源:ddl.py

示例9: __call__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def __call__(self, target, bind, **kw):
        """Execute the DDL as a ddl_listener."""

        if self._should_execute(target, bind, **kw):
            return bind.execute(self.against(target)) 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:ddl.py

示例10: downgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def downgrade():
    conn = op.get_bind()
    for table in updatable_tables:
        trigger_params = {'trigger': ('%s_set_meta_updated' % table), 'table': table}
        trigger = ('DROP TRIGGER %(trigger)s ON %(table)s;' % trigger_params)
        conn.execute(trigger)

    conn.execute(sa.DDL('DROP FUNCTION set_meta_updated();')) 
开发者ID:opentrials,项目名称:collectors,代码行数:10,代码来源:20170123151655_add_trigger_for_meta_updated.py

示例11: setUpModule

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def setUpModule():
    """Create the tables in the doko_test schema."""
    engine.execute(DDL('DROP SCHEMA IF EXISTS doko_test CASCADE'))
    try:
        Base.metadata.create_all(engine)
    except Exception:
        engine.execute(DDL('DROP SCHEMA IF EXISTS doko_test CASCADE'))
        raise 
开发者ID:SEL-Columbia,项目名称:dokomoforms,代码行数:10,代码来源:util.py

示例12: tearDownModule

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DDL [as 别名]
def tearDownModule():
    """Drop the doko_test schema."""
    engine.execute(DDL('DROP SCHEMA IF EXISTS doko_test CASCADE')) 
开发者ID:SEL-Columbia,项目名称:dokomoforms,代码行数:5,代码来源:util.py


注:本文中的sqlalchemy.DDL属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。