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


Python sqlalchemy.Interval方法代码示例

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


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

示例1: test_python_type

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def test_python_type(self):
        eq_(types.Integer().python_type, int)
        eq_(types.Numeric().python_type, decimal.Decimal)
        eq_(types.Numeric(asdecimal=False).python_type, float)
        eq_(types.LargeBinary().python_type, util.binary_type)
        eq_(types.Float().python_type, float)
        eq_(types.Interval().python_type, datetime.timedelta)
        eq_(types.Date().python_type, datetime.date)
        eq_(types.DateTime().python_type, datetime.datetime)
        eq_(types.String().python_type, str)
        eq_(types.Unicode().python_type, util.text_type)
        eq_(types.Enum("one", "two", "three").python_type, str)

        assert_raises(
            NotImplementedError, lambda: types.TypeEngine().python_type
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py

示例2: setup_class

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def setup_class(cls):
        global interval_table, metadata
        metadata = MetaData(testing.db)
        interval_table = Table(
            "intervaltable",
            metadata,
            Column(
                "id", Integer, primary_key=True, test_needs_autoincrement=True
            ),
            Column("native_interval", Interval()),
            Column(
                "native_interval_args",
                Interval(day_precision=3, second_precision=6),
            ),
            Column("non_native_interval", Interval(native=False)),
        )
        metadata.create_all() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_types.py

示例3: get_last_events

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def get_last_events(self, request):
		try:
			last_event_id = int(request.headers.get('Last-Event-Id', request.query.get('last-event-id')))
		except (ValueError, TypeError):
			last_event_id = None
		interval = request.query.get('interval')
		if interval is not None and last_event_id is None:
			last_event_id = 0
		if last_event_id is not None:
			events = self.metadata.tables['events']
			query = sqlalchemy.select([
				events.c.id, events.c.event, events.c.data, events.c.time
			])
			query = query.where(events.c.id > last_event_id)
			if interval is not None:
				query = query.where(events.c.time > sqlalchemy.func.current_timestamp() - sqlalchemy.cast(interval, sqlalchemy.Interval))
			query = query.order_by(events.c.id)
			try:
				with self.engine.begin() as conn:
					return [
						{'id': id, 'event': event, 'data': dict(data, time=time.isoformat())}
						for id, event, data, time in conn.execute(query)
					]
			except sqlalchemy.exc.DataError as e:
				raise aiohttp.web.HTTPBadRequest from e
		return [] 
开发者ID:mrphlip,项目名称:lrrbot,代码行数:28,代码来源:eventserver.py

示例4: test_compare_interval_str

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def test_compare_interval_str(self):
        # this form shouldn't be used but testing here
        # for compatibility
        self._compare_default_roundtrip(Interval, "14 days") 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:6,代码来源:test_postgresql.py

示例5: test_compare_interval_text

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def test_compare_interval_text(self):
        self._compare_default_roundtrip(Interval, text("'14 days'")) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:4,代码来源:test_postgresql.py

示例6: is_interval_field

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def is_interval_field(model, fieldname):
    """Returns ``True`` if and only if the field of `model` with the specified
    name corresponds to a :class:`datetime.timedelta` object.

    """
    fieldtype = get_field_type(model, fieldname)
    return isinstance(fieldtype, Interval) 
开发者ID:yfauser,项目名称:planespotter,代码行数:9,代码来源:helpers.py

示例7: strings_to_dates

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def strings_to_dates(model, dictionary):
    """Returns a new dictionary with all the mappings of `dictionary` but
    with date strings and intervals mapped to :class:`datetime.datetime` or
    :class:`datetime.timedelta` objects.

    The keys of `dictionary` are names of fields in the model specified in the
    constructor of this class. The values are values to set on these fields. If
    a field name corresponds to a field in the model which is a
    :class:`sqlalchemy.types.Date`, :class:`sqlalchemy.types.DateTime`, or
    :class:`sqlalchemy.Interval`, then the returned dictionary will have the
    corresponding :class:`datetime.datetime` or :class:`datetime.timedelta`
    Python object as the value of that mapping in place of the string.

    This function outputs a new dictionary; it does not modify the argument.

    """
    result = {}
    for fieldname, value in dictionary.items():
        if is_date_field(model, fieldname) and value is not None:
            if value.strip() == '':
                result[fieldname] = None
            elif value in CURRENT_TIME_MARKERS:
                result[fieldname] = getattr(func, value.lower())()
            else:
                value_as_datetime = parse_datetime(value)
                result[fieldname] = value_as_datetime
                # If the attribute on the model needs to be a Date object as
                # opposed to a DateTime object, just get the date component of
                # the datetime.
                fieldtype = get_field_type(model, fieldname)
                if isinstance(fieldtype, Date):
                    result[fieldname] = value_as_datetime.date()
        elif (is_interval_field(model, fieldname) and value is not None
              and isinstance(value, int)):
            result[fieldname] = datetime.timedelta(seconds=value)
        else:
            result[fieldname] = value
    return result 
开发者ID:yfauser,项目名称:planespotter,代码行数:40,代码来源:helpers.py

示例8: test_date_coercion

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def test_date_coercion(self):
        expr = column("bar", types.NULLTYPE) - column("foo", types.TIMESTAMP)
        eq_(expr.type._type_affinity, types.NullType)

        expr = func.sysdate() - column("foo", types.TIMESTAMP)
        eq_(expr.type._type_affinity, types.Interval)

        expr = func.current_date() - column("foo", types.TIMESTAMP)
        eq_(expr.type._type_affinity, types.Interval) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:11,代码来源:test_types.py

示例9: test_interval_coercion

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def test_interval_coercion(self):
        expr = column("bar", types.Interval) + column("foo", types.Date)
        eq_(expr.type._type_affinity, types.DateTime)

        expr = column("bar", types.Interval) * column("foo", types.Numeric)
        eq_(expr.type._type_affinity, types.Interval) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:8,代码来源:test_types.py

示例10: test_non_native_adapt

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Interval [as 别名]
def test_non_native_adapt(self):
        interval = Interval(native=False)
        adapted = interval.dialect_impl(testing.db.dialect)
        assert isinstance(adapted, Interval)
        assert adapted.native is False
        eq_(str(adapted), "DATETIME") 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:8,代码来源:test_types.py


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