Python sqlalchemy.Time() Examples
The following are 9
code examples of sqlalchemy.Time().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy
, or try the search function
.
Example #1
Source File: alchemy.py From ibis with Apache License 2.0 | 5 votes |
def sa_time(_, satype, nullable=True): return dt.Time(nullable=nullable)
Example #2
Source File: fields.py From ormantic with BSD 3-Clause "New" or "Revised" License | 5 votes |
def Time( *, primary_key: bool = False, allow_null: bool = False, index: bool = False, unique: bool = False, ) -> Type[time]: namespace = dict( primary_key=primary_key, allow_null=allow_null, index=index, unique=unique, column_type=sqlalchemy.Time(), ) return type("Time", (time, ColumnFactory), namespace)
Example #3
Source File: test_query.py From sqlalchemy with MIT License | 5 votes |
def define_tables(cls, metadata): Table( "t", metadata, Column("id", Integer, primary_key=True), Column("dtme", DateTime), Column("dt", Date), Column("tm", Time), Column("intv", postgresql.INTERVAL), Column("dttz", DateTime(timezone=True)), )
Example #4
Source File: test_types.py From sqlalchemy with MIT License | 5 votes |
def define_tables(cls, metadata): Table( "time_t", metadata, Column("id", Integer, primary_key=True, autoincrement=False), Column("time_col", Time), )
Example #5
Source File: test_types.py From sqlalchemy with MIT License | 5 votes |
def date_fixture(self, metadata): t = Table( "test_dates", metadata, Column("adate", Date), Column("atime1", Time), Column("atime2", Time), Column("adatetime", DateTime), Column("adatetimeoffset", DATETIMEOFFSET), ) d1 = datetime.date(2007, 10, 30) t1 = datetime.time(11, 2, 32) d2 = datetime.datetime(2007, 10, 30, 11, 2, 32) return t, (d1, t1, d2)
Example #6
Source File: mapper.py From tableschema-sql-py with MIT License | 5 votes |
def convert_type(self, type): """Convert type to SQL """ # Default dialect mapping = { 'any': sa.Text, 'array': None, 'boolean': sa.Boolean, 'date': sa.Date, 'datetime': sa.DateTime, 'duration': None, 'geojson': None, 'geopoint': None, 'integer': sa.Integer, 'number': sa.Float, 'object': None, 'string': sa.Text, 'time': sa.Time, 'year': sa.Integer, 'yearmonth': None, } # Postgresql dialect if self.__dialect == 'postgresql': mapping.update({ 'array': JSONB, 'geojson': JSONB, 'number': sa.Numeric, 'object': JSONB, }) # Not supported type if type not in mapping: message = 'Field type "%s" is not supported' raise tableschema.exceptions.StorageError(message % type) return mapping[type]
Example #7
Source File: mapper.py From tableschema-sql-py with MIT License | 5 votes |
def restore_type(self, type): """Restore type from SQL """ # All dialects mapping = { ARRAY: 'array', sa.Boolean: 'boolean', sa.Date: 'date', sa.DateTime: 'datetime', sa.Float: 'number', sa.Integer: 'integer', JSONB: 'object', JSON: 'object', sa.Numeric: 'number', sa.Text: 'string', sa.Time: 'time', sa.VARCHAR: 'string', UUID: 'string', } # Get field type field_type = None for key, value in mapping.items(): if isinstance(type, key): field_type = value # Not supported if field_type is None: message = 'Type "%s" is not supported' raise tableschema.exceptions.StorageError(message % type) return field_type # Internal
Example #8
Source File: test_types.py From sqlalchemy with MIT License | 4 votes |
def test_dates(self): "Exercise type specification for date types." columns = [ # column type, args, kwargs, expected ddl (mssql.MSDateTime, [], {}, "DATETIME", None), (types.DATE, [], {}, "DATE", None), (types.Date, [], {}, "DATE", None), (types.Date, [], {}, "DATETIME", MS_2005_VERSION), (mssql.MSDate, [], {}, "DATE", None), (mssql.MSDate, [], {}, "DATETIME", MS_2005_VERSION), (types.TIME, [], {}, "TIME", None), (types.Time, [], {}, "TIME", None), (mssql.MSTime, [], {}, "TIME", None), (mssql.MSTime, [1], {}, "TIME(1)", None), (types.Time, [], {}, "DATETIME", MS_2005_VERSION), (mssql.MSTime, [], {}, "TIME", None), (mssql.MSSmallDateTime, [], {}, "SMALLDATETIME", None), (mssql.MSDateTimeOffset, [], {}, "DATETIMEOFFSET", None), (mssql.MSDateTimeOffset, [1], {}, "DATETIMEOFFSET(1)", None), (mssql.MSDateTime2, [], {}, "DATETIME2", None), (mssql.MSDateTime2, [0], {}, "DATETIME2(0)", None), (mssql.MSDateTime2, [1], {}, "DATETIME2(1)", None), (mssql.MSTime, [0], {}, "TIME(0)", None), (mssql.MSDateTimeOffset, [0], {}, "DATETIMEOFFSET(0)", None), ] metadata = MetaData() table_args = ["test_mssql_dates", metadata] for index, spec in enumerate(columns): type_, args, kw, res, server_version = spec table_args.append( Column("c%s" % index, type_(*args, **kw), nullable=None) ) date_table = Table(*table_args) dialect = mssql.dialect() dialect.server_version_info = MS_2008_VERSION ms_2005_dialect = mssql.dialect() ms_2005_dialect.server_version_info = MS_2005_VERSION gen = dialect.ddl_compiler(dialect, schema.CreateTable(date_table)) gen2005 = ms_2005_dialect.ddl_compiler( ms_2005_dialect, schema.CreateTable(date_table) ) for col in date_table.c: index = int(col.name[1:]) server_version = columns[index][4] if not server_version: testing.eq_( gen.get_column_specification(col), "%s %s" % (col.name, columns[index][3]), ) else: testing.eq_( gen2005.get_column_specification(col), "%s %s" % (col.name, columns[index][3]), ) self.assert_(repr(col))
Example #9
Source File: test_types.py From sqlalchemy with MIT License | 4 votes |
def test_dates(self): "Exercise type specification for date types." columns = [ # column type, args, kwargs, expected ddl (mssql.MSDateTime, [], {}, "DATETIME", []), (types.DATE, [], {}, "DATE", [">=", (10,)]), (types.Date, [], {}, "DATE", [">=", (10,)]), (types.Date, [], {}, "DATETIME", ["<", (10,)], mssql.MSDateTime), (mssql.MSDate, [], {}, "DATE", [">=", (10,)]), (mssql.MSDate, [], {}, "DATETIME", ["<", (10,)], mssql.MSDateTime), (types.TIME, [], {}, "TIME", [">=", (10,)]), (types.Time, [], {}, "TIME", [">=", (10,)]), (mssql.MSTime, [], {}, "TIME", [">=", (10,)]), (mssql.MSTime, [1], {}, "TIME(1)", [">=", (10,)]), (types.Time, [], {}, "DATETIME", ["<", (10,)], mssql.MSDateTime), (mssql.MSTime, [], {}, "TIME", [">=", (10,)]), (mssql.MSSmallDateTime, [], {}, "SMALLDATETIME", []), (mssql.MSDateTimeOffset, [], {}, "DATETIMEOFFSET", [">=", (10,)]), ( mssql.MSDateTimeOffset, [1], {}, "DATETIMEOFFSET(1)", [">=", (10,)], ), (mssql.MSDateTime2, [], {}, "DATETIME2", [">=", (10,)]), (mssql.MSDateTime2, [0], {}, "DATETIME2(0)", [">=", (10,)]), (mssql.MSDateTime2, [1], {}, "DATETIME2(1)", [">=", (10,)]), ] table_args = ["test_mssql_dates", metadata] for index, spec in enumerate(columns): type_, args, kw, res, requires = spec[0:5] if ( requires and testing._is_excluded("mssql", *requires) or not requires ): c = Column("c%s" % index, type_(*args, **kw), nullable=None) testing.db.dialect.type_descriptor(c.type) table_args.append(c) dates_table = Table(*table_args) gen = testing.db.dialect.ddl_compiler( testing.db.dialect, schema.CreateTable(dates_table) ) for col in dates_table.c: index = int(col.name[1:]) testing.eq_( gen.get_column_specification(col), "%s %s" % (col.name, columns[index][3]), ) self.assert_(repr(col)) dates_table.create(checkfirst=True) reflected_dates = Table( "test_mssql_dates", MetaData(testing.db), autoload=True ) for col in reflected_dates.c: self.assert_types_base(col, dates_table.c[col.key])