我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用sqlalchemy.types.Time()。
def bind_processor(self, dialect): datetime_time = datetime.time format = self._storage_format def process(value): if value is None: return None elif isinstance(value, datetime_time): return format % { 'hour': value.hour, 'minute': value.minute, 'second': value.second, 'microsecond': value.microsecond, } else: raise TypeError("SQLite Time type only accepts Python " "time objects as input.") return process
def psql_map_type(t): if isinstance(t,String): return {'type':'string'} elif isinstance(t,Numeric) or isinstance(t,Integer): return {'type':'number'} elif isinstance(t,Boolean): return {'type':'boolean'} elif isinstance(t,Date): return {'type':'date'} elif isinstance(t,Time): return {'type':'time'} elif isinstance(t,DateTime): return {'type':'datetime'} # Python operator and function signature tables
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]
def _test_get_columns(self, schema=None, table_type='table'): meta = MetaData(testing.db) users, addresses, dingalings = self.tables.users, \ self.tables.email_addresses, self.tables.dingalings table_names = ['users', 'email_addresses'] if table_type == 'view': table_names = ['users_v', 'email_addresses_v'] insp = inspect(meta.bind) for table_name, table in zip(table_names, (users, addresses)): schema_name = schema cols = insp.get_columns(table_name, schema=schema_name) self.assert_(len(cols) > 0, len(cols)) # should be in order for i, col in enumerate(table.columns): eq_(col.name, cols[i]['name']) ctype = cols[i]['type'].__class__ ctype_def = col.type if isinstance(ctype_def, sa.types.TypeEngine): ctype_def = ctype_def.__class__ # Oracle returns Date for DateTime. if testing.against('oracle') and ctype_def \ in (sql_types.Date, sql_types.DateTime): ctype_def = sql_types.Date # assert that the desired type and return type share # a base within one of the generic types. self.assert_(len(set(ctype.__mro__). intersection(ctype_def.__mro__). intersection([ sql_types.Integer, sql_types.Numeric, sql_types.DateTime, sql_types.Date, sql_types.Time, sql_types.String, sql_types._Binary, ])) > 0, '%s(%s), %s(%s)' % (col.name, col.type, cols[i]['name'], ctype)) if not col.primary_key: assert cols[i]['default'] is None
def _test_get_columns(self, schema=None, table_type='table'): meta = MetaData(testing.db) users, addresses, dingalings = self.tables.users, \ self.tables.email_addresses, self.tables.dingalings table_names = ['users', 'email_addresses'] if table_type == 'view': table_names = ['users_v', 'email_addresses_v'] insp = inspect(meta.bind) for table_name, table in zip(table_names, (users, addresses)): schema_name = schema cols = insp.get_columns(table_name, schema=schema_name) self.assert_(len(cols) > 0, len(cols)) # should be in order for i, col in enumerate(table.columns): eq_(col.name, cols[i]['name']) ctype = cols[i]['type'].__class__ ctype_def = col.type if isinstance(ctype_def, sa.types.TypeEngine): ctype_def = ctype_def.__class__ # Oracle returns Date for DateTime. if testing.against('oracle') and ctype_def \ in (sql_types.Date, sql_types.DateTime): ctype_def = sql_types.Date # assert that the desired type and return type share # a base within one of the generic types. self.assert_(len(set(ctype.__mro__). intersection(ctype_def.__mro__).intersection([ sql_types.Integer, sql_types.Numeric, sql_types.DateTime, sql_types.Date, sql_types.Time, sql_types.String, sql_types._Binary, ])) > 0, '%s(%s), %s(%s)' % (col.name, col.type, cols[i]['name'], ctype)) if not col.primary_key: assert cols[i]['default'] is None