# ngbatis
**Repository Path**: CorvusYe/ngbatis
## Basic Information
- **Project Name**: ngbatis
- **Description**: NGBATIS 是一款针对 Nebula Graph + Springboot 的数据库 ORM 框架。借鉴于 MyBatis 的使用习惯进行开发。具备部分MyBatis-plus的CRUD特性
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: http://corvusye.gitee.io/ngbatis-docs/#/
- **GVP Project**: No
## Statistics
- **Stars**: 40
- **Forks**: 10
- **Created**: 2022-06-11
- **Last Updated**: 2025-05-23
## Categories & Tags
**Categories**: database-dev
**Tags**: None
## README
# NgBatis
English | 中文
- [NgBatis Docs](https://nebula-contrib.github.io/ngbatis/)
- [NgBatis 文档](https://graph-cn.github.io/ngbatis-docs/)
## NGBATIS是什么?
**NgBatis** 是一款针对 [Nebula Graph](https://github.com/vesoft-inc/nebula) + Springboot 的数据库 ORM 框架。借鉴于 [MyBatis](https://github.com/mybatis/mybatis-3) 的使用习惯进行开发。包含了一些类似于[mybatis-plus](https://github.com/baomidou/mybatis-plus)的单表操作,另外还有一些图特有的实体-关系基本操作。
如果使用上更习惯于JPA的方式,[graph-ocean](https://github.com/nebula-contrib/graph-ocean) 是个不错的选择。
## NgBatis 是怎么运行的?
请看设计文档 [EXECUTION-PROCESS.md](./EXECUTION-PROCESS.md)
## 项目要求
- Springboot
- Maven
- Java 8+
## 版本匹配
NgBatis | nebula-java | JDK | Springboot | Beetl
---|-------------|---|------------|---
1.3.0 | 3.8.3 | 8 | 2.7.0 | 3.15.10.RELEASE
1.3.0-jdk17 | 3.8.3 | 17 | 3.0.7 | 3.15.10.RELEASE
1.2.2 | 3.6.0 | 8 | 2.7.0 | 3.15.10.RELEASE
1.2.2-jdk17 | 3.6.0 | 17 | 3.0.7 | 3.15.10.RELEASE
1.2.1 | 3.6.0 | 8 | 2.7.0 | 3.15.10.RELEASE
1.2.0-jdk17 | 3.6.0 | 17 | 3.0.7 | 3.15.10.RELEASE
1.2.0 | 3.6.0 | 8 | 2.7.0 | 3.15.10.RELEASE
1.1.5 | 3.5.0 | 8 | 2.7.0 | 3.1.8.RELEASE
1.1.4 | 3.5.0 | 8 | 2.7.0 | 3.1.8.RELEASE
1.1.3 | 3.5.0 | 8 | 2.7.0 | 3.1.8.RELEASE
1.1.2 | 3.4.0 | 8 | 2.7.0 | 3.1.8.RELEASE
### 快照版
NgBatis | nebula-java | JDK | Springboot | Beetl
---|-------------|---|------------|---
1.2.2-jdk17-SNAPSHOT | 3.6.0 | 17 | 3.0.7 | 3.15.10.RELEASE
1.2.2-SNAPSHOT | 3.6.0 | 8 | 2.7.0 | 3.15.10.RELEASE
> 在同版本号快照版中,依赖的第三方可能会随时升级
## 如何使用(可在克隆代码后,参考 ngbatis-demo 项目)
### 在项目引入
- Maven
```xml
org.nebula-contrib
ngbatis
1.3.0
```
- Gradle
```groovy
implementation 'org.nebula-contrib:ngbatis:1.3.0'
```
### 参考 [【ngbatis-demo】](./ngbatis-demo),与springboot无缝集成。在该项目的 test 中还有api的样例。在开发过程中每增加一个特性也都会同步更新ngbatis-demo的用例
### 配置数据库
在 application.yml 中添加配置 **将数据源修改成可访问到的NebulaGraph**
```yml
nebula:
ngbatis:
session-life-length: 300000 # since v1.1.2
check-fixed-rate: 300000 # since v1.1.2
# `use-session-pool` 默认是 false,如开启,则 space 是必须指定的
# space除了使用当前文件的声明意外,还可以使用:(@Space) or xml(space="test")
use-session-pool: false # since v1.1.2
hosts: 127.0.0.1:19669, 127.0.0.1:9669
username: root
password: nebula
space: test
pool-config:
min-conns-size: 0
max-conns-size: 10
timeout: 0
idle-time: 0
interval-idle: -1
wait-time: 0
min-cluster-health-rate: 1.0
enable-ssl: false
```
### 扫描动态代理的 bean
```java
@SpringBootApplication(scanBasePackages = { "org.nebula", "your.domain"})
public class YourApplication {
public static void main(String[] args) {
new SpringApplication(YourApplication.class).run(args);
}
}
```
> 如果项目中使用的是 SpringCloud,
> 请使用`@ComponentScan( basePackages = {"org.nebula.contrib", "your.domain"} )`
## 日常开发示例
### 自己编写 nGQL (MyBatis的思路)
#### 声明数据访问接口
```java
package ye.weicheng.ngbatis.demo.repository;
import ye.weicheng.ngbatis.demo.pojo.Person;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface TestRepository {
// new features from v1.2.0
Integer returnAge(@Param("person")Person person);
Person selectPerson();
Person selectByPerson(Person person);
List selectAgeGt(Integer age);
List selectListString();
List