我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用sqlalchemy.types.DATE。
def initialize(self, connection): super(FBDialect, self).initialize(connection) self._version_two = ('firebird' in self.server_version_info and self.server_version_info >= (2, ) ) or \ ('interbase' in self.server_version_info and self.server_version_info >= (6, ) ) if not self._version_two: # TODO: whatever other pre < 2.0 stuff goes here self.ischema_names = ischema_names.copy() self.ischema_names['TIMESTAMP'] = sqltypes.DATE self.colspecs = { sqltypes.DateTime: sqltypes.DATE } self.implicit_returning = self._version_two and \ self.__dict__.get('implicit_returning', True)
def initialize(self, connection): super(FBDialect, self).initialize(connection) self._version_two = ('firebird' in self.server_version_info and \ self.server_version_info >= (2, ) ) or \ ('interbase' in self.server_version_info and \ self.server_version_info >= (6, ) ) if not self._version_two: # TODO: whatever other pre < 2.0 stuff goes here self.ischema_names = ischema_names.copy() self.ischema_names['TIMESTAMP'] = sqltypes.DATE self.colspecs = { sqltypes.DateTime: sqltypes.DATE } self.implicit_returning = self._version_two and \ self.__dict__.get('implicit_returning', True)
def sqltype_to_stdtype(sqltype): import sqlalchemy.types as sqltypes if isinstance(sqltype, (sqltypes.VARCHAR, sqltypes.CHAR, sqltypes.TEXT, sqltypes.Enum, sqltypes.String)): return _STRING_TYPE if isinstance(sqltype, (sqltypes.DATETIME, sqltypes.DATE, sqltypes.TIME, sqltypes.TIMESTAMP)): return _DATE_TYPE if isinstance(sqltype, (sqltypes.INTEGER, sqltypes.BIGINT, sqltypes.SMALLINT, sqltypes.Integer)): return _INTEGER_TYPE if isinstance(sqltype, (sqltypes.REAL, sqltypes.DECIMAL, sqltypes.NUMERIC, sqltypes.FLOAT)): return _DECIMAL_TYPE if isinstance(sqltype, sqltypes.BOOLEAN): return _BOOLEAN_TYPE
def stdtype_to_sqltype(stdtype): import sqlalchemy.types as sqltypes if isinstance(stdtype, stdtypes.StringType): return sqltypes.VARCHAR(length=stdtype.max_len) if 0 < stdtype.max_len < 65536 else sqltypes.TEXT() if isinstance(stdtype, stdtypes.BoolType): return sqltypes.BOOLEAN() if isinstance(stdtype, stdtypes.DateType): return sqltypes.DATE() if stdtype.only_date else sqltypes.TIMESTAMP() if isinstance(stdtype, stdtypes.IntegerType): return sqltypes.BIGINT() if stdtype.length > 11 else sqltypes.INTEGER() if isinstance(stdtype, stdtypes.DecimalType): return sqltypes.DECIMAL() if isinstance(stdtype, stdtypes.ArrayType): return sqltypes.ARRAY(item_type=stdtype.item_type)
def test_reflect_select(engine, table): assert len(table.c) == 9 assert isinstance(table.c.integer, Column) assert isinstance(table.c.integer.type, types.Integer) assert isinstance(table.c.timestamp.type, types.TIMESTAMP) assert isinstance(table.c.string.type, types.String) assert isinstance(table.c.float.type, types.Float) assert isinstance(table.c.boolean.type, types.Boolean) assert isinstance(table.c.date.type, types.DATE) assert isinstance(table.c.datetime.type, types.DATETIME) assert isinstance(table.c.time.type, types.TIME) assert isinstance(table.c.bytes.type, types.BINARY) rows = table.select().execute().fetchall() assert len(rows) == 1000