當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。