weed3-4.1.查询之输出

作者: 草编椅 | 来源:发表于2019-10-11 21:23 被阅读0次

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

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

查询可是个复杂的话题了。。。
今天先讲讲能输出什么?
  • 1.1.快捷查询数量
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); //设个默认值为:false
  • 2.2.查询输出数组
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); 

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)
             .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,它有很多转换接口:
/** 将所有列转为类做为数组的数据(类为: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();
    1. 其中 getVariate() 返回的是 Variate,也提供了些转换接口
T value(T def);
double doubleValue(double def);
long longValue(long def);
int intValue(int def);
String stringValue(String def);
下一篇:4.2.查询之条件

相关文章

  • weed3-4.1.查询之输出

    Weed3 一个超轻量级ORM框架(只有90kb不到哦) 源码:https://github.com/noear/...

  • [FFmpeg]CMD查询是否包含音视频流信息

    查询音频 输出为0则为无音频,否则则有 查询视频 输出为0则为无视频,否则则有

  • 常用命令

    查询文件find / -name getconf 输出指定匹配内容grep 正则 输出内容 传递输出内容|例如:f...

  • 5.MySQL字符集和权限安全

    字符集--应用显示乱码 1、使用gbk编码,gbk连接,数据插入gbk查询都正常输出,utf8查询正常输出。2、使...

  • 6、oracle之查询

    设置查询输出的格式: 修改查询字段的名字: col col_name heading col_name_new; ...

  • MySQL笔记2

    典型子查询 一个查询的输出是另一个查询的输入,也称为嵌套子查询 5个关键点:1、在查询时基于未知时应考虑使用子查询...

  • mongodb常用查询操作

    javascript操作 打印每一个查询结果 判断输出mongodb查询后的数据中是否存在某key

  • sql多表查询

    普通多表查询 嵌套多表查询 链接多表查询 左链接(会将左表的内容全部输出,没有需要补NULL) 右链接(会将右表的...

  • The University of Amsterdam (ILP

    思路:输入查询item,官方根据狄利克雷模型输出查询结果,从这些查询结果中选取部分(1000个)重新排序,然后返回...

  • 「Mysql索引原理(十三)」索引案例2-避免多个范围条件

    什么是范围条件? 从EXPLAIN的输出很难区分MySQL是要查询范围值,还是查询列表值。 EXPLAIN使...

网友评论

    本文标题:weed3-4.1.查询之输出

    本文链接:https://www.haomeiwen.com/subject/bbwxmctx.html