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


Python func.extract方法代码示例

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


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

示例1: test_extract_bind

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import extract [as 别名]
def test_extract_bind(self, connection):
        """Basic common denominator execution tests for extract()"""

        date = datetime.date(2010, 5, 1)

        def execute(field):
            return connection.execute(select([extract(field, date)])).scalar()

        assert execute("year") == 2010
        assert execute("month") == 5
        assert execute("day") == 1

        date = datetime.datetime(2010, 5, 1, 12, 11, 10)

        assert execute("year") == 2010
        assert execute("month") == 5
        assert execute("day") == 1 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_functions.py

示例2: test_extract_expression

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import extract [as 别名]
def test_extract_expression(self, connection):
        meta = self.metadata
        table = Table("test", meta, Column("dt", DateTime), Column("d", Date))
        meta.create_all(connection)
        connection.execute(
            table.insert(),
            {
                "dt": datetime.datetime(2010, 5, 1, 12, 11, 10),
                "d": datetime.date(2010, 5, 1),
            },
        )
        rs = connection.execute(
            select([extract("year", table.c.dt), extract("month", table.c.d)])
        )
        row = rs.first()
        assert row[0] == 2010
        assert row[1] == 5
        rs.close() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_functions.py

示例3: __init__

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import extract [as 别名]
def __init__(self, field, expr, **kwargs):
        """Return a :class:`.Extract` construct.

        This is typically available as :func:`.extract`
        as well as ``func.extract`` from the
        :data:`.func` namespace.

        """
        self.type = type_api.INTEGERTYPE
        self.field = field
        self.expr = _literal_as_binds(expr, None) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:elements.py

示例4: __init__

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import extract [as 别名]
def __init__(self, field, expr, **kwargs):
        """Return a :class:`.Extract` construct.

        This is typically available as :func:`.extract`
        as well as ``func.extract`` from the
        :data:`.func` namespace.

        """
        self.type = type_api.INTEGERTYPE
        self.field = field
        self.expr = coercions.expect(roles.ExpressionElementRole, expr) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:13,代码来源:elements.py

示例5: test_non_functions

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import extract [as 别名]
def test_non_functions(self):
        expr = func.cast("foo", Integer)
        self.assert_compile(expr, "CAST(:param_1 AS INTEGER)")

        expr = func.extract("year", datetime.date(2010, 12, 5))
        self.assert_compile(expr, "EXTRACT(year FROM :param_1)") 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:8,代码来源:test_functions.py

示例6: get_user_activity

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import extract [as 别名]
def get_user_activity(session):
    """Create a plot showing the user statistics."""
    # Create a subquery to ensure that the user fired a inline query
    # Group the new users by date
    creation_date = cast(User.created_at, Date).label("creation_date")
    all_users_subquery = (
        session.query(creation_date, func.count(User.id).label("count"))
        .filter(User.inline_queries.any())
        .group_by(creation_date)
        .subquery()
    )

    # Create a running window which sums all users up to this point for the current millennium ;P
    all_users = (
        session.query(
            all_users_subquery.c.creation_date,
            cast(
                func.sum(all_users_subquery.c.count).over(
                    partition_by=func.extract(
                        "millennium", all_users_subquery.c.creation_date
                    ),
                    order_by=all_users_subquery.c.creation_date.asc(),
                ),
                Integer,
            ).label("running_total"),
        )
        .order_by(all_users_subquery.c.creation_date)
        .all()
    )
    all_users = [("all", q[0], q[1]) for q in all_users]

    # Combine the results in a single dataframe and name the columns
    user_statistics = all_users
    dataframe = pandas.DataFrame(user_statistics, columns=["type", "date", "users"])

    # Plot each result set
    fig, ax = plt.subplots(figsize=(30, 15), dpi=120)
    for key, group in dataframe.groupby(["type"]):
        ax = group.plot(ax=ax, kind="line", x="date", y="users", label=key)

    image = image_from_figure(fig)
    image.name = "user_statistics.png"
    return image 
开发者ID:Nukesor,项目名称:sticker-finder,代码行数:45,代码来源:plot.py


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