统一的SQL数据访问层
- 多异构数据源支持
- 统一化sql查询支持
- sql扩展支持
组件 | 版本 | |
---|---|---|
antlr | 4.10.1 | |
antlr-runtime | 4.10.1 | |
elasticsearch | 7.17.0+ | |
elasticsearch-rest-client | 7.17.0 | |
elasticsearch-rest-high-level-client | 7.17.0 | |
springframework | ||
springboot | optional |
- Pom引入
<dependency>
<groupId>fun.l-angel</groupId>
<artifactId>cave-sql</actifactId>
</dependency>
- 配置扫描路径、配置数据源
@SpringBootApplication
@CaveScan(packages = {"fun.langel.cql.cave"},
datasource = {@DataSource(name = "defaultEs", klass = ElasticSearchDataSource.class, priority = 1)})
public class App {
public static void main(String... args){
SpringApplication.run(App.class, args);
}
}
- 编写签名类
@Cave
public interface CaveDemo {
@Select(sql = "select field1,field2 from index1 where f1 = #{param1}", direct = "defaultEs")
String query(@Param(name = "param1") String param1);
@Select(sql = "select field1,field2 from demo_index where field1 = #{param1}",
direct = "defaultEs",
returnType = Model.class)
List<Model> queryList(@Param(name = "param1") String param1);
}
public class CaveDemo{
static {
System.setProperty("cave.elasticsearch.hosts", "127.0.0.1:9200");
}
@Autowired
private CaveDemo caveDemo;
@Test
public void test_queryEs() {
caveDemo.query("param_abc");
}
@Test
public void test_queryEs_list() {
List<Model> r = caveDemo.queryList("value1");
System.out.println(r);
}
}
# 0.0.1 版本
like
not like
= (equal)
!= (not equal)
> (greater)
< (less)
>= (greater or equals)
<= (less or equals)
and
or
order by
between
is null
is not null
# 0.0.2 版本
count -
avg
- c_exists('colName') ES
- c_script('script'') ES
- c_keyvalue(columnName,'key') #解析key-value,K1:V1;K2:V2;