package hf.lskj.com.carstockcount.db;

import java.util.List;

import android.content.Context;

import hf.lskj.com.carstockcount.MyApplication;

public class UserDaoUtils {
    private Context context;
    public UserDao dao;

    public UserDaoUtils(Context context) {
        this.context = context;
        dao = MyApplication.getInstances().getDaoSession().getUserDao();
    }

    public void insert(User User) {
        dao.insertOrReplace(User);
    }

    public void delete(String key) {
        dao.deleteByKey(key);
    }

    public void update(User User) {
        dao.update(User);
    }



    /**
     * 根据Id来查询数据库中个人信息
     */
    public List<User> queryByKey(String key) {
        return dao.queryBuilder().where(UserDao.Properties.LoginId.eq(key)).orderAsc().list();
    }

    /**
     * 查询所有的User
     */
    public List<User> loadAll() {
        return dao.loadAll();
    }

    public User loadCurrent(){
        return dao.queryBuilder().where(UserDao.Properties.Current.eq(1)).unique();
    }
}
