from sqlalchemy import DECIMAL, Index, String, Date, Integer, Text, CHAR, SmallInteger, Float, Time, case, and_, extract, Boolean, Enum, TypeDecorator
# 自定义类型
class DateTimeString(TypeDecorator):
impl = String
def process_bind_param(self, value, dialect):
if value is not None:
return value.strftime('%Y-%m-%d %H:%M:%S.%f')
return value
def process_result_value(self, value, dialect):
if value is not None:
return datetime.strptime(value, '%Y-%m-%d %H:%M:%S.%f')
return value
后续实现orm的时候字段为
localtime: Mapped[datetime] = mapped_column(DateTimeString(), nullable=True)
标签:-%,sqlite,sqlalchemy,return,自定义,value
From: https://www.cnblogs.com/meizhengchao/p/18213145