import peter
This commit is contained in:
0
database/tinformationsource/__init__.py
Normal file
0
database/tinformationsource/__init__.py
Normal file
BIN
database/tinformationsource/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
database/tinformationsource/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
database/tinformationsource/__pycache__/curd.cpython-312.pyc
Normal file
BIN
database/tinformationsource/__pycache__/curd.cpython-312.pyc
Normal file
Binary file not shown.
BIN
database/tinformationsource/__pycache__/model.cpython-312.pyc
Normal file
BIN
database/tinformationsource/__pycache__/model.cpython-312.pyc
Normal file
Binary file not shown.
31
database/tinformationsource/curd.py
Normal file
31
database/tinformationsource/curd.py
Normal file
@ -0,0 +1,31 @@
|
||||
from database.tinformationsource.model import TInformationSource
|
||||
|
||||
|
||||
def create_information_source(db, information_source: TInformationSource):
|
||||
db.add(information_source)
|
||||
db.commit()
|
||||
db.refresh(information_source)
|
||||
return information_source
|
||||
|
||||
def get_information_source_by_id(db, information_source_id: int):
|
||||
return db.query(TInformationSource).filter(TInformationSource.id == information_source_id).first()
|
||||
|
||||
def get_active_information_sources(db) -> list:
|
||||
return db.query(TInformationSource).filter(TInformationSource.active == True).all()
|
||||
|
||||
def update_information_source(db, information_source_id: int, updates: dict):
|
||||
update_information = db.query(TInformationSource).filter(TInformationSource.id == information_source_id).first()
|
||||
if update_information:
|
||||
for key, value in updates.items():
|
||||
setattr(update_information, key, value)
|
||||
db.commit()
|
||||
db.refresh(update_information)
|
||||
return update_information
|
||||
|
||||
|
||||
def delete_update_information(db, information_source_id: int):
|
||||
update_information = db.query(TInformationSource).filter(TInformationSource.id == information_source_id).first()
|
||||
if update_information:
|
||||
db.delete(update_information)
|
||||
db.commit()
|
||||
return update_information
|
||||
34
database/tinformationsource/model.py
Normal file
34
database/tinformationsource/model.py
Normal file
@ -0,0 +1,34 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from sqlalchemy import Column, String, Boolean, TIMESTAMP, func, INT
|
||||
from sqlalchemy.dialects.postgresql import BIGINT
|
||||
|
||||
from database.database import Base
|
||||
|
||||
|
||||
@dataclass
|
||||
class TInformationSource(Base):
|
||||
__tablename__ = 't_information_source'
|
||||
|
||||
id: int = Column(BIGINT, primary_key=True, autoincrement=True, comment='编号')
|
||||
title: str = Column(String, nullable=False, comment='标题')
|
||||
description: str = Column(String, nullable=True, comment='描述')
|
||||
keywords: str = Column(String, nullable=True, comment='关键字')
|
||||
url: str = Column(String, nullable=True, comment='网站链接')
|
||||
rss: str = Column(String, nullable=True, comment='RSS链接')
|
||||
api: str = Column(String, nullable=True, comment='API')
|
||||
primary_category: str = Column(String, nullable=True, comment='一级类别')
|
||||
secondary_category: str = Column(String, nullable=True, comment='二级类别')
|
||||
tertiary_category: str = Column(String, nullable=True, comment='三级类别')
|
||||
label: str = Column(String, nullable=True, comment='标签')
|
||||
lang: str = Column(String, nullable=False, default='zh', comment='语言')
|
||||
priority: int = Column(INT, nullable=False, default=100, comment='优先级')
|
||||
active: bool = Column(Boolean, default=False, nullable=False, comment='是否启用:false未启用,true启用')
|
||||
module: str = Column(String, nullable=True, comment='任务逻辑所在模块名称')
|
||||
method: str = Column(String, nullable=True, comment='任务逻辑的函数名称')
|
||||
create_time: str = Column(TIMESTAMP(timezone=True), server_default=func.now(), nullable=False, comment='创建时间')
|
||||
update_time: str = Column(TIMESTAMP(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False, comment='更新时间')
|
||||
is_static: bool = Column(Boolean, default=True, nullable=False, comment='是否是静态网站:false动态,true静态')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<TInformationSource(id={self.id}, title={self.title}, category={self.category}, active={self.active})>"
|
||||
Reference in New Issue
Block a user