ratingprocess/Utils/UniqueCoder/MysqlColumnIDUtils.py

11 lines
381 B
Python
Raw Normal View History

2022-11-18 15:11:47 +08:00
from sqlalchemy.orm import Session
def set_next_id(db: Session, num_len: int, prefix: str, model):
data = db.query(model).with_entities(model.id).order_by(model.id.desc()).first()
if data:
num = str(int({**data}.get("id").split(prefix)[-1]) + 1)
return prefix + "0" * (num_len - len(num)) + num
else:
return prefix + "0" * (num_len - 1) + "1"