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


Python sqlalchemy.Sequence方法代码示例

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


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

示例1: initialize_model

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def initialize_model(cls):
        """ Create the sequence to determine name """
        super(Sequence, cls).initialize_model()
        seq = SQLASequence(cls._cls_seq_name)
        seq.create(cls.registry.bind)

        to_create = getattr(cls.registry,
                            '_need_sequence_to_create_if_not_exist', ())
        if to_create is None:
            return

        for vals in to_create:
            if cls.query().filter(cls.code == vals['code']).count():
                continue

            formatter = vals.get('formater')
            if formatter is None:
                del vals['formater']

            cls.insert(**vals) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:22,代码来源:sequence.py

示例2: create_sequence

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def create_sequence(cls, values):
        """Create the database sequence for an instance of Sequence Model.

        :return: suitable field values for insertion of the Model instance
        :rtype: dict
        """
        seq_name = values.get('seq_name')
        if seq_name is None:
            seq_id = cls.registry.execute(SQLASequence(cls._cls_seq_name))
            seq_name = '%s_%d' % (cls.__tablename__, seq_id)
            values['seq_name'] = seq_name

        number = values.setdefault('number', 0)
        if number:
            seq = SQLASequence(seq_name, number)
        else:
            seq = SQLASequence(seq_name)
        seq.create(cls.registry.bind)
        return values 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:21,代码来源:sequence.py

示例3: generate_ori_identifier

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def generate_ori_identifier(self, iri):
        """
        Generates a Resource with an ORI identifier and adds the IRI as a Source if it does not already exist.
        """

        session = self.Session()
        new_id = self.engine.execute(Sequence('ori_id_seq'))
        new_identifier = Uri(Ori, new_id)

        try:
            # If the resource already exists, create the source as a child of the resource
            resource = session.query(Source).filter(Source.iri == iri).one().resource
            resource.sources.append(Source(iri=iri))
            session.flush()
        except NoResultFound:
            # If the resource does not exist, create resource and source together
            resource = Resource(ori_id=new_id, iri=new_identifier, sources=[Source(iri=iri)])
            session.add(resource)
            session.commit()
        finally:
            session.close()

        return new_identifier 
开发者ID:openstate,项目名称:open-raadsinformatie,代码行数:25,代码来源:postgres_database.py

示例4: _create_users_addresses_tables

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def _create_users_addresses_tables(engine_testaccount, metadata):
    users = Table('users', metadata,
                  Column('id', Integer, Sequence('user_id_seq'),
                         primary_key=True),
                  Column('name', String),
                  Column('fullname', String),
                  )

    addresses = Table('addresses', metadata,
                      Column('id', Integer, Sequence('address_id_seq'),
                             primary_key=True),
                      Column('user_id', None, ForeignKey('users.id')),
                      Column('email_address', String, nullable=False)
                      )
    metadata.create_all(engine_testaccount)
    return users, addresses 
开发者ID:snowflakedb,项目名称:snowflake-sqlalchemy,代码行数:18,代码来源:test_pandas.py

示例5: _create_sequence

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def _create_sequence(table_name: Text) -> "Sequence":
    """Creates a sequence object for a specific table name.

    If using Oracle you will need to create a sequence in your database,
    as described here: https://rasa.com/docs/rasa/api/tracker-stores/#sqltrackerstore
    Args:
        table_name: The name of the table, which gets a Sequence assigned

    Returns: A `Sequence` object
    """

    from sqlalchemy.ext.declarative import declarative_base

    sequence_name = f"{table_name}_seq"
    Base = declarative_base()
    return sa.Sequence(sequence_name, metadata=Base.metadata, optional=True) 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:18,代码来源:tracker_store.py

示例6: test_sequence_not_duped

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def test_sequence_not_duped(self):
        engine, buf = self._engine_fixture()
        metadata = MetaData()
        t = Table(
            "testtable",
            metadata,
            Column(
                "pk", Integer, Sequence("testtable_pk_seq"), primary_key=True,
            ),
        )

        t.create(engine)
        t.drop(engine)

        eq_(re.findall(r"CREATE (\w+)", buf.getvalue()), ["SEQUENCE", "TABLE"])

        eq_(re.findall(r"DROP (\w+)", buf.getvalue()), ["TABLE", "SEQUENCE"]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_execute.py

示例7: test_strlen

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def test_strlen(self):
        metadata = self.metadata

        # On FB the length() function is implemented by an external UDF,
        # strlen().  Various SA tests fail because they pass a parameter
        # to it, and that does not work (it always results the maximum
        # string length the UDF was declared to accept). This test
        # checks that at least it works ok in other cases.

        t = Table(
            "t1",
            metadata,
            Column("id", Integer, Sequence("t1idseq"), primary_key=True),
            Column("name", String(10)),
        )
        metadata.create_all()
        t.insert(values=dict(name="dante")).execute()
        t.insert(values=dict(name="alighieri")).execute()
        select(
            [func.count(t.c.id)], func.length(t.c.name) == 5
        ).execute().first()[0] == 1 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_firebird.py

示例8: test_format

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def test_format(self):
        seq = Sequence("my_seq_no_schema")
        dialect = postgresql.dialect()
        assert (
            dialect.identifier_preparer.format_sequence(seq)
            == "my_seq_no_schema"
        )
        seq = Sequence("my_seq", schema="some_schema")
        assert (
            dialect.identifier_preparer.format_sequence(seq)
            == "some_schema.my_seq"
        )
        seq = Sequence("My_Seq", schema="Some_Schema")
        assert (
            dialect.identifier_preparer.format_sequence(seq)
            == '"Some_Schema"."My_Seq"'
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_compiler.py

示例9: test_insert_from_select_seq

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def test_insert_from_select_seq(self):
        m = MetaData()

        t1 = Table(
            "t",
            m,
            Column("id", Integer, Sequence("id_seq"), primary_key=True),
            Column("data", String),
        )

        stmt = t1.insert().from_select(("data",), select([t1.c.data]))

        self.assert_compile(
            stmt,
            "INSERT INTO t (data, id) SELECT t.data, "
            "nextval('id_seq') AS next_value_1 FROM t",
            dialect=postgresql.dialect(),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_insert.py

示例10: dataset_no_autoinc

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def dataset_no_autoinc(self, metadata):
        # plain autoincrement/PK table in the actual schema
        Table("x", metadata, Column("set_id", Integer, primary_key=True))

        # for the INSERT use a table with a Sequence
        # and autoincrement=False.  Using a ForeignKey
        # would have the same effect

        some_seq = Sequence("some_seq")

        dataset_no_autoinc = Table(
            "x",
            MetaData(),
            Column(
                "set_id",
                Integer,
                some_seq,
                primary_key=True,
                autoincrement=False,
            ),
        )
        return dataset_no_autoinc 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_defaults.py

示例11: test_col_w_optional_sequence_non_autoinc_no_firing

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def test_col_w_optional_sequence_non_autoinc_no_firing(
        self, dataset_no_autoinc, connection
    ):
        """this is testing that a Table which includes a Sequence, when
        run against a DB that does not support sequences, the Sequence
        does not get in the way.

        """
        dataset_no_autoinc.c.set_id.default.optional = True

        connection.execute(dataset_no_autoinc.insert())
        eq_(
            connection.scalar(
                select([func.count("*")]).select_from(dataset_no_autoinc)
            ),
            1,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_defaults.py

示例12: test_lastrow_accessor_four

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def test_lastrow_accessor_four(self):
        metadata = MetaData()
        self._test_lastrow_accessor(
            Table(
                "t4",
                metadata,
                Column(
                    "id",
                    Integer,
                    Sequence("t4_id_seq", optional=True),
                    primary_key=True,
                ),
                Column("foo", String(30), primary_key=True),
                Column("bar", String(30), server_default="hi"),
            ),
            {"foo": "hi", "id": 1},
            {"id": 1, "foo": "hi", "bar": "hi"},
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_insert_exec.py

示例13: test_freestanding_sequence_via_autoinc

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def test_freestanding_sequence_via_autoinc(self, connection):
        t = Table(
            "some_table",
            self.metadata,
            Column(
                "id",
                Integer,
                autoincrement=True,
                primary_key=True,
                default=Sequence(
                    "my_sequence", metadata=self.metadata
                ).next_value(),
            ),
        )
        self.metadata.create_all(connection)

        result = connection.execute(t.insert())
        eq_(result.inserted_primary_key, (1,)) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_sequences.py

示例14: test_schema_translate_map_sequence

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def test_schema_translate_map_sequence(self):
        s1 = schema.Sequence("s1")
        s2 = schema.Sequence("s2", schema="foo")
        s3 = schema.Sequence("s3", schema="bar")

        schema_translate_map = {None: "z", "bar": None, "foo": "bat"}

        self.assert_compile(
            schema.CreateSequence(s1),
            "CREATE SEQUENCE [SCHEMA__none].s1 START WITH 1",
            schema_translate_map=schema_translate_map,
        )

        self.assert_compile(
            schema.CreateSequence(s2),
            "CREATE SEQUENCE [SCHEMA_foo].s2 START WITH 1",
            schema_translate_map=schema_translate_map,
        )

        self.assert_compile(
            schema.CreateSequence(s3),
            "CREATE SEQUENCE [SCHEMA_bar].s3 START WITH 1",
            schema_translate_map=schema_translate_map,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_compiler.py

示例15: test_pickle_metadata_sequence_restated

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Sequence [as 别名]
def test_pickle_metadata_sequence_restated(self):
        m1 = MetaData()
        Table(
            "a",
            m1,
            Column("id", Integer, primary_key=True),
            Column("x", Integer, Sequence("x_seq")),
        )

        m2 = pickle.loads(pickle.dumps(m1))

        s2 = Sequence("x_seq")
        t2 = Table(
            "a",
            m2,
            Column("id", Integer, primary_key=True),
            Column("x", Integer, s2),
            extend_existing=True,
        )

        assert m2._sequences["x_seq"] is t2.c.x.default
        assert m2._sequences["x_seq"] is s2 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_metadata.py


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