本文整理汇总了Python中sqlalchemy.sql.sqltypes.DateTime方法的典型用法代码示例。如果您正苦于以下问题:Python sqltypes.DateTime方法的具体用法?Python sqltypes.DateTime怎么用?Python sqltypes.DateTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql.sqltypes
的用法示例。
在下文中一共展示了sqltypes.DateTime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_notna_dtype
# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import DateTime [as 别名]
def test_notna_dtype(self):
cols = {'Bool': Series([True, None]),
'Date': Series([datetime(2012, 5, 1), None]),
'Int': Series([1, None], dtype='object'),
'Float': Series([1.1, None])
}
df = DataFrame(cols)
tbl = 'notna_dtype_test'
df.to_sql(tbl, self.conn)
returned_df = sql.read_sql_table(tbl, self.conn) # noqa
meta = sqlalchemy.schema.MetaData(bind=self.conn)
meta.reflect()
if self.flavor == 'mysql':
my_type = sqltypes.Integer
else:
my_type = sqltypes.Boolean
col_dict = meta.tables[tbl].columns
assert isinstance(col_dict['Bool'].type, my_type)
assert isinstance(col_dict['Date'].type, sqltypes.DateTime)
assert isinstance(col_dict['Int'].type, sqltypes.Integer)
assert isinstance(col_dict['Float'].type, sqltypes.Float)
示例2: test_datatype
# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import DateTime [as 别名]
def test_datatype(self, table, column):
"""Tests that database column datatype matches the one defined in the
models.
"""
database_column = self.find_database_column(table, column)
if isinstance(column.type, sqltypes.String):
expected_type = sqltypes.VARCHAR
elif isinstance(column.type, sqltypes.Integer):
expected_type = sqltypes.INTEGER
elif isinstance(column.type, sqltypes.Boolean):
expected_type = sqltypes.BOOLEAN
elif isinstance(column.type, sqltypes.DateTime):
expected_type = sqltypes.DATETIME
if not isinstance(database_column['type'], expected_type):
self.errors.append(
DatatypeMismatch(table, database_column, expected_type,
parent=self)
)
示例3: test_sqlalchemy_type_mapping
# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import DateTime [as 别名]
def test_sqlalchemy_type_mapping(self):
# Test Timestamp objects (no datetime64 because of timezone) (GH9085)
df = DataFrame({'time': to_datetime(['201412120154', '201412110254'],
utc=True)})
db = sql.SQLDatabase(self.conn)
table = sql.SQLTable("test_type", db, frame=df)
assert isinstance(table.table.c['time'].type, sqltypes.DateTime)
示例4: parse_operator
# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import DateTime [as 别名]
def parse_operator(cls, filter_name_dict):
""" 用来返回sqlalchemy query对象filter使用的表达式
Args:
filter_name_dict (dict): 过滤条件dict
{
'last_name': {'eq': 'wang'}, # 如果是dic使用key作为操作符
'age': {'>': 12}
}
Returns:
binary_expression_list (lambda list)
"""
def _change_type(cls, field, value):
""" 有些表字段比如DateTime类型比较的时候需要转换类型,
前端传过来的都是字符串,Date等类型没法直接相比较,需要转成Date类型
Args:
cls (class): Model class
field (str): Model class field
value (str): value need to compare
"""
field_type = getattr(cls, field).type
if isinstance(field_type, Date):
return date_str_to_obj(value)
elif isinstance(field_type, DateTime):
return datetime_str_to_obj(value)
else:
return value
binary_expression_list = []
for field, op_dict in list(filter_name_dict.items()):
for op, op_val in list(op_dict.items()):
op_val = _change_type(cls, field, op_val)
if op in OPERATOR_FUNC_DICT:
binary_expression_list.append(
OPERATOR_FUNC_DICT[op](cls, field, op_val)
)
return binary_expression_list