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