Skip to content

L-Angel/cave

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cave

统一的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

设计架构

使用

  1. Pom引入
<dependency>
    <groupId>fun.l-angel</groupId>
    <artifactId>cave-sql</actifactId>
</dependency>
  1. 配置扫描路径、配置数据源
@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);
    }
}
  1. 编写签名类
@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);
    }
}

CQL支持的语法

# 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;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published