from utils.rdbmsUtil.databaseUtil import sql_operation
from utils.rdbmsUtil.modelUser import User
from sqlalchemy.sql import text
from sqlalchemy.orm import Session


def sqlOfUpdate(name, age):
    return "Update users SET age= :age WHERE name= :name"


class UserOperations:
    @sql_operation("INSERT INTO users (name, age,companyid) VALUES (:name, :age,:companyid) ON CONFLICT (id) DO UPDATE SET name=:name,age = :age,companyid=:companyid", entity_type='user', batch=True)
    def upsert_users(self, session: Session, users):
        pass

    @sql_operation("SELECT * FROM users WHERE name = :name and age= :age",  entity_type='user')
    def get_user(self, session: Session, *,  name, age):  # 使用 * 来强制之后的参数必须为关键字参数
        pass

    @sql_operation(sqlOfUpdate,  entity_type='user')
    def update(self, session: Session, *, name, age):
        pass
