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


Python func.now方法代码示例

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


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

示例1: rename_table

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def rename_table(
            cls, operations, old_table_name, new_table_name, schema=None):
        """Emit an ALTER TABLE to rename a table.

        :param old_table_name: old name.
        :param new_table_name: new name.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        """
        op = cls(old_table_name, new_table_name, schema=schema)
        return operations.invoke(op) 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:ops.py

示例2: rename_table

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def rename_table(
        cls, operations, old_table_name, new_table_name, schema=None
    ):
        """Emit an ALTER TABLE to rename a table.

        :param old_table_name: old name.
        :param new_table_name: new name.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        """
        op = cls(old_table_name, new_table_name, schema=schema)
        return operations.invoke(op) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:20,代码来源:ops.py

示例3: test_render_server_default_no_context

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def test_render_server_default_no_context(self):
        uo = ops.UpgradeOps(
            ops=[
                ops.CreateTableOp(
                    "sometable",
                    [Column("x", types.DateTime(), server_default=func.now())],
                )
            ]
        )

        eq_ignore_whitespace(
            autogenerate.render_python_code(uo),
            "# ### commands auto generated by Alembic - please adjust! ###\n"
            "    op.create_table('sometable',\n"
            "    sa.Column('x', sa.DateTime(), "
            "server_default=sa.text(!U'now()'), nullable=True)\n"
            "    )\n"
            "    # ### end Alembic commands ###",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:21,代码来源:test_autogen_render.py

示例4: test_render_server_default_context_passed

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def test_render_server_default_context_passed(self):
        uo = ops.UpgradeOps(
            ops=[
                ops.CreateTableOp(
                    "sometable",
                    [Column("x", types.DateTime(), server_default=func.now())],
                )
            ]
        )
        context = MigrationContext.configure(dialect_name="sqlite")
        eq_ignore_whitespace(
            autogenerate.render_python_code(uo, migration_context=context),
            "# ### commands auto generated by Alembic - please adjust! ###\n"
            "    op.create_table('sometable',\n"
            "    sa.Column('x', sa.DateTime(), "
            "server_default=sa.text(!U'(CURRENT_TIMESTAMP)'), nullable=True)\n"
            "    )\n"
            "    # ### end Alembic commands ###",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:21,代码来源:test_autogen_render.py

示例5: anniversary

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def anniversary(self):
        """Return how many days left until next anniversary."""
        arrival_date = self.arrival_date
        if not arrival_date:
            return (False, 0)

        today = datetime.now()
        current_arrival_date = arrival_date.replace(year=today.year)
        # if it's already past for this year
        if current_arrival_date.date() < today.date():
            current_arrival_date += relativedelta(months=12)

        if current_arrival_date.date() == today.date():
            return (True, 0)

        delta = (today - current_arrival_date).days
        return (True if delta == 0 else False, abs(delta)) 
开发者ID:sayoun,项目名称:pyvac,代码行数:19,代码来源:models.py

示例6: get_cp_acquired_history

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def get_cp_acquired_history(cls, vac, acquired, user, today=None):
        """Get CP acquired history."""
        today = today or datetime.now()
        cycle_start, _ = vac.get_cycle_boundaries(today)

        cycle_start, _ = vac.get_cycle_boundaries(today)
        if cycle_start < vac.epoch:
            cycle_start = vac.epoch

        if cycle_start.day != 1:
            cycle_start = cycle_start + relativedelta(days=1)

        if user.arrival_date > cycle_start:
            cycle_start = user.arrival_date

        if user.country == 'lu':
            return [{'date': cycle_start, 'value': 200}]

        delta = relativedelta(cycle_start, today)
        months = abs(delta.months)

        return [{'date': cycle_start + relativedelta(months=idx),
                 'value': vac.coeff}
                for idx, item in enumerate(range(months + 1))] 
开发者ID:sayoun,项目名称:pyvac,代码行数:26,代码来源:models.py

示例7: get_acquis

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def get_acquis(cls, user, starting_date, today=None):
        """Retrieve amount of acquis for CP LU."""
        today = today or datetime.now()

        delta = relativedelta(starting_date, today)
        months = abs(delta.months)
        years = abs(delta.years)

        acquis = None
        cp_bonus = 0
        # add bonus CP based on arrival_date, 1 more per year each 5 years
        # cp bonus are added on the last acquisition day of previous cycle,
        # so on 31/05 of year - 1
        if years > 0:
            cp_bonus = int(math.floor(user.seniority / 5))

        if not months and years:
            months = 12
            acquis = 200 + cp_bonus

        log.debug('%s: using coeff %s * months %s + (bonus %s)' %
                  (user.login, cls.coeff, months, cp_bonus))
        acquis = acquis or (months * cls.coeff)
        return acquis 
开发者ID:sayoun,项目名称:pyvac,代码行数:26,代码来源:models.py

示例8: test_function_default

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def test_function_default(self):
        t = Table(
            "t",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column("x", DateTime(), server_default=func.now()),
        )
        t.create(testing.db)
        with testing.db.connect() as conn:
            now = conn.scalar(func.now())
            today = datetime.datetime.today()
            conn.execute(t.insert())
            conn.execute(t.insert().values(x=today))
            eq_(
                conn.execute(select([t.c.x]).order_by(t.c.id)).fetchall(),
                [(now,), (today,)],
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_sqlite.py

示例9: test_empty_insert_pk2

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def test_empty_insert_pk2(self):
        # now warns due to [ticket:3216]

        with expect_warnings(
            "Column 'b.x' is marked as a member of the "
            "primary key for table 'b'",
            "Column 'b.y' is marked as a member of the "
            "primary key for table 'b'",
        ):
            assert_raises(
                exc.IntegrityError,
                self._test_empty_insert,
                Table(
                    "b",
                    MetaData(testing.db),
                    Column("x", Integer, primary_key=True),
                    Column("y", Integer, primary_key=True),
                ),
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_sqlite.py

示例10: test_empty_insert_pk3

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def test_empty_insert_pk3(self):
        # now warns due to [ticket:3216]
        with expect_warnings(
            "Column 'c.x' is marked as a member of the primary key for table"
        ):
            assert_raises(
                exc.IntegrityError,
                self._test_empty_insert,
                Table(
                    "c",
                    MetaData(testing.db),
                    Column("x", Integer, primary_key=True),
                    Column(
                        "y", Integer, DefaultClause("123"), primary_key=True
                    ),
                ),
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_sqlite.py

示例11: test_outerjoin_of_select

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def test_outerjoin_of_select(self):
        stmt = select([self.table1.c.myid])

        with testing.expect_deprecated(
            r"The SelectBase.outerjoin\(\) method is deprecated and will be "
            "removed"
        ):
            self.assert_compile(
                stmt.outerjoin(
                    self.table2, self.table2.c.otherid == self.table1.c.myid
                ),
                # note the SQL is wrong here as the subquery now has a name
                "(SELECT mytable.myid AS myid FROM mytable) AS anon_1 "
                "LEFT OUTER JOIN myothertable "
                "ON myothertable.otherid = mytable.myid",
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_deprecations.py

示例12: from_profile

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def from_profile(cls, user, profile):
        if not user or user.is_anonymous:
            if not app.config.get("SECURITY_REGISTERABLE"):
                msg = "User not found. Registration disabled."
                logging.warning(msg)
                raise Exception(_(msg))
            email = profile.data.get("email")
            if not email:
                msg = "Please provide an email address."
                logging.warning(msg)
                raise Exception(_(msg))
            conflict = User.query.filter(User.email == email).first()
            if conflict:
                msg = "Email {} is already used. Login and then connect " + \
                      "external profile."
                msg = _(msg).format(email)
                logging.warning(msg)
                raise Exception(msg)

            now = datetime.now()
            user = User(
                email=email,
                name="{} {}".format(profile.data.get("first_name"),
                                    profile.data.get("last_name")),
                confirmed_at=now,
                active=True)

            db.session.add(user)
            db.session.flush()

        assert user.id, "User does not have an id"
        connection = cls(user_id=user.id, **profile.data)
        db.session.add(connection)
        db.session.commit()
        return connection 
开发者ID:beavyHQ,项目名称:beavy,代码行数:37,代码来源:social_connection.py

示例13: drop_constraint

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def drop_constraint(
            cls, operations, constraint_name, table_name,
            type_=None, schema=None):
        """Drop a constraint of the given name, typically via DROP CONSTRAINT.

        :param constraint_name: name of the constraint.
        :param table_name: table name.
        :param type_: optional, required on MySQL.  can be
         'foreignkey', 'primary', 'unique', or 'check'.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name

        """

        op = cls(constraint_name, table_name, type_=type_, schema=schema)
        return operations.invoke(op) 
开发者ID:jpush,项目名称:jbox,代码行数:28,代码来源:ops.py

示例14: drop_index

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def drop_index(cls, operations, index_name, table_name=None, schema=None):
        """Issue a "drop index" instruction using the current
        migration context.

        e.g.::

            drop_index("accounts")

        :param index_name: name of the index.
        :param table_name: name of the owning table.  Some
         backends such as Microsoft SQL Server require this.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> index_name

        """
        op = cls(index_name, table_name=table_name, schema=schema)
        return operations.invoke(op) 
开发者ID:jpush,项目名称:jbox,代码行数:29,代码来源:ops.py

示例15: upgrade

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import now [as 别名]
def upgrade():
    op.create_table('enforcements',
      sa.Column('enforcement_id', mysql.INTEGER(unsigned=True), nullable=False, autoincrement=True),
      sa.Column('account_id', mysql.INTEGER(unsigned=True)),
      sa.Column('resource_id', sa.String(length=256), nullable=False),
      sa.Column('action', sa.String(length=64), nullable=False),
      sa.Column('timestamp', mysql.DATETIME(timezone=False), default=func.now()),
      sa.Column('metrics', mysql.JSON()),
      sa.PrimaryKeyConstraint('enforcement_id')) 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:11,代码来源:3fca8951cd76_new_enforcements_table.py


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