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


Python types.Numeric方法代码示例

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


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

示例1: get_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def get_type(data_type):
    type_map = {
        "bytes": types.LargeBinary,
        "boolean": types.Boolean,
        "date": types.Date,
        "datetime": types.DateTime,
        "double": types.Numeric,
        "text": types.String,
        "keyword": types.String,
        "integer": types.Integer,
        "half_float": types.Float,
        "geo_point": types.String,
        # TODO get a solution for nested type
        "nested": types.String,
        # TODO get a solution for object
        "object": types.BLOB,
        "long": types.BigInteger,
        "float": types.Float,
        "ip": types.String,
    }
    type_ = type_map.get(data_type)
    if not type_:
        logger.warning(f"Unknown type found {data_type} reverting to string")
        type_ = types.String
    return type_ 
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:27,代码来源:basesqlalchemy.py

示例2: test_float_coercion

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def test_float_coercion(self, connection):
        data_table = self.tables.data_table

        for type_, result in [
            (Numeric, decimal.Decimal("140.381230939")),
            (Float, 140.381230939),
            (Float(asdecimal=True), decimal.Decimal("140.381230939")),
            (Numeric(asdecimal=False), 140.381230939),
        ]:
            ret = connection.execute(
                select([func.stddev_pop(data_table.c.data, type_=type_)])
            ).scalar()

            eq_(round_decimal(ret, 9), result)

            ret = connection.execute(
                select([cast(func.stddev_pop(data_table.c.data), type_)])
            ).scalar()
            eq_(round_decimal(ret, 9), result) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_types.py

示例3: test_arrays_pg

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def test_arrays_pg(self, connection):
        metadata = self.metadata
        t1 = Table(
            "t",
            metadata,
            Column("x", postgresql.ARRAY(Float)),
            Column("y", postgresql.ARRAY(REAL)),
            Column("z", postgresql.ARRAY(postgresql.DOUBLE_PRECISION)),
            Column("q", postgresql.ARRAY(Numeric)),
        )
        metadata.create_all()
        connection.execute(
            t1.insert(), x=[5], y=[5], z=[6], q=[decimal.Decimal("6.4")]
        )
        row = connection.execute(t1.select()).first()
        eq_(row, ([5], [5], [6], [decimal.Decimal("6.4")])) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py

示例4: test_arrays_base

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def test_arrays_base(self, connection):
        metadata = self.metadata
        t1 = Table(
            "t",
            metadata,
            Column("x", sqltypes.ARRAY(Float)),
            Column("y", sqltypes.ARRAY(REAL)),
            Column("z", sqltypes.ARRAY(postgresql.DOUBLE_PRECISION)),
            Column("q", sqltypes.ARRAY(Numeric)),
        )
        metadata.create_all()
        connection.execute(
            t1.insert(), x=[5], y=[5], z=[6], q=[decimal.Decimal("6.4")]
        )
        row = connection.execute(t1.select()).first()
        eq_(row, ([5], [5], [6], [decimal.Decimal("6.4")])) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py

示例5: test_numeric_default

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def test_numeric_default(self, connection):
        metadata = self.metadata
        # pg8000 appears to fail when the value is 0,
        # returns an int instead of decimal.
        t = Table(
            "t",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("nd", Numeric(asdecimal=True), default=1),
            Column("nf", Numeric(asdecimal=False), default=1),
            Column("fd", Float(asdecimal=True), default=1),
            Column("ff", Float(asdecimal=False), default=1),
        )
        metadata.create_all()
        connection.execute(t.insert())

        row = connection.execute(t.select()).first()
        assert isinstance(row[1], decimal.Decimal)
        assert isinstance(row[2], float)
        assert isinstance(row[3], decimal.Decimal)
        assert isinstance(row[4], float)
        eq_(row, (1, decimal.Decimal("1"), 1, decimal.Decimal("1"), 1)) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_types.py

示例6: test_python_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def test_python_type(self):
        eq_(types.Integer().python_type, int)
        eq_(types.Numeric().python_type, decimal.Decimal)
        eq_(types.Numeric(asdecimal=False).python_type, float)
        eq_(types.LargeBinary().python_type, util.binary_type)
        eq_(types.Float().python_type, float)
        eq_(types.Interval().python_type, datetime.timedelta)
        eq_(types.Date().python_type, datetime.date)
        eq_(types.DateTime().python_type, datetime.datetime)
        eq_(types.String().python_type, str)
        eq_(types.Unicode().python_type, util.text_type)
        eq_(types.Enum("one", "two", "three").python_type, str)

        assert_raises(
            NotImplementedError, lambda: types.TypeEngine().python_type
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py

示例7: _convert_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def _convert_type(self, dj_field, sa_type):
        kwargs = {}
        if sa_type is SA_ARRAY:
            internal_type = dj_field.base_field.get_internal_type()
            kwargs['item_type'] = self._types.get(internal_type)
            if kwargs['item_type'] is None:
                raise ConversionError(
                    'Unable convert array: '
                    'item type "%s" not found' % internal_type
                )
        elif sa_type is Geometry:
            kwargs['geometry_type'] = 'POINT'
            kwargs['srid'] = dj_field.srid
        elif sa_type is sa_types.Numeric:
            kwargs['scale'] = dj_field.decimal_places,
            kwargs['precision'] = dj_field.max_digits
        elif sa_type in (sa_types.String, sa_types.Text):
            kwargs['length'] = dj_field.max_length
        elif sa_type is SA_UUID:
            kwargs['as_uuid'] = True
        return sa_type(**kwargs) 
开发者ID:dvhb,项目名称:dvhb-hybrid,代码行数:23,代码来源:convert.py

示例8: _type_affinity

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def _type_affinity(self):
        if bool(self.scale and self.scale > 0):
            return sqltypes.Numeric
        else:
            return sqltypes.Integer 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:base.py

示例9: result_processor

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def result_processor(self, dialect, type_):
        if not self.asdecimal:
            return processors.to_float
        else:
            return sqltypes.Numeric.result_processor(self, dialect, type_) 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:pysybase.py

示例10: test_numeric_reflection

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def test_numeric_reflection(self):
        for typ in self._type_round_trip(
            sql_types.Numeric(18, 5),
        ):
            assert isinstance(typ, sql_types.Numeric)
            eq_(typ.precision, 18)
            eq_(typ.scale, 5) 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:test_reflection.py

示例11: _resolve_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def _resolve_type(self, t, **kw):
        """
        Resolve types for String, Numeric, Date/Time, etc. columns
        """
        t = self.normalize_name(t)
        if t in ischema_names:
            #print(t,ischema_names[t])
            t = ischema_names[t]
            
            if issubclass(t, sqltypes.String):
                return t(length=kw['length']/2 if kw['chartype']=='UNICODE' else kw['length'],\
                            charset=kw['chartype'])

            elif issubclass(t, sqltypes.Numeric):
                return t(precision=kw['prec'], scale=kw['scale'])

            elif issubclass(t, sqltypes.Time) or issubclass(t, sqltypes.DateTime):
                #Timezone
                tz=kw['fmt'][-1]=='Z'

                #Precision                
                prec = kw['fmt']    
                #For some timestamps and dates, there is no precision, or indicatd in scale
                prec = prec[prec.index('(') + 1: prec.index(')')] if '(' in prec else 0
                prec = kw['scale'] if prec=='F' else int(prec)

                #prec = int(prec[prec.index('(') + 1: prec.index(')')]) if '(' in prec else 0
                return t(precision=prec,timezone=tz)

            elif issubclass(t, sqltypes.Interval):
                return t(day_precision=kw['prec'],second_precision=kw['scale'])

            else:
                return t() # For types like Integer, ByteInt

        return ischema_names[None] 
开发者ID:Teradata,项目名称:sqlalchemy-teradata,代码行数:38,代码来源:dialect.py

示例12: test_should_numeric_convert_float

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def test_should_numeric_convert_float():
    assert get_field(types.Numeric()).type == graphene.Float 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:4,代码来源:test_converter.py

示例13: get_columns

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def get_columns(self, connection, table_name, schema=None, **kw):
        SQL_COLS = """
            SELECT CAST(a.attname AS VARCHAR(128)) as name,
                   a.atttypid as typeid,
                   not a.attnotnull as nullable,
                   a.attcolleng as length,
                   a.format_type
            FROM _v_relation_column a
            WHERE a.name = :tablename
            ORDER BY a.attnum
        """
        s = text(SQL_COLS,
                 bindparams=[bindparam('tablename', type_=sqltypes.String)],
                 typemap={'name': NAME,
                          'typeid': sqltypes.Integer,
                          'nullable': sqltypes.Boolean,
                          'length': sqltypes.Integer,
                          'format_type': sqltypes.String,
                          })
        c = connection.execute(s, tablename=table_name)
        rows = c.fetchall()
        # format columns
        columns = []
        for name, typeid, nullable, length, format_type in rows:
            coltype_class, has_length = oid_datatype_map[typeid]
            if coltype_class is sqltypes.Numeric:
                precision, scale = re.match(
                    r'numeric\((\d+),(\d+)\)', format_type).groups()
                coltype = coltype_class(int(precision), int(scale))
            elif has_length:
                coltype = coltype_class(length)
            else:
                coltype = coltype_class()
            columns.append({
                'name': name,
                'type': coltype,
                'nullable': nullable,
            })
        return columns 
开发者ID:deontologician,项目名称:netezza_sqlalchemy,代码行数:41,代码来源:netezza_dialect.py

示例14: __init__

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def __init__(self, *args, **kwargs):
        if self.impl == types.Numeric:
            kwargs['scale'] = 28
            kwargs['precision'] = 1000
        types.TypeDecorator.__init__(self, *args, **kwargs) 
开发者ID:simplecrypto,项目名称:simplecoin_multi,代码行数:7,代码来源:model_lib.py

示例15: test_tuple_flag

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Numeric [as 别名]
def test_tuple_flag(self, connection):
        metadata = self.metadata

        t1 = Table(
            "t1",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("data", self.ARRAY(String(5), as_tuple=True)),
            Column(
                "data2", self.ARRAY(Numeric(asdecimal=False), as_tuple=True)
            ),
        )
        metadata.create_all()
        connection.execute(
            t1.insert(), id=1, data=["1", "2", "3"], data2=[5.4, 5.6]
        )
        connection.execute(
            t1.insert(), id=2, data=["4", "5", "6"], data2=[1.0]
        )
        connection.execute(
            t1.insert(),
            id=3,
            data=[["4", "5"], ["6", "7"]],
            data2=[[5.4, 5.6], [1.0, 1.1]],
        )

        r = connection.execute(t1.select().order_by(t1.c.id)).fetchall()
        eq_(
            r,
            [
                (1, ("1", "2", "3"), (5.4, 5.6)),
                (2, ("4", "5", "6"), (1.0,)),
                (3, (("4", "5"), ("6", "7")), ((5.4, 5.6), (1.0, 1.1))),
            ],
        )
        # hashable
        eq_(
            set(row[1] for row in r),
            set([("1", "2", "3"), ("4", "5", "6"), (("4", "5"), ("6", "7"))]),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:42,代码来源:test_types.py


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