码农的世界程序员Weed3 ORM框架专题

weed3-4.1.查询之输出

2019-10-11  本文已影响0人  草编椅

Weed3 一个超轻量级ORM框架(只有90kb不到哦)

源码:https://github.com/noear/weed3

查询可是个复杂的话题了。。。
今天先讲讲能输出什么?
db.table("user_info").where("user_id<?", 10).count();
db.table("user_info").where("user_id<?", 10).exists();
bool val = db.table("user_info")
             .where("user_id=?", 10)
             .select("sex").getValue(false); //设个默认值为:false
List<String> ary = db.table("user_info")
             .where("user_id=?", 10)
             .select("mobile").getArray("mobile");
Map<String,Object> map = db.table("user_info")
             .where("user_id=?", 10)
             .select("*").getMap(); 
List<Map<String,Object>> list = db.table("user_info")
             .where("user_id>?", 10).limit(20) //限20条记录
             .select("*").getMapList(); 
UserModel m = db.table("user_info")
             .where("user_id=?", 10)
             .select("*").getItem(UserModel.class); 

public class UserModel{
    public String name;
    public String mobile;
    public int sex;
}
List<UserModel> list = db.table("user_info")
             .where("user_id=?", 10)
             .select("*").getList(UserModel.class); 
那还能再输出什么?
public interface IQuery extends ICacheController<IQuery> {
     long getCount() throws SQLException;
     Object getValue() throws SQLException;
     <T> T getValue(T def) throws SQLException;

     Variate getVariate() throws SQLException;
     Variate getVariate(Act2<CacheUsing,Variate> cacheCondition) throws SQLException;

     <T extends IBinder> T getItem(T model) throws SQLException;
     <T extends IBinder> T getItem(T model, Act2<CacheUsing, T> cacheCondition) throws SQLException;


     <T extends IBinder> List<T> getList(T model) throws SQLException;
     <T extends IBinder> List<T> getList(T model, Act2<CacheUsing, List<T>> cacheCondition) throws SQLException;

     <T> T getItem(Class<T> cls) throws SQLException;
     <T> T getItem(Class<T> cls,Act2<CacheUsing, T> cacheCondition) throws SQLException;

     <T> List<T> getList(Class<T> cls) throws SQLException;
     <T> List<T> getList(Class<T> cls,Act2<CacheUsing, List<T>> cacheCondition) throws SQLException;

     DataList getDataList() throws SQLException;
     DataList getDataList(Act2<CacheUsing, DataList> cacheCondition) throws SQLException;
     DataItem getDataItem() throws SQLException;
     DataItem getDataItem(Act2<CacheUsing, DataItem> cacheCondition) throws SQLException;

     List<Map<String,Object>> getMapList() throws SQLException;
     Map<String,Object> getMap() throws SQLException;

     <T> List<T> getArray(String column) throws SQLException;
}

/** 将所有列转为类做为数组的数据(类为:IBinder 子类) */
List<T> toList(T model);
/** 将所有列转为类做为数组的数据 */
List<T> toEntityList(Class<T> cls);
/** 选1列做为MAP的key,并把行数据做为val */
Map<String,Object> toMap(String keyColumn);
/** 选两列做为MAP的数据 */
Map<String,Object> toMap(String keyColumn,String valColumn);
/** 选一列做为SET的数据 */
Set<T> toSet(String column)
/** 选一列做为数组的数据 */
List<T> toArray(String columnName)
/** 选一列做为数组的数据 */
List<T> toArray(int columnIndex)
/** 转为json字符串 */
String toJson();
T value(T def);
double doubleValue(double def);
long longValue(long def);
int intValue(int def);
String stringValue(String def);
下一篇:4.2.查询之条件
上一篇 下一篇

猜你喜欢

热点阅读