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


Python sqlalchemy.Numeric方法代码示例

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


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

示例1: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('state',
    sa.Column('address', sa.String(length=42), nullable=False),
    sa.Column('balance', sa.Numeric(), nullable=False),
    sa.Column('nonce', sa.Integer(), nullable=True),
    sa.Column('code', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('address')
    )
    op.create_index(op.f('ix_state_address'), 'state', ['address'], unique=False)
    op.create_table('storage',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('address', sa.String(length=42), nullable=True),
    sa.Column('position', sa.String(length=66), nullable=False),
    sa.Column('storage', sa.String(length=66), nullable=False),
    sa.ForeignKeyConstraint(['address'], ['state.address'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_storage_position'), 'storage', ['position'], unique=False)
    op.add_column('meta_info', sa.Column('current_state_block', sa.Numeric(), nullable=True))
    # ### end Alembic commands ### 
开发者ID:analyseether,项目名称:ether_sql,代码行数:23,代码来源:efc3b5068a72_add_current_state_tables.py

示例2: get_model_search_filter

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def get_model_search_filter(Model):
    mapper = inspect(Model)

    class ModelSearchFilter(CharFilter):
        def filter(self, qs, value):
            value = self.clean_value(value)
            if value in EMPTY_VALUES:
                return qs

            def map_column(column):
                if isinstance(column.type, (sqlalchemy.Integer, sqlalchemy.Numeric)):
                    return cast(column, sqlalchemy.String).__eq__(value)
                elif isinstance(column.type, sqlalchemy.String):
                    return column.ilike('%{}%'.format(value))
                elif isinstance(column.type, sqlalchemy.JSON):
                    return cast(column, sqlalchemy.String).ilike('%{}%'.format(value))

            operators = list(filter(lambda x: x is not None, map(map_column, mapper.columns)))

            return qs.filter(or_(*operators))

    return ModelSearchFilter 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:24,代码来源:model_search.py

示例3: test_remove_unique_index_not_reported

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def test_remove_unique_index_not_reported(self):
        m1 = MetaData()
        Table(
            "order",
            m1,
            Column("order_id", Integer, primary_key=True),
            Column("amount", Numeric(10, 2), nullable=True),
            Column("user_id", Integer),
            Index("oid_ix", "order_id", "user_id", unique=True),
        )
        m2 = MetaData()
        Table(
            "order",
            m2,
            Column("order_id", Integer, primary_key=True),
            Column("amount", Numeric(10, 2), nullable=True),
            Column("user_id", Integer),
        )

        diffs = self._fixture(m1, m2)
        eq_(diffs, []) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:23,代码来源:test_autogen_indexes.py

示例4: init_database

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def init_database():

    Base = declarative_base()

    class Model(Base):
        __tablename__ = 'models'
        TS_name = Column(String(250), nullable=False,primary_key=True)
        TS_winner_name = Column(String(250), nullable=False)
        TS_model = Column(LargeBinary())
        TS_model_params = Column(String(250))
        TS_metric = Column(Numeric)
        TS_update = Column('TS_update', DATETIME, index=False, nullable=False,primary_key=True,default=datetime.datetime.utcnow)

    class TS(Base):
        __tablename__ = 'timeseries'
        TS_name = Column(String(250), nullable=False,primary_key=True)
        TS_data = Column(Text())
        TS_update = Column('TS_update', DATETIME, index=False, nullable=False,primary_key=True,default=datetime.datetime.utcnow)


    DB_NAME = 'sqlite:///Timecop_modelsv1.db'
    engine = create_engine(DB_NAME)
    #self.__db.echo = True
    Base.metadata.create_all(engine) 
开发者ID:BBVA,项目名称:timecop,代码行数:26,代码来源:BBDD.py

示例5: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def upgrade():
    notification_types = postgresql.ENUM('email', 'sms', 'letter', name='notification_type', create_type=False)
    op.create_table('rates',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('valid_from', sa.DateTime(), nullable=False),
    sa.Column('rate', sa.Numeric(), nullable=False),
    sa.Column('notification_type', notification_types, nullable=False),
    sa.PrimaryKeyConstraint('id')
    )

    op.create_index(op.f('ix_rates_notification_type'), 'rates', ['notification_type'], unique=False)

    op.get_bind()
    op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) "
               "VALUES('{}', '2016-05-18 00:00:00', 1.65, 'sms')".format(uuid.uuid4()))
    op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) "
               "VALUES('{}', '2017-04-01 00:00:00', 1.58, 'sms')".format(uuid.uuid4())) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:19,代码来源:0075_create_rates_table.py

示例6: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def upgrade():
    op.create_table('provider_rates',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('valid_from', sa.DateTime(), nullable=False),
    sa.Column('provider', sa.Enum('mmg', 'twilio', 'firetext', 'ses', name='providers'), nullable=False),
    sa.Column('rate', sa.Numeric(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('provider_statistics',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('day', sa.Date(), nullable=False),
    sa.Column('provider', sa.Enum('mmg', 'twilio', 'firetext', 'ses', name='providers'), nullable=False),
    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('unit_count', sa.BigInteger(), nullable=False),
    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_provider_statistics_service_id'), 'provider_statistics', ['service_id'], unique=False) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:20,代码来源:0005_add_provider_stats.py

示例7: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def upgrade():
    relative_modifier = table('relative_modifier',
            column('id', sa.Integer),
            column('value', sa.Float),
            column('numeric_value', sa.Numeric(precision=8, scale=5)))
    op.add_column('relative_modifier',
            sa.Column('numeric_value', sa.Numeric(precision=8, scale=5)))
    conn = op.get_bind()
    sel = select([relative_modifier.c.id, relative_modifier.c.value])
    results = conn.execute(sel)
    q = Decimal(10) ** -5
    for id_, float_value in results:
        decimal_value = Decimal(float_value).quantize(q)
        up = update(relative_modifier).where(relative_modifier.c.id == id_)\
                .values({'numeric_value': decimal_value})
        conn.execute(up)
    op.drop_column('relative_modifier', 'value')
    op.alter_column('relative_modifier', 'numeric_value', nullable=True,
            new_column_name='value', existing_type=sa.Numeric(precision=8,
                    scale=5)) 
开发者ID:paxswill,项目名称:evesrp,代码行数:22,代码来源:5795c29b2c7a_.py

示例8: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('inventory_in_out_link',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('date', sa.DateTime(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('in_price', sa.Numeric(precision=8, scale=2, decimal_return_scale=2), nullable=False),
    sa.Column('in_date', sa.DateTime(), nullable=False),
    sa.Column('receiving_line_id', sa.Integer(), nullable=False),
    sa.Column('out_price', sa.Numeric(precision=8, scale=2, decimal_return_scale=2), nullable=False),
    sa.Column('out_date', sa.DateTime(), nullable=False),
    sa.Column('out_quantity', sa.Numeric(precision=8, scale=2, decimal_return_scale=2), nullable=False),
    sa.Column('shipping_line_id', sa.Integer(), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=True),
    sa.Column('remark', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['product.id'], ),
    sa.ForeignKeyConstraint(['receiving_line_id'], ['receiving_line.id'], ),
    sa.ForeignKeyConstraint(['shipping_line_id'], ['shipping_line.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column(u'inventory_transaction_line', sa.Column('saleable_quantity', sa.Numeric(precision=8, scale=2, decimal_return_scale=2), nullable=True))
    # ### end Alembic commands ### 
开发者ID:betterlife,项目名称:betterlifepsi,代码行数:25,代码来源:35_a173601e2e8c_.py

示例9: __init__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def __init__(self, *arg, **kw):
        """Create a TRY_CAST expression.

        :class:`.TryCast` is a subclass of SQLAlchemy's :class:`.Cast`
        construct, and works in the same way, except that the SQL expression
        rendered is "TRY_CAST" rather than "CAST"::

            from sqlalchemy import select
            from sqlalchemy import Numeric
            from sqlalchemy.dialects.mssql import try_cast

            stmt = select([
                try_cast(product_table.c.unit_price, Numeric(10, 4))
            ])

        The above would render::

            SELECT TRY_CAST (product_table.unit_price AS NUMERIC(10, 4))
            FROM product_table

        .. versionadded:: 1.3.7

        """
        super(TryCast, self).__init__(*arg, **kw) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:base.py

示例10: test_basic_override

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def test_basic_override(self):
        meta = self.metadata
        table = Table(
            "override_test",
            meta,
            Column("col1", sa.Integer, primary_key=True),
            Column("col2", sa.String(20)),
            Column("col3", sa.Numeric),
        )
        table.create()

        meta2 = MetaData(testing.db)
        table = Table(
            "override_test",
            meta2,
            Column("col2", sa.Unicode()),
            Column("col4", sa.String(30)),
            autoload=True,
        )

        self.assert_(isinstance(table.c.col1.type, sa.Integer))
        self.assert_(isinstance(table.c.col2.type, sa.Unicode))
        self.assert_(isinstance(table.c.col4.type, sa.String)) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_reflection.py

示例11: test_override_upgrade_pk_flag

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def test_override_upgrade_pk_flag(self):
        meta = self.metadata
        table = Table(
            "override_test",
            meta,
            Column("col1", sa.Integer),
            Column("col2", sa.String(20)),
            Column("col3", sa.Numeric),
        )
        table.create()

        meta2 = MetaData(testing.db)
        table = Table(
            "override_test",
            meta2,
            Column("col1", sa.Integer, primary_key=True),
            autoload=True,
        )

        eq_(list(table.primary_key), [table.c.col1])
        eq_(table.c.col1.primary_key, True) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_reflection.py

示例12: test_float_coercion

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy 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

示例13: test_arrays_base

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy 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

示例14: test_numeric_codes

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Numeric [as 别名]
def test_numeric_codes(self):
        from sqlalchemy.dialects.postgresql import (
            pg8000,
            pygresql,
            psycopg2,
            psycopg2cffi,
            base,
        )

        dialects = (
            pg8000.dialect(),
            pygresql.dialect(),
            psycopg2.dialect(),
            psycopg2cffi.dialect(),
        )
        for dialect in dialects:
            typ = Numeric().dialect_impl(dialect)
            for code in (
                base._INT_TYPES + base._FLOAT_TYPES + base._DECIMAL_TYPES
            ):
                proc = typ.result_processor(dialect, code)
                val = 23.7
                if proc is not None:
                    val = proc(val)
                assert val in (23.7, decimal.Decimal("23.7")) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:test_types.py

示例15: test_numeric_default

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy 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


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