# Linq.J A Memory-based Object Query language
[中文](./README-zh.md) / English
`Java uses Linq capabilities similar to C#` [C# Linq](https://learn.microsoft.com/zh-cn/dotnet/csharp/linq/)
<p>
<a href="https://www.erupt.xyz" target="_blank"><img src="https://img.shields.io/badge/Linq.J-brightgreen" alt="Erupt Framework"></a>
<a href="https://mvnrepository.com/search?q=linq.j"><img src="https://img.shields.io/maven-central/v/xyz.erupt/linq.j" alt="maven-central"></a>
<a href="https://www.oracle.com/technetwork/java/javase/downloads/index.html"><img src="https://img.shields.io/badge/JDK-8+-green.svg" alt="jdk 8+"></a>
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="license Apache 2.0"></a>
<a href='https://gitee.com/erupt/linq/stargazers'><img src='https://gitee.com/erupt/linq/badge/star.svg?theme=gray' alt='GitEE star' ></img></a>
<a href="https://github.com/erupts/linq.j"><img src="https://img.shields.io/github/stars/erupts/linq.j?style=social" alt="GitHub stars"></a>
</p>
### Linq is Object oriented sql, linq is actually a query on the data in memory, enabling developers to write queries more easily. These query expressions look a lot like SQL
> You can join, filter, sort, and group data sources with minimal code. These operations can be combined in a single query to obtain more complex results
#### allows you to write Java code that manipulates in-memory data in the same way that you query a database, for example
- List, Array
- SQL result data
- CSV, XML, JSON document datasets
- Stream, File stream
#### Application Scenarios
- Result association for RPCS such as Feign/Dubbo during distributed development
- In-memory computation of heterogeneous system data
- Use code to organize SQL result data
- Sorted aggregation of multiple result objects with in-memory paging
- Semantic object transformation and mapping
- Clean code, no need for loops and branches to manipulate data
- Federated access across data sources
#### Operation syntax
`From` `Select` `Distinct`、`Join`、`Where`、`Group By`、`Order By`、`Limit`、`Offset`、`...`
#### Tips
⚠️ Note: The object field must have a get method to facilitate lambda lookup. It is recommended to use the **Lombok** @Getter annotation to quickly create get access to the field
#### How to Use
It has zero external dependencies and is only 50kb in size
```xml
<dependency>
<groupId>xyz.erupt</groupId>
<artifactId>linq.j</artifactId>
<version>0.0.5</version>
</dependency>
```
#### Example 1
```javascript
var strings = Linq.from("C", "A", "B", "B").gt(Th::is, "A").orderByDesc(Th::is).write(String.class);
// [C, B, B]
var integers = Linq.from(1, 2, 3, 7, 6, 5).orderBy(Th::is).write(Integer.class);
// [1, 2, 3, 5, 6, 7]
var name = Linq.from(data)
// left join
.innerJoin(target, Target::getId, Data::getId)
// where like
.like(Data::getName, "a")
// select name
.select(Data::getName)
// distinct
.distinct()
// order by
.orderBy(Data::getName)
.write(String.class);
```
#### Example 2
```java
public class ObjectQuery{
private final List<TestSource> source = http.get("https://gw.alipayobjects.com/os/antfincdn/v6MvZBUBsQ/column-data.json");
private final List<TestSourceExt> target = mongodb.query("db.target.find()");
/**
* select demo
*/
public void select(){
// select *
Linq.from(source).select(TestSource.class);
// select a, b, c
Linq.from(source)
.select(TestSource::getName, TestSource::getDate, TestSource::getTags)
.select(TestSource::getTags, "tag2") // alias
.select(Columns.ofx(TestSource::getId, id -> id + "xxx")); // value convert
// select count(*), sum(id), max(id)
Linq.from(source)
.select(Columns.count("count"))
.select(Columns.sum(TestSource::getId, "sum"))
.select(Columns.max(TestSource::getId, "max"));
}
/**
* join demo
*/
public void join(){
// left join
Linq.from(source).leftJoin(target, TestSourceExt::getId, TestSource::getId)
.select(TestSource.class)
.select(TestSourceExt::getName)
.select(TestSourceExt2::getValue);
// right join
Linq.from(source).rightJoin(target, TestSourceExt::getId, TestSource::getId);
// inner join
Linq.from(source).innerJoin(target, TestSourceExt::getId, TestSource::getId);
// full join
Linq.from(source).fullJoin(target, TestSourceExt::getId, TestSource::getId);
}
/**
* where demo
*/
public void where() {
// =
Linq.from(source).eq(TestSource::getName, "Thanos").select(Columns.count(countAlias)).writeOne(Integer.class);
// >=:lval and <=:rval
Linq.from(source).between(TestSource::getId, 1, 3);
// in (x,x,x)
Linq.from(source).in(TestSource::getId, 1, 2, 3);
// like '%x%'
Linq.from(source).like(TestSource::getName, "a");
// is null
Linq.from(source).isNull(TestSource::getId);
// customer single field where
Linq.from(source).where(TestSource::getId, id -> id >= 5);
// customer condition or multi field
Linq.from(source).where(data -> {
String name = data.get(TestSource::getName);
Integer age = (Integer)data.get(TestSource::getAge);
// name = 'xxx' or age > 10
return "xxx".equals(name) || age > 10;
});
}
/**
* group by demo
*/
public void groupBy(){
Linq.from(source)
.groupBy(TestSource::getName)
.select(
Columns.of(TestSource::getName, "name"),
Columns.min(TestSource::getDate, "min"),
Columns.avg(TestSource::getId, "avg"),
Columns.count("count"),
Columns.count(TestSource::getName, "countName"),
Columns.countDistinct(TestSource::getName, "countDistinct")
)
.having(row -> Integer.parseInt(row.get("avg").toString()) > 2)
.orderBy(TestSource::getAge);
}
/**
* result write demo
*/
public void write(){
// write List<Object>
List<TestSource> list = Linq.from(source).orderByAsc(TestSource::getDate).write(TestSource.class);
// write Object
TestSource obj = Linq.from(source).limit(3).writeOne(TestSource.class);
// write List<Map>
List<Map<String, Object>> map = Linq.from(source).writeMap();
// write Map
Map<String, Object> mapOne = Linq.from(source).writeMapOne();
}
}
```
#### Next iteration plan
- [ ] Supports combining multiple query result sets: UNION ALL, UNION, INTERSECT, EXCEPT, UNION BY NAME
- [ ] Supports window functions
- [ ] Support Nested loop join
- [x] supports having
- [x] Support group column format group by date(created_at)
没有合适的资源?快使用搜索试试~ 我知道了~
2024最新版python中j-pythonj基础笔记
共54个文件
java:48个
md:2个
gitignore:1个
需积分: 1 0 下载量 133 浏览量
2024-09-14
13:25:27
上传
评论
收藏 377KB ZIP 举报
温馨提示
2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中j_pythonj基础笔记2024最新版python中
资源推荐
资源详情
资源评论
收起资源包目录
56 (3).zip (54个子文件)
linq-main
pom.xml 6KB
src
test
resources
CustomerChurnModelDataSet.json 2.42MB
java
xyz
erupt
linq
LambdaTest.java 1KB
PerformanceTest.java 1KB
LinqTest.java 14KB
data
TestTo.java 380B
source
TestSourceParent.java 266B
TestSourceExt.java 476B
TestSourceGroupByVo.java 1KB
TestSource.java 855B
TestSourceExt2.java 488B
customer
CustomerChurnModel.java 3KB
CustomerInfo.java 619B
student
StudentSubject.java 467B
StudentVo.java 830B
StudentScore.java 1KB
StudentScoreAnalysis.java 1KB
Student.java 1015B
BaseModel.java 264B
DatasetStudentTest.java 5KB
DatasetCustomerTest.java 2KB
main
java
xyz
erupt
linq
lambda
SFunction.java 193B
LambdaInfo.java 509B
Th.java 143B
LambdaSee.java 3KB
consts
JoinExchange.java 90B
JoinMethod.java 102B
CompareSymbol.java 97B
OrderByDirection.java 85B
schema
Column.java 2KB
OrderBySchema.java 682B
WhereSchema.java 734B
JoinSchema.java 2KB
Row.java 1KB
Dql.java 2KB
engine
EruptEngine.java 8KB
Engine.java 1KB
exception
LinqException.java 238B
grammar
OrderBy.java 972B
Join.java 1KB
Write.java 2KB
GroupBy.java 659B
Select.java 1KB
Where.java 3KB
util
CompareUtil.java 815B
RowUtil.java 5KB
Columns.java 7KB
VirtualColumn.java 628B
ReflectField.java 1KB
Linq.java 7KB
LICENSE 1KB
.gitignore 394B
README.md 7KB
README-zh.md 7KB
共 54 条
- 1
资源评论
脚步的影子
- 粉丝: 2045
- 资源: 186
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功