29 lines
1.5 KiB
Python
29 lines
1.5 KiB
Python
from sqlalchemy import Column, Integer, Text, String, Float, DateTime, func
|
||
from sqlalchemy.ext.declarative import declarative_base
|
||
|
||
# 基础模型基类(如果已有全局 Base 可直接复用)
|
||
ResourceBase = declarative_base()
|
||
|
||
class U3C3(ResourceBase):
|
||
"""对应 sqlite 中的 u3c3 表"""
|
||
__tablename__ = "u3c3" # 表名与原表保持一致
|
||
|
||
# 字段定义(严格映射原表结构)
|
||
id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
|
||
sites = Column(Text, comment="站点名称")
|
||
category = Column(Text, comment="分类")
|
||
title = Column(Text, comment="标题")
|
||
# 关键修改:给 String 加长度(如 512,根据实际链接长度调整)
|
||
url = Column(String(512), unique=True, comment="资源链接(唯一)")
|
||
torrent_url = Column(Text, comment="种子链接")
|
||
magnet_url = Column(Text, comment="磁力链接")
|
||
size_text = Column(Text, comment="大小文本描述")
|
||
size_gb = Column(Float, comment="大小(GB)")
|
||
update_date = Column(Text, comment="更新日期")
|
||
# 补充:MySQL 中建议用 func.now() 替代 func.datetime(...),兼容性更好
|
||
created_at = Column(DateTime, default=func.now(), comment="创建时间(本地时间)")
|
||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间(本地时间)")
|
||
|
||
def __repr__(self):
|
||
"""打印实例时显示的信息"""
|
||
return f"<U3c3(id={self.id}, title='{self.title[:20]}...')>" |