微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python sqlalchemy 模块-DECIMAL 实例源码

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(),
        sa.Column("updated_at",
        sa.PrimaryKeyConstraint("id")
    )

    op.create_table(
        "order_details",
        sa.Column("order_id",
        sa.Column("product_id", sa.String(),
        sa.Column("price", sa.DECIMAL(18, 2),
        sa.Column("quantity",
        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,
        sa.Column('$Volume',
        sa.Column('LowPrice',
        sa.Column('HighPrice',
        sa.Column('AvgPrice', sa.DECIMAL,
        sa.Column('LastPrice', 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,
        ts_col,
        sa.Column('Bid',  # No example of nullable
        sa.Column('Ask',
        sa.Column('Last',
        sa.Column('Low',
        sa.Column('High',
        sa.Column('Average',
        sa.Index('idx', ts_col,
    )
项目: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()'),
        sa.Column('name', sa.Unicode(),
        sa.Column('url',
        sa.PrimaryKeyConstraint('id', name=op.f('pk_Feed')),
        sa.UniqueConstraint('url', name=op.f('uq_Feed_url'))
    )
    op.create_table(
        'user',
        sa.Column('email',
        sa.Column('password', name=op.f('pk_user')),
        sa.UniqueConstraint('email', name=op.f('uq_user_email'))
    )
    op.create_table(
        'article',
        sa.Column('Feed_id',
        sa.Column('title',
        sa.Column('html_text',
        sa.Column('clean_text',
        sa.Column('publication_date', postgresql.TIMESTAMP(timezone='UTC'),
        sa.ForeignKeyConstraint(['Feed_id'], ['Feed.id'], name=op.f('fk_article_Feed_id_Feed')), name=op.f('pk_article'))
    )
    op.create_table(
        'subscription',
        sa.Column('user_id', name=op.f('fk_subscription_Feed_id_Feed')),
        sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_subscription_user_id_user')), name=op.f('pk_subscription'))
    )
    op.create_table(
        'rating',
        sa.Column('article_id',
        sa.Column('user_rating', sa.DECIMAL(precision=4, scale=2),
        sa.Column('machine_rating',
        sa.Column('read', sa.Boolean(), server_default=sa.text('FALSE'),
        sa.ForeignKeyConstraint(['article_id'], ['article.id'], name=op.f('fk_rating_article_id_article')), name=op.f('fk_rating_Feed_id_Feed')), name=op.f('fk_rating_user_id_user')), name=op.f('pk_rating'))
    )

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐