本文整理汇总了Python中sqlalchemy.NUMERIC属性的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.NUMERIC属性的具体用法?Python sqlalchemy.NUMERIC怎么用?Python sqlalchemy.NUMERIC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.NUMERIC属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: downgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def downgrade():
connection = op.get_bind()
if connection.engine.name != 'sqlite':
return
with op.batch_alter_table('user') as batch_op:
batch_op.add_column(sa.Column('_password',
type_=sa.NUMERIC(precision=128),
server_default='',
nullable=False
))
connection.execute(
UserHelper.update().values(_password=UserHelper.c.password)
)
with op.batch_alter_table('user') as batch_op:
batch_op.drop_column('password')
batch_op.alter_column('_password', server_default=None, new_column_name='password')
示例2: downgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def downgrade():
op.drop_table('letter_rates')
op.create_table('letter_rates',
sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('valid_from', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='letter_rates_pkey'),
postgresql_ignore_search_path=False
)
op.create_table('letter_rate_details',
sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('letter_rate_id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('page_total', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('rate', sa.NUMERIC(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['letter_rate_id'], ['letter_rates.id'],
name='letter_rate_details_letter_rate_id_fkey'),
sa.PrimaryKeyConstraint('id', name='letter_rate_details_pkey')
)
示例3: downgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("stores", "default_currency")
op.drop_column("invoices", "currency")
op.alter_column(
"invoices",
column_name="price",
new_column_name="amount",
existing_type=sa.NUMERIC(precision=16, scale=8),
existing_nullable=False,
existing_server_default=None,
)
op.alter_column(
"products",
column_name="price",
new_column_name="amount",
existing_type=sa.NUMERIC(precision=16, scale=8),
existing_nullable=False,
existing_server_default=None,
)
# ### end Alembic commands ###
示例4: _log
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def _log(t, expr):
arg, base = expr.op().args
sa_arg = t.translate(arg)
if base is not None:
sa_base = t.translate(base)
return sa.cast(
sa.func.log(
sa.cast(sa_base, sa.NUMERIC), sa.cast(sa_arg, sa.NUMERIC)
),
t.get_sqla_type(expr.type()),
)
return sa.func.ln(sa_arg)
示例5: _round
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def _round(t, expr):
arg, digits = expr.op().args
sa_arg = t.translate(arg)
if digits is None:
return sa.func.round(sa_arg)
# postgres doesn't allow rounding of double precision values to a specific
# number of digits (though simple truncation on doubles is allowed) so
# we cast to numeric and then cast back if necessary
result = sa.func.round(sa.cast(sa_arg, sa.NUMERIC), t.translate(digits))
if digits is not None and isinstance(arg.type(), dt.Decimal):
return result
result = sa.cast(result, sa.dialects.postgresql.DOUBLE_PRECISION())
return result
示例6: _mod
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def _mod(t, expr):
left, right = map(t.translate, expr.op().args)
# postgres doesn't allow modulus of double precision values, so upcast and
# then downcast later if necessary
if not isinstance(expr.type(), dt.Integer):
left = sa.cast(left, sa.NUMERIC)
right = sa.cast(right, sa.NUMERIC)
result = left % right
if expr.type().equals(dt.double):
return sa.cast(result, sa.dialects.postgresql.DOUBLE_PRECISION())
else:
return result
示例7: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def upgrade():
op.alter_column('ft_billing', 'billable_units',
existing_type=sa.NUMERIC(),
type_=sa.Integer(),
existing_nullable=True)
op.alter_column('ft_billing', 'rate_multiplier',
existing_type=sa.NUMERIC(),
type_=sa.Integer())
示例8: downgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def downgrade():
op.alter_column('ft_billing', 'rate_multiplier',
existing_type=sa.Integer(),
type_=sa.NUMERIC())
op.alter_column('ft_billing', 'billable_units',
existing_type=sa.Integer(),
type_=sa.NUMERIC(),
existing_nullable=True)
示例9: downgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('sales_order_line', sa.Column('original_amount', sa.NUMERIC(precision=8, scale=2), autoincrement=False, nullable=True))
op.add_column('sales_order_line', sa.Column('adjust_amount', sa.NUMERIC(precision=8, scale=2), autoincrement=False, nullable=True))
op.add_column('sales_order_line', sa.Column('actual_amount', sa.NUMERIC(precision=8, scale=2), autoincrement=False, nullable=True))
op.drop_table('preference')
### end Alembic commands ###
示例10: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.alter_column('enum_values', 'code',
existing_type=sa.VARCHAR(length=32),
nullable=False)
op.alter_column('product', 'purchase_price',
existing_type=sa.NUMERIC(precision=8, scale=2),
nullable=False)
op.alter_column('product', 'retail_price',
existing_type=sa.NUMERIC(precision=8, scale=2),
nullable=False)
### end Alembic commands ###
示例11: downgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.alter_column('product', 'retail_price',
existing_type=sa.NUMERIC(precision=8, scale=2),
nullable=True)
op.alter_column('product', 'purchase_price',
existing_type=sa.NUMERIC(precision=8, scale=2),
nullable=True)
op.alter_column('enum_values', 'code',
existing_type=sa.VARCHAR(length=32),
nullable=True)
### end Alembic commands ###
示例12: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"invoices", sa.Column("currency", sa.Text(), nullable=True, server_default="USD")
)
op.add_column(
"stores",
sa.Column("default_currency", sa.Text(), nullable=True, server_default="USD"),
)
op.alter_column("invoices", "currency", server_default=None)
op.alter_column("stores", "default_currency", server_default=None)
op.alter_column(
"invoices",
column_name="amount",
new_column_name="price",
existing_type=sa.NUMERIC(precision=16, scale=8),
existing_nullable=False,
existing_server_default=None,
)
op.alter_column(
"products",
column_name="amount",
new_column_name="price",
existing_type=sa.NUMERIC(precision=16, scale=8),
existing_nullable=False,
existing_server_default=None,
)
# ### end Alembic commands ###
示例13: test_typedecorator_impl
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def test_typedecorator_impl(self):
for impl_, exp, kw in [
(Float, "FLOAT", {}),
(Float, "FLOAT(2)", {"precision": 2}),
(Float(2), "FLOAT(2)", {"precision": 4}),
(Numeric(19, 2), "NUMERIC(19, 2)", {}),
]:
for dialect_ in (
dialects.postgresql,
dialects.mssql,
dialects.mysql,
):
dialect_ = dialect_.dialect()
raw_impl = types.to_instance(impl_, **kw)
class MyType(types.TypeDecorator):
impl = impl_
dec_type = MyType(**kw)
eq_(dec_type.impl.__class__, raw_impl.__class__)
raw_dialect_impl = raw_impl.dialect_impl(dialect_)
dec_dialect_impl = dec_type.dialect_impl(dialect_)
eq_(dec_dialect_impl.__class__, MyType)
eq_(
raw_dialect_impl.__class__, dec_dialect_impl.impl.__class__
)
self.assert_compile(MyType(**kw), exp, dialect=dialect_)
示例14: test_numeric_plain
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def test_numeric_plain(self):
self.assert_compile(types.NUMERIC(), "NUMERIC")
示例15: test_numeric_precision
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import NUMERIC [as 别名]
def test_numeric_precision(self):
self.assert_compile(types.NUMERIC(2), "NUMERIC(2)")