Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

1619khze/sqlstream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlstream

Simple dsl style sql builder

Status: unfinished

How to use:

Configuration Connection

  public void init() {
    String jdbcUrl = "jdbc:mysql://localhost:3306/orm_test?useSSL=false&useUnicode=true&characterEncoding=utf-8" +
            "&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&transformedBitIsBoolean=true&serverTimezone=Asia/Shanghai";
    this.sqlStream = SQLStreamBuilder.builder()
            .jdbcUrl(jdbcUrl)
            .username("username")
            .password("password")
            .driver("com.mysql.cj.jdbc.Driver")
            .build();
  }

AllEq

  public void testSelectAllEq() {
    Map<TypeFunction<User, ?>, String> params = new HashMap<>();
    params.put(User::getUsername, null);
    List<User> list = sqlStream.select().from(User.class)
            .allEq(params, true)
            .list();
    System.out.println(list);
  }

AllEq By BiPredicate

  public void testSelectAllEqByBiPredicate() {
    Map<TypeFunction<User, ?>, String> params = new HashMap<>();
    params.put(User::getUsername, "xx");

    List<User> list = sqlStream.select().from(User.class)
            .allEq((key, s) -> s.equals("xx1"), params, true)
            .list();
    System.out.println(list);
  }

AllEq By Condition

  public void testSelectAllEqByCondition() {
    Map<TypeFunction<User, ?>, String> params = new HashMap<>();
    params.put(User::getUsername, "xx");

    List<User> list = sqlStream.select().from(User.class)
            .allEq(params.size() == 1, params, true)
            .list();
    System.out.println(list);
  }

AllEq By BiPredicate And Condition

  public void testSelectAllEqByBiPredicateAndCondition() {
    Map<TypeFunction<User, ?>, String> params = new HashMap<>();
    params.put(User::getUsername, "xx");
    List<User> list = sqlStream.select().from(User.class)
            .allEq(params.size() == 1,
                    (key, value) -> value.equals("xx1"), params, true)
            .list();
    System.out.println(list);
  }

Simple Query

  public void testSelectCountField() {
    Long count = sqlStream.select().count("username")
            .from(User.class)
            .eq(User::getUsername, "xx")
            .size();
    System.out.println(count);
  }

  public void testSelectOne() {
    User user = sqlStream.select()
            .from(User.class)
            .eq(User::getUsername, "xx")
            .one();
    System.out.println(user);
  }

  public void testSelectAll() {
    List<User> list = sqlStream.select()
            .from(User.class)
            .list();
    System.out.println(list);
  }

About

⛅ Based on sql2o, refer to the design of mybatis-plus and the chain call style library implemented by api

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages