task: add send common mail task
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 11s
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 11s
This commit is contained in:
32
database/tcontent/crud.py
Normal file
32
database/tcontent/crud.py
Normal file
@ -0,0 +1,32 @@
|
||||
from database.tcontent.model import TContent
|
||||
|
||||
def create_content(db, content: TContent):
|
||||
db.add(content)
|
||||
db.commit()
|
||||
db.refresh(content)
|
||||
return content
|
||||
|
||||
def get_content_by_id(db, content_id: int):
|
||||
return db.query(TContent).filter(TContent.id == content_id).first()
|
||||
|
||||
def update_content(db, content_id: int, updates: dict):
|
||||
content = db.query(TContent).filter(TContent.id == content_id).first()
|
||||
if content:
|
||||
for key, value in updates.items():
|
||||
setattr(content, key, value)
|
||||
db.commit()
|
||||
db.refresh(content)
|
||||
return content
|
||||
|
||||
def delete_content(db, content_id: int):
|
||||
content = db.query(TContent).filter(TContent.id == content_id).first()
|
||||
if content:
|
||||
db.delete(content)
|
||||
db.commit()
|
||||
return content
|
||||
|
||||
def drop_table(db):
|
||||
TContent.__table__.drop(db.get_bind(), checkfirst=True)
|
||||
|
||||
def create_table(db):
|
||||
TContent.__table__.create(db.get_bind(), checkfirst=True)
|
||||
15
database/tcontent/debug.py
Normal file
15
database/tcontent/debug.py
Normal file
@ -0,0 +1,15 @@
|
||||
import database.tcontent.model
|
||||
from database.database import get_session, create_tables
|
||||
from database.tcontent.crud import drop_table, get_content_by_id
|
||||
|
||||
|
||||
|
||||
# create_tables()
|
||||
|
||||
# with get_session() as db:
|
||||
# task = get_content_by_id(db, 1)
|
||||
# print(task)
|
||||
# print(task.id)
|
||||
|
||||
with get_session() as db:
|
||||
drop_table(db)
|
||||
12
database/tcontent/model.py
Normal file
12
database/tcontent/model.py
Normal file
@ -0,0 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, DateTime, func
|
||||
from database.database import Base
|
||||
|
||||
class TContent(Base):
|
||||
__tablename__ = 't_content'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True, comment='自动递增的唯一内容ID')
|
||||
project = Column(String(64), nullable=False, comment='项目名称', index=True)
|
||||
subject = Column(String(256), nullable=False, comment='主题')
|
||||
content = Column(Text, nullable=True, comment='内容')
|
||||
create_time = Column(DateTime, server_default=func.now(), nullable=False, comment='创建时间')
|
||||
update_time = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False, comment='更新时间')
|
||||
Reference in New Issue
Block a user