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


Python sqlalchemy.type_coerce方法代码示例

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


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

示例1: _set_table

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def _set_table(self, schema, column, table):
        SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table 
开发者ID:yfauser,项目名称:planespotter,代码行数:19,代码来源:sqltypes.py

示例2: _set_table

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def _set_table(self, schema, column, table):
        if self.native_enum:
            SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:20,代码来源:sqltypes.py

示例3: cast

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def cast(self, type_):
        """Produce a type cast, i.e. ``CAST(<expression> AS <type>)``.

        This is a shortcut to the :func:`_expression.cast` function.

        .. seealso::

            :ref:`coretutorial_casts`

            :func:`_expression.cast`

            :func:`_expression.type_coerce`

        .. versionadded:: 1.0.7

        """
        return Cast(self, type_) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:elements.py

示例4: _set_table

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def _set_table(self, column, table):
        schema = util.preloaded.sql_schema
        SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping},
            ),
            _type_bound=True,
        )
        assert e.table is table 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:sqltypes.py

示例5: _test_bind

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def _test_bind(self, coerce_fn, conn):
        MyType = self.MyType

        t = self.tables.t
        conn.execute(t.insert().values(data=coerce_fn("d1", MyType)))

        stmt = select(
            [
                bindparam(None, "x", String(50), unique=True),
                coerce_fn(
                    bindparam(None, "x", String(50), unique=True), MyType
                ),
            ]
        )

        eq_(
            conn.execute(stmt).fetchall(),
            [("x", "BIND_INxBIND_OUT")]
            if coerce_fn is type_coerce
            else [("x", "xBIND_OUT")],
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_types.py

示例6: test_type_coerce_auto_label

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

        self.assert_compile(
            select(
                [
                    type_coerce(table1.c.name, Integer),
                    type_coerce(table1.c.name, String),
                    table1.c.name,
                ]
            ),
            # ideally type_coerce wouldn't label at all...
            "SELECT some_table.name AS name, "
            "some_table.name AS name, "
            "some_table.name FROM some_table",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_labels.py

示例7: test_label_plus_element

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def test_label_plus_element(self):
        t = Table("t", MetaData(), Column("a", Integer))
        l1 = t.c.a.label("bar")
        tc = type_coerce(t.c.a + "str", String)
        stmt = select([t.c.a, l1, tc])
        comp = stmt.compile()
        tc_anon_label = comp._create_result_map()["anon_1"][1][0]
        eq_(
            comp._create_result_map(),
            {
                "a": ("a", (t.c.a, "a", "a", "t_a"), t.c.a.type),
                "bar": ("bar", (l1, "bar"), l1.type),
                "anon_1": (
                    tc.anon_label,
                    (tc_anon_label, "anon_1", tc),
                    tc.type,
                ),
            },
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_compiler.py

示例8: setup_mappers

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def setup_mappers(cls):
        mapper(
            cls.classes.Person,
            cls.tables.person,
            properties=dict(
                pets=relationship(
                    cls.classes.Pet,
                    primaryjoin=(
                        orm.foreign(cls.tables.pets.c.person_id)
                        == sa.cast(
                            sa.type_coerce(cls.tables.person.c.id, Integer),
                            Integer,
                        )
                    ),
                )
            ),
        )

        mapper(cls.classes.Pet, cls.tables.pets) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_lazy_relations.py

示例9: test_unhashable_type

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def test_unhashable_type(self):
        from sqlalchemy.types import TypeDecorator, Integer
        from sqlalchemy.sql import type_coerce

        class MyType(TypeDecorator):
            impl = Integer
            hashable = False

            def process_result_value(self, value, dialect):
                return [value]

        User, users = self.classes.User, self.tables.users

        mapper(User, users)

        s = Session()
        q = s.query(User, type_coerce(users.c.id, MyType).label("foo")).filter(
            User.id == 7
        )
        row = q.first()
        eq_(row, (User(id=7), [7])) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_query.py

示例10: list_dids_by_meta

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def list_dids_by_meta(scope, select, session=None):
    """
    Add or update the given metadata to the given did

    :param scope: the scope of the did
    :param name: the name of the did
    :param meta: the metadata to be added or updated
    """
    # Currently for sqlite only add, get and delete is implemented.
    if session.bind.dialect.name == 'sqlite':
        raise NotImplementedError
    if session.bind.dialect.name == 'oracle':
        oracle_version = int(session.connection().connection.version.split('.')[0])
        if oracle_version < 12:
            raise NotImplementedError

    query = session.query(models.DidMeta)
    if scope is not None:
        query = query.filter(models.DidMeta.scope == scope)

    for k, v in iteritems(select):
        if session.bind.dialect.name == 'oracle':
            query = query.filter(text("json_exists(meta,'$.%s?(@==''%s'')')" % (k, v)))
        else:
            query = query.filter(cast(models.DidMeta.meta[k], String) == type_coerce(v, JSON))
    dids = list()
    for row in query.yield_per(10):
        dids.append({'scope': row.scope, 'name': row.name})
    return dids 
开发者ID:rucio,项目名称:rucio,代码行数:31,代码来源:did.py

示例11: __getitem__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def __getitem__(self, index):
            super_ = super(ARRAY_D.Comparator, self).__getitem__(index)
            if not isinstance(index, slice) and self.type.dimensions > 1:
                super_ = type_coerce(
                    super_,
                    ARRAY_D(
                        self.type.item_type,
                        dimensions=self.type.dimensions - 1,
                        zero_indexes=self.type.zero_indexes)
                )
            return super_ 
开发者ID:sdss,项目名称:marvin,代码行数:13,代码来源:ArrayUtils.py

示例12: test_limit_preserves_typing_information

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def test_limit_preserves_typing_information(self):
        class MyType(TypeDecorator):
            impl = Integer

        stmt = select([type_coerce(column("x"), MyType).label("foo")]).limit(1)
        dialect = oracle.dialect()
        compiled = stmt.compile(dialect=dialect)
        assert isinstance(compiled._create_result_map()["foo"][-1], MyType) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:10,代码来源:test_compiler.py

示例13: test_type_coerce_preserve_subq

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def test_type_coerce_preserve_subq(self):
        class MyType(TypeDecorator):
            impl = Integer

        stmt = select([type_coerce(column("x"), MyType).label("foo")])
        subq = stmt.subquery()
        stmt2 = subq.select()
        subq2 = stmt2.subquery()
        assert isinstance(stmt._raw_columns[0].type, MyType)
        assert isinstance(subq.c.foo.type, MyType)
        assert isinstance(stmt2.selected_columns.foo.type, MyType)
        assert isinstance(subq2.c.foo.type, MyType) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:14,代码来源:test_selectable.py

示例14: test_insert_round_trip_type_coerce

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def test_insert_round_trip_type_coerce(self, connection):
        self._test_insert_round_trip(type_coerce, connection) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:4,代码来源:test_types.py

示例15: test_coerce_from_nulltype_type_coerce

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import type_coerce [as 别名]
def test_coerce_from_nulltype_type_coerce(self, connection):
        self._test_coerce_from_nulltype(type_coerce, connection) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:4,代码来源:test_types.py


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