Python sqlalchemy 模块,DECIMAL 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用sqlalchemy.DECIMAL

项目:nameko-examples    作者:nameko    | 项目源码 | 文件源码
def upgrade():
    op.create_table(
        "orders",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id")
    )

    op.create_table(
        "order_details",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("order_id", sa.Integer(), nullable=False),
        sa.Column("product_id", sa.String(), nullable=False),
        sa.Column("price", sa.DECIMAL(18, 2), nullable=False),
        sa.Column("quantity", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.ForeignKeyConstraint(
            ["order_id"], ["orders.id"],
            name="fk_order_details_orders"
        ),
    )
项目:pyiem    作者:rheineke    | 项目源码 | 文件源码
def daily_market_table(metadata, market):
    table_name = history_key(market)
    # Index columns
    date_col = sa.Column('Date', sa.DATETIME, nullable=False)
    asset_col = sa.Column(
        config.ASSET_ID,
        sa.INTEGER,
        sa.ForeignKey(config.ASSETS + '.' + config.ID),
        nullable=False
    )

    return sa.Table(
        table_name,
        metadata,
        date_col,
        asset_col,
        sa.Column('Units', sa.INTEGER, nullable=False),
        sa.Column('$Volume', sa.INTEGER, nullable=False),
        sa.Column('LowPrice', sa.INTEGER, nullable=False),
        sa.Column('HighPrice', sa.INTEGER, nullable=False),
        sa.Column('AvgPrice', sa.DECIMAL, nullable=False),
        sa.Column('LastPrice', sa.INTEGER, nullable=True),  # Null == NaN?
        sa.Index('idx', asset_col, date_col, unique=True),
    )
项目:pyiem    作者:rheineke    | 项目源码 | 文件源码
def quotes_table(metadata, market):
    table_name = quote_key(market)

    # Index columns
    ts_col = sa.Column('Timestamp', sa.TIMESTAMP, nullable=False)
    asset_col = sa.Column(
        config.ASSET_ID,
        sa.INTEGER,
        sa.ForeignKey(config.ASSETS + '.' + config.ID),
        nullable=False
    )

    return sa.Table(
        table_name,
        metadata,
        ts_col,
        asset_col,
        sa.Column('Bid', sa.INTEGER, nullable=False),  # No example of nullable
        sa.Column('Ask', sa.INTEGER, nullable=False),
        sa.Column('Last', sa.INTEGER, nullable=False),
        sa.Column('Low', sa.INTEGER, nullable=True),
        sa.Column('High', sa.INTEGER, nullable=True),
        sa.Column('Average', sa.DECIMAL, nullable=True),
        sa.Index('idx', asset_col, ts_col, unique=True),
    )
项目:backend    作者:deinfoxication    | 项目源码 | 文件源码
def upgrade():
    """Upgrade instructions."""
    op.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"')
    op.create_table(
        'feed',
        sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
        sa.Column('name', sa.Unicode(), nullable=True),
        sa.Column('url', sa.Unicode(), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_feed')),
        sa.UniqueConstraint('url', name=op.f('uq_feed_url'))
    )
    op.create_table(
        'user',
        sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
        sa.Column('email', sa.Unicode(), nullable=False),
        sa.Column('password', sa.Unicode(), nullable=False),
        sa.Column('name', sa.Unicode(), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_user')),
        sa.UniqueConstraint('email', name=op.f('uq_user_email'))
    )
    op.create_table(
        'article',
        sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
        sa.Column('feed_id', postgresql.UUID(), nullable=False),
        sa.Column('title', sa.Unicode(), nullable=False),
        sa.Column('url', sa.Unicode(), nullable=False),
        sa.Column('html_text', sa.Unicode(), nullable=False),
        sa.Column('clean_text', sa.Unicode(), nullable=False),
        sa.Column('publication_date', postgresql.TIMESTAMP(timezone='UTC'), nullable=False),
        sa.ForeignKeyConstraint(['feed_id'], ['feed.id'], name=op.f('fk_article_feed_id_feed')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_article'))
    )
    op.create_table(
        'subscription',
        sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
        sa.Column('user_id', postgresql.UUID(), nullable=False),
        sa.Column('feed_id', postgresql.UUID(), nullable=False),
        sa.ForeignKeyConstraint(['feed_id'], ['feed.id'], name=op.f('fk_subscription_feed_id_feed')),
        sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_subscription_user_id_user')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_subscription'))
    )
    op.create_table(
        'rating',
        sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
        sa.Column('user_id', postgresql.UUID(), nullable=False),
        sa.Column('article_id', postgresql.UUID(), nullable=False),
        sa.Column('feed_id', postgresql.UUID(), nullable=False),
        sa.Column('user_rating', sa.DECIMAL(precision=4, scale=2), nullable=True),
        sa.Column('machine_rating', sa.DECIMAL(precision=4, scale=2), nullable=True),
        sa.Column('read', sa.Boolean(), server_default=sa.text('FALSE'), nullable=False),
        sa.ForeignKeyConstraint(['article_id'], ['article.id'], name=op.f('fk_rating_article_id_article')),
        sa.ForeignKeyConstraint(['feed_id'], ['feed.id'], name=op.f('fk_rating_feed_id_feed')),
        sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_rating_user_id_user')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_rating'))
    )