我们从Python开源项目中,提取了以下28个代码示例,用于说明如何使用sqlalchemy.types.Interval()。
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('t_string', types.String(60)), 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), )
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
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]