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


Python sqlalchemy.DATETIME属性代码示例

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


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

示例1: init_database

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

示例2: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def upgrade():
  """ Change tables to use DATETIME column types instead of TIMESTAMP """
  # Change tables to use DATETIME column types instead of TIMESTAMP
  op.alter_column("instance_status_history", "timestamp",
                  type_=sa.DATETIME,
                  server_default=None,
                  existing_nullable=False)

  op.alter_column("metric", "last_timestamp",
                  type_=sa.DATETIME,
                  existing_nullable=True,
                  existing_server_default=sa.text("NULL"))

  op.alter_column("metric_data", "timestamp",
                  type_=sa.DATETIME,
                  existing_nullable=False)
  ### end Alembic commands ### 
开发者ID:htm-community,项目名称:skeleton-htmengine-app,代码行数:19,代码来源:001_1d2eddc43366_timestatmp_to_datetime.py

示例3: test_round_trip_sqlite_datetime

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def test_round_trip_sqlite_datetime(self):
        variant = DateTime().with_variant(
            dialects.sqlite.DATETIME(truncate_microseconds=True), "sqlite"
        )

        t = Table("t", self.metadata, Column("x", variant))
        with testing.db.connect() as conn:
            t.create(conn)

            conn.execute(
                t.insert(), x=datetime.datetime(2015, 4, 18, 10, 15, 17, 4839)
            )

            eq_(
                conn.scalar(
                    select([t.c.x]).where(
                        t.c.x
                        == datetime.datetime(2015, 4, 18, 10, 15, 17, 1059)
                    )
                ),
                datetime.datetime(2015, 4, 18, 10, 15, 17),
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_types.py

示例4: test_variant_righthand_coercion_returns_self

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def test_variant_righthand_coercion_returns_self(self):
        my_datetime_normal = DateTime()
        my_datetime_variant = DateTime().with_variant(
            dialects.sqlite.DATETIME(truncate_microseconds=False), "sqlite"
        )

        tab = table(
            "test",
            column("avalue", my_datetime_normal),
            column("bvalue", my_datetime_variant),
        )
        expr = tab.c.avalue == datetime.datetime(2015, 10, 14, 15, 17, 18)

        is_(expr.right.type._type_affinity, DateTime)
        is_(expr.right.type, my_datetime_normal)

        expr = tab.c.bvalue == datetime.datetime(2015, 10, 14, 15, 17, 18)

        is_(expr.right.type, my_datetime_variant) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_types.py

示例5: search_by_age

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def search_by_age(cls, *, limit=100, page=1, accounts=None, locations=None, age=720,
                      properties=None, include_disabled=False):
        """Search for resources based on the provided filters

        Args:
            limit (`int`): Number of results to return. Default: 100
            page (`int`): Pagination offset for results. Default: 1
            accounts (`list` of `int`): A list of account id's to limit the returned resources to
            locations (`list` of `str`): A list of locations as strings to limit the search for
            age (`int`): Age of instances older than `age` days to return
            properties (`dict`): A `dict` containing property name and value pairs. Values can be either a str or a list
            of strings, in which case a boolean OR search is performed on the values
            include_disabled (`bool`): Include resources from disabled accounts. Default: False

        Returns:
            `list` of `Resource`
        """
        qry = cls.search(
            limit=limit,
            page=page,
            accounts=accounts,
            locations=locations,
            properties=properties,
            include_disabled=include_disabled,
            return_query=True
        )

        age_alias = aliased(ResourceProperty)
        qry = (
            qry.join(age_alias, Resource.resource_id == age_alias.resource_id)
                .filter(
                age_alias.name == 'launch_date',
                cast(func.JSON_UNQUOTE(age_alias.value), DATETIME) < datetime.now() - timedelta(days=age)
            )
        )

        total = qry.count()
        qry = qry.limit(limit)
        qry = qry.offset((page - 1) * limit if page > 1 else 0)

        return total, [cls(x) for x in qry.all()] 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:43,代码来源:resources.py

示例6: downgrade

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

    # Add old columns with usercache
    op.create_index('ix_usercache_expiration', 'usercache', ['expiration'], unique=False)
    op.add_column('usercache', sa.Column('expiration', sa.DATETIME(), nullable=True))
    op.add_column('usercache', sa.Column('realm', sa.VARCHAR(length=256), nullable=True))

    # Remove Oracle Schema definition
    op.alter_column('tokenrealm', 'id',
               existing_type=sa.INTEGER(),
               nullable=False)
    op.drop_index(op.f('ix_token_user_id'), table_name='token')
    op.drop_index(op.f('ix_token_tokentype'), table_name='token')
    op.drop_index(op.f('ix_token_serial'), table_name='token')
    op.drop_index(op.f('ix_token_resolver'), table_name='token')
    op.alter_column('token', 'active',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.drop_index(op.f('ix_subscription_application'), table_name='subscription')
    op.drop_constraint(None, 'smsgateway')
    op.drop_constraint(None, 'resolver')
    op.drop_constraint(None, 'realm')
    op.drop_constraint(None, 'radiusserver')
    op.drop_constraint(None, 'policy')
    op.create_index('ix_pidea_audit_id', 'pidea_audit', ['id'], unique=False)
    op.drop_constraint(None, 'machineresolver')
    op.create_index('ix_clientapplication_id', 'clientapplication', ['id'], unique=False)
    op.drop_constraint(None, 'caconnector') 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:30,代码来源:4238eac8ccab_.py

示例7: test_reflect_select

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def test_reflect_select(table, table_using_test_dataset):
    for table in [table, table_using_test_dataset]:
        assert len(table.c) == 18

        assert isinstance(table.c.integer, Column)
        assert isinstance(table.c.integer.type, types.Integer)
        assert isinstance(table.c.timestamp.type, types.TIMESTAMP)
        assert isinstance(table.c.string.type, types.String)
        assert isinstance(table.c.float.type, types.Float)
        assert isinstance(table.c.boolean.type, types.Boolean)
        assert isinstance(table.c.date.type, types.DATE)
        assert isinstance(table.c.datetime.type, types.DATETIME)
        assert isinstance(table.c.time.type, types.TIME)
        assert isinstance(table.c.bytes.type, types.BINARY)
        assert isinstance(table.c['record.age'].type, types.Integer)
        assert isinstance(table.c['record.name'].type, types.String)
        assert isinstance(table.c['nested_record.record.age'].type, types.Integer)
        assert isinstance(table.c['nested_record.record.name'].type, types.String)
        assert isinstance(table.c.array.type, types.ARRAY)

        rows = table.select().execute().fetchall()
        assert len(rows) == 1000 
开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:24,代码来源:test_sqlalchemy_bigquery.py

示例8: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('user') as batch_op:
        batch_op.alter_column('created',
               existing_type=sa.DATETIME(),
               nullable=False)
        batch_op.alter_column('updated',
               existing_type=sa.DATETIME(),
               nullable=False)
    ### end Alembic commands ### 
开发者ID:frol,项目名称:flask-restplus-server-example,代码行数:12,代码来源:2e9d99288cd_.py

示例9: downgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('user') as batch_op:
        batch_op.alter_column('updated',
               existing_type=sa.DATETIME(),
               nullable=True)
        batch_op.alter_column('created',
               existing_type=sa.DATETIME(),
               nullable=True)
    ### end Alembic commands ### 
开发者ID:frol,项目名称:flask-restplus-server-example,代码行数:12,代码来源:2e9d99288cd_.py

示例10: test_render_table_upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def test_render_table_upgrade(self):
        m = MetaData()
        t = Table(
            "test",
            m,
            Column("id", Integer, primary_key=True),
            Column("name", Unicode(255)),
            Column("address_id", Integer, ForeignKey("address.id")),
            Column("timestamp", DATETIME, server_default="NOW()"),
            Column("amount", Numeric(5, 2)),
            UniqueConstraint("name", name="uq_name"),
            UniqueConstraint("timestamp"),
        )

        op_obj = ops.CreateTableOp.from_table(t)
        eq_ignore_whitespace(
            autogenerate.render_op_text(self.autogen_context, op_obj),
            "op.create_table('test',"
            "sa.Column('id', sa.Integer(), nullable=False),"
            "sa.Column('name', sa.Unicode(length=255), nullable=True),"
            "sa.Column('address_id', sa.Integer(), nullable=True),"
            "sa.Column('timestamp', sa.DATETIME(), "
            "server_default='NOW()', "
            "nullable=True),"
            "sa.Column('amount', sa.Numeric(precision=5, scale=2), "
            "nullable=True),"
            "sa.ForeignKeyConstraint(['address_id'], ['address.id'], ),"
            "sa.PrimaryKeyConstraint('id'),"
            "sa.UniqueConstraint('name', name='uq_name'),"
            "sa.UniqueConstraint('timestamp')"
            ")",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:34,代码来源:test_autogen_render.py

示例11: test_alter_column_modify_datetime_default

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def test_alter_column_modify_datetime_default(self):
        # use CHANGE format when the datatype is DATETIME or TIMESTAMP,
        # as this is needed for a functional default which is what you'd
        # get with a DATETIME/TIMESTAMP.  Will also work in the very unlikely
        # case the default is a fixed timestamp value.
        context = op_fixture("mysql")
        op.alter_column(
            "t",
            "c",
            existing_type=DATETIME(),
            server_default=text("CURRENT_TIMESTAMP"),
        )
        context.assert_(
            "ALTER TABLE t CHANGE c c DATETIME NULL DEFAULT CURRENT_TIMESTAMP"
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:17,代码来源:test_mysql.py

示例12: test_add_datetime_server_default_current_timestamp

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def test_add_datetime_server_default_current_timestamp(self):
        self._run_alter_col(
            {"type": DATETIME()}, {"server_default": text("CURRENT_TIMESTAMP")}
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:6,代码来源:test_mysql.py

示例13: test_add_datetime_server_default_now

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def test_add_datetime_server_default_now(self):
        self._run_alter_col(
            {"type": DATETIME()},
            {"server_default": text("NOW()")},
            compare={"server_default": text("CURRENT_TIMESTAMP")},
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:8,代码来源:test_mysql.py

示例14: test_add_datetime_server_default_current_timestamp_bundle_onupdate

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def test_add_datetime_server_default_current_timestamp_bundle_onupdate(
        self,
    ):
        # note SQLAlchemy reflection bundles the ON UPDATE part into the
        # server default reflection see
        # https://github.com/sqlalchemy/sqlalchemy/issues/4652
        self._run_alter_col(
            {"type": DATETIME()},
            {
                "server_default": text(
                    "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
                )
            },
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:16,代码来源:test_mysql.py

示例15: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DATETIME [as 别名]
def upgrade():
    """Fix server defaults for DATETIME columns, because
    0 ("0000-00-00 00:00:00") is deprecated as default for those colum types
    as of mysql 5.7.8, and will fail with mysql installed with default config.
    """
    op.alter_column("instance_status_history", "timestamp",
                    server_default=None,
                    existing_type=sa.DATETIME,
                    existing_nullable=False) 
开发者ID:htm-community,项目名称:skeleton-htmengine-app,代码行数:11,代码来源:002_872a895b8e8_fix_datetime_and_timestamp_defaults.py


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