當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。