Skip to content

Latest commit

 

History

History
127 lines (91 loc) · 3.51 KB

README.md

File metadata and controls

127 lines (91 loc) · 3.51 KB

rabbit-sql-spring-boot-starter

License Maven Version

Language: English | 简体中文

Introducing

It's not instead of any ORM framework, no conflict with ORM framework, just a lib.

Spring-boot autoconfigure starter based on rabbit-sql, use spring managed transaction as default, use @Transactional annotation or inject com.github.chengyuxing.sql.spring.autoconfigure.Tx (simple wrapper for spring transaction) to use transaction.

  • support application.yml auto complete;
  • compatible with spring jdbc transaction;
  • compatible with mybatis, spring-data-jpa and so on to use transaction together;

⚠️ don't use rabbit-sql's built-in Tx, use spring transaction instead.

  • com.github.chengyuxing.sql.transaction.Tx
  • com.github.chengyuxing.sql.spring.autoconfigure.Tx ✅

get more usage about rabbit-sql from document

Maven dependency (jdk1.8)

Maven central

<dependency>
    <groupId>com.github.chengyuxing</groupId>
    <artifactId>rabbit-sql-spring-boot-starter</artifactId>
    <version>2.9.7</version>
</dependency>

IDEA plugin support

Plugin marketplace: Rabbit sql and documentation.

Configuration

application.yml (spring.datasource is required):

spring:
  datasource:
    url: jdbc:postgresql://127.0.0.1:5432/postgres
    username: chengyuxing

Inject Baki ready to use:

@Autowired
Baki baki;

Custom configuration

begin with input baki to edit application.yml, a simple example look like:

application.yml

baki:
  xql-file-manager:
    files:
      a: mydir/one.sql
      b: mydir/two.sql

Working with Rabbit sql plugin

  1. Remove the xql-file-manager property from application.yml ;
  2. Sql file extension must rename to xql ;
  3. Create xql-file-manager.yml in resource root .../src/main/resources ;
  4. Configure properties.

simple usage

@SpringBootApplication
public class Startup implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(Startup.class, args);
    }

    @Autowired
    Baki baki;

    @Override
    public void run(String... args) throws Exception {
        try (Stream<DataRow> s = baki.query("&a.region").arg("id", 5).stream()) {
            s.forEach(System.out::println);
        }
    }
}

work with spring transaction:

@Service
public class MyService {

    @Autowired
    Baki baki;

    @Transactional
    public void some() {
        baki.insert("test.tx").save(Args.of("a", 1));
        int i = 1 / 0;    // will be rollback
        baki.insert("test.tx").save(Args.of("a", 2));
    }
}