weed3-2.3.1.查詢之輸出

Weed3 一個微型ORM框架(只有0.1Mb哦)

源碼:https://github.com/noear/weed3
源碼:https://gitee.com/noear/weed3

查詢可是個復(fù)雜的話題了,可能我們80%的數(shù)據(jù)庫處理都在查詢。
今天先講講weed3的查詢能輸出什么?
  • 1.1.快捷查詢數(shù)量
db.table("user_info").where("user_id<?", 10).count();
  • 1.2.快捷查詢是否存在
db.table("user_info").where("user_id<?", 10).exists();
  • 2.1.查詢一行的一個字段,輸出單值
bool val = db.table("user_info")
             .where("user_id=?", 10)
             .select("sex").getValue(false); //設(shè)個默認值為:false
  • 2.2.查詢多行的一個字段,輸出數(shù)組
List<String> ary = db.table("user_info")
             .where("user_id=?", 10)
             .select("mobile").getArray("mobile");
  • 3.1.查詢一行,輸出map
Map<String,Object> map = db.table("user_info")
             .where("user_id=?", 10)
             .select("*").getMap(); 
  • 3.2.查詢多行,輸出map list
List<Map<String,Object>> list = db.table("user_info")
             .where("user_id>?", 10).limit(20) //限20條記錄
             .select("*").getMapList(); 
  • 4.1.查詢一行,輸出entity
UserModel m = db.table("user_info")
             .where("user_id=?", 10)
             .select("*").getItem(UserModel.class); 

//用戶模型(我統(tǒng)叫它模型)
//這里寫了最簡單的格式,可以改為bean風(fēng)格
public class UserModel{
    public String name;
    public String mobile;
    public int sex;
}
  • 4.2.查詢多行,輸出entity list
List<UserModel> list = db.table("user_info")
             .where("user_id>?", 10).limit(0,20) //分頁取20行
             .select("*").getList(UserModel.class); 
那還能再輸出什么?
  • 1.select("...") 返回的是一個:IQuery
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;
}

  • 2.其中 getDataList() 返加的是 DataList,它有一些類型轉(zhuǎn)換接口:
/** 將所有列轉(zhuǎn)為類做為數(shù)組的數(shù)據(jù)(類為:IBinder 子類) */
List<T> toList(T model);
/** 將所有列轉(zhuǎn)為類做為數(shù)組的數(shù)據(jù) */
List<T> toEntityList(Class<T> cls);
/** 選1列做為MAP的key,并把行數(shù)據(jù)做為val */
Map<String,Object> toMap(String keyColumn);
/** 選兩列做為MAP的數(shù)據(jù) */
Map<String,Object> toMap(String keyColumn,String valColumn);
/** 選一列做為SET的數(shù)據(jù) */
Set<T> toSet(String column)
/** 選一列做為數(shù)組的數(shù)據(jù) */
List<T> toArray(String columnName)
/** 選一列做為數(shù)組的數(shù)據(jù) */
List<T> toArray(int columnIndex)
/** 轉(zhuǎn)為json字符串 */
String toJson();
    1. 其中 getVariate() 返回的是 Variate,也提供了些轉(zhuǎn)換接口
T value(T def);
double doubleValue(double def);
long longValue(long def);
int intValue(int def);
String stringValue(String def);
下一篇:2.3.2.查詢之條件
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴謹 對...
    cosWriter閱讀 11,665評論 1 32
  • 一. Java基礎(chǔ)部分.................................................
    wy_sure閱讀 4,012評論 0 11
  • 一、基礎(chǔ)知識:1、JVM、JRE和JDK的區(qū)別:JVM(Java Virtual Machine):java虛擬機...
    殺小賊閱讀 2,565評論 0 4
  • width: 65%;border: 1px solid #ddd;outline: 1300px solid #...
    邵勝奧閱讀 5,172評論 0 1
  • 在執(zhí)行adb命令時,有時候會報錯:Permission denied 這是由于非admin用戶對該文件夾操作權(quán)限不...
    BestFei閱讀 8,725評論 0 1

友情鏈接更多精彩內(nèi)容