温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

weed3-2.3.1.查询的输出有哪些

发布时间:2021-09-29 15:59:49 来源:亿速云 阅读:90 作者:iii 栏目:大数据

本篇内容主要讲解“weed3-2.3.1.查询的输出有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“weed3-2.3.1.查询的输出有哪些”吧!

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

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

查询可是个复杂的话题了,可能我们80%的数据库处理都在查询。
今天先讲讲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); 

//用户模型(我统叫它模型)
//这里写了最简单的格式,可以改为bean风格
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,它有一些类型转换接口:

/** 将所有列转为类做为数组的数据(类为: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);

到此,相信大家对“weed3-2.3.1.查询的输出有哪些”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI