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


Python types.Interval方法代码示例

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


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

示例1: test_python_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types 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: test_querying_table

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Interval [as 别名]
def test_querying_table(metadata):
    """
    Create an object for test table.

    """

    # When using pytest-xdist, we don't want concurrent table creations
    # across test processes so we assign a unique name for table based on
    # the current worker id.
    worker_id = os.environ.get('PYTEST_XDIST_WORKER', 'master')
    return Table(
        'test_querying_table_' + worker_id, metadata,
        Column('id', types.Integer, autoincrement=True, primary_key=True),
        Column('serial', types.Integer, Sequence("serial_seq")),
        Column('t_string', types.String(60), onupdate='updated'),
        Column('t_list', types.ARRAY(types.String(60))),
        Column('t_enum', types.Enum(MyEnum)),
        Column('t_int_enum', types.Enum(MyIntEnum)),
        Column('t_datetime', types.DateTime()),
        Column('t_date', types.DateTime()),
        Column('t_interval', types.Interval()),
        Column('uniq_uuid', PG_UUID, nullable=False, unique=True, default=uuid4),
    ) 
开发者ID:CanopyTax,项目名称:asyncpgsa,代码行数:25,代码来源:test_querying.py

示例3: initialize

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Interval [as 别名]
def initialize(self, connection):
        super(OracleDialect, self).initialize(connection)
        self.implicit_returning = self.__dict__.get(
            'implicit_returning',
            self.server_version_info > (10, )
        )

        if self._is_oracle_8:
            self.colspecs = self.colspecs.copy()
            self.colspecs.pop(sqltypes.Interval)
            self.use_ansi = False 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:base.py

示例4: _resolve_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Interval [as 别名]
def _resolve_type(self, t, **kw):
        """
        Resolve types for String, Numeric, Date/Time, etc. columns
        """
        t = self.normalize_name(t)
        if t in ischema_names:
            #print(t,ischema_names[t])
            t = ischema_names[t]
            
            if issubclass(t, sqltypes.String):
                return t(length=kw['length']/2 if kw['chartype']=='UNICODE' else kw['length'],\
                            charset=kw['chartype'])

            elif issubclass(t, sqltypes.Numeric):
                return t(precision=kw['prec'], scale=kw['scale'])

            elif issubclass(t, sqltypes.Time) or issubclass(t, sqltypes.DateTime):
                #Timezone
                tz=kw['fmt'][-1]=='Z'

                #Precision                
                prec = kw['fmt']    
                #For some timestamps and dates, there is no precision, or indicatd in scale
                prec = prec[prec.index('(') + 1: prec.index(')')] if '(' in prec else 0
                prec = kw['scale'] if prec=='F' else int(prec)

                #prec = int(prec[prec.index('(') + 1: prec.index(')')]) if '(' in prec else 0
                return t(precision=prec,timezone=tz)

            elif issubclass(t, sqltypes.Interval):
                return t(day_precision=kw['prec'],second_precision=kw['scale'])

            else:
                return t() # For types like Integer, ByteInt

        return ischema_names[None] 
开发者ID:Teradata,项目名称:sqlalchemy-teradata,代码行数:38,代码来源:dialect.py

示例5: test_interval

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Interval [as 别名]
def test_interval(self):
        self._test('interval', sqltypes.Interval) 
开发者ID:cockroachdb,项目名称:sqlalchemy-cockroachdb,代码行数:4,代码来源:test_introspection.py

示例6: test_ad_hoc_types

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Interval [as 别名]
def test_ad_hoc_types(self):
        """test storage of bind processors, result processors
        in dialect-wide registry."""

        from sqlalchemy.dialects import mysql, postgresql, sqlite
        from sqlalchemy import types

        eng = engines.testing_engine()
        for args in (
            (types.Integer,),
            (types.String,),
            (types.PickleType,),
            (types.Enum, "a", "b", "c"),
            (sqlite.DATETIME,),
            (postgresql.ENUM, "a", "b", "c"),
            (types.Interval,),
            (postgresql.INTERVAL,),
            (mysql.VARCHAR,),
        ):

            @profile_memory()
            def go():
                type_ = args[0](*args[1:])
                bp = type_._cached_bind_processor(eng.dialect)
                rp = type_._cached_result_processor(eng.dialect, 0)
                bp, rp  # strong reference

            go()

        assert not eng.dialect._type_memos 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:32,代码来源:test_memusage.py

示例7: test_interval_coercion

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

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

示例8: test_date_coercion

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types 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

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types 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

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types 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

示例11: __init__

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Interval [as 别名]
def __init__(self):
        self._types = {
            # Django internal type => SQLAlchemy type
            'ArrayField': SA_ARRAY,
            'AutoField': sa_types.Integer,
            'BigAutoField': sa_types.BigInteger,
            'BigIntegerField': sa_types.BigInteger,
            'BooleanField': sa_types.Boolean,
            'CharField': sa_types.String,
            'DateField': sa_types.Date,
            'DateTimeField': sa_types.DateTime,
            'DecimalField': sa_types.Numeric,
            'DurationField': sa_types.Interval,
            'FileField': sa_types.String,
            'FilePathField': sa_types.String,
            'FloatField': sa_types.Float,
            'GenericIPAddressField': sa_types.String,
            'IntegerField': sa_types.Integer,
            'JSONField': SA_JSONB,
            'NullBooleanField': sa_types.Boolean,
            'PointField': Geometry,
            'PositiveIntegerField': sa_types.Integer,
            'PositiveSmallIntegerField': sa_types.SmallInteger,
            'SlugField': sa_types.String,
            'SmallIntegerField': sa_types.SmallInteger,
            'TextField': sa_types.Text,
            'TimeField': sa_types.Time,
            'UUIDField': SA_UUID,
            # TODO: Add missing GIS fields
        } 
开发者ID:dvhb,项目名称:dvhb-hybrid,代码行数:32,代码来源:convert.py

示例12: initialize

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Interval [as 别名]
def initialize(self, connection):
        super(OracleDialect, self).initialize(connection)
        self.implicit_returning = self.__dict__.get(
                                    'implicit_returning',
                                    self.server_version_info > (10, )
                                    )

        if self._is_oracle_8:
            self.colspecs = self.colspecs.copy()
            self.colspecs.pop(sqltypes.Interval)
            self.use_ansi = False 
开发者ID:binhex,项目名称:moviegrabber,代码行数:13,代码来源:base.py


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