# astrub
**Repository Path**: phaeris/astrub
## Basic Information
- **Project Name**: astrub
- **Description**: 极简代码与配置,实现异构jdbc联合查询框架
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: https://github.com/PhaerisWakfu/astrub
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2023-05-06
- **Last Updated**: 2024-09-09
## Categories & Tags
**Categories**: Uncategorized
**Tags**: calcite, HDMS, 异构数据源
## README
# Astrub
> 极简代码与配置,实现异构jdbc联合查询
## 引入依赖
```xml
com.gitee.phaeris
astrub
${latest.version}
org.springframework.boot
spring-boot-starter-jdbc
mysql
mysql-connector-java
org.postgresql
postgresql
```
## 配置
```yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/ds1?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=GMT%2B8
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
astrub:
# 是否开启自动注册为数据源(如果本身已有数据源可能会导致覆盖的情况)
enabled: false
schemas:
# 第一个schema为默认schema
- name: mysql
driver: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/astrub
user: root
password: root
- name: pg
driver: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/astrub?currentSchema=mySchema
user: postgres
password: 123456
```
## 数据库脚本
### mysql
```mysql
create table address
(
name varchar(200) null comment '名字',
area varchar(20) null
)
charset = utf8;
```
### pg
```postgresql
create table phone
(
name varchar,
phone varchar
);
```
## 查询
```java
import ConnectionHelper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.List;
import java.util.Map;
/**
* @author wyh
* @since 2023/4/24
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class DatasourceTest {
@Autowired
private JdbcTemplate jdbcTemplate;
@Test
void testLocalDatasource() {
String sql = "select * from car";
List