# sorm
**Repository Path**: parselife/sorm
## Basic Information
- **Project Name**: sorm
- **Description**: ☕ SORM:java开发的一个轻量、简单易用的 `ORM`
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: https://cat-eat-bat.github.io/vjpress/guide/sorm/intro.html
- **GVP Project**: No
## Statistics
- **Stars**: 2
- **Forks**: 0
- **Created**: 2025-06-16
- **Last Updated**: 2025-11-04
## Categories & Tags
**Categories**: Uncategorized
**Tags**: Java, ORM, SpringBoot, postgres, 数据库ORM
## README
# 介绍
**SORM** 是一个轻量、简单易用的关系型数据库 ORM。当你厌烦了 Mybatis(plus) 的 xml 写法以及 JPA 的复杂配置时,你可以试试 `SORM` :yellow_heart: 。
## 特性
- 支持常见数据库
- 支持多数据源
- 支持数据源配置加密
- 支持运行时数据库表自动生成(DDL)
- 支持数据表字段自动生成(DML)
- 框架集成支持 `springboot`、`javalin` 等
- 对空间数据操作支持 `postgis`
- 内置支持两种数据库连接池(`hikari`/`druid`, 可在配置中切换,默认 `hikari`)
## 数据库支持
- Mysql v5.7+
- H2数据库
- PostgresSQL(postgis)
- 达梦数据库(`v8`)
- 人大金仓
- duckdb
- mongodb(`wip`)
## 框架支持
- 支持 SpringBoot 2.x
- 支持 Javalin 4.x
## 使用
本章节将介绍如何使用 `SORM`, 代码可参考工程中的 `sorm-example` 模块
### 1. 引入依赖
```xml
org.winterfell
app-spring-boot-starter
1.4.0-SNAPSHOT
org.winterfell
sorm-spring-boot-starter
1.7.0-SNAPSHOT
com.h2database
h2
2.2.220
```
### 2. 配置数据库连接信息
在 `application.yml` 中配置数据库连接信息:
```yaml{16-27}
server:
port: 8000
spring:
application:
name: sorm-sample
profiles:
active: local
h2:
console:
enabled: true
swagger:
title: Sorm 示例应用
description: 示例应用描述
version: 1.0
sorm:
data-sources:
default:
url: jdbc:h2:~/Data/swap/demo;AUTO_SERVER=true;CASE_INSENSITIVE_IDENTIFIERS=TRUE
username: sa
password:
driver-class-name: org.h2.Driver
settings:
ddl-auto: create_if_not_exist
show-sql: true
entity-packages: org.winterfell.sample.sorm.domain.entity
dev-mode: true
```
### 3. 创建实体类
::: code-group
```java{3} [Student.java]
@Data
@Accessors(chain = true)
@Table
public class Student extends Model {
@Id(autoStrategy = IdAutoStrategy.snow_flake)
private String id;
private String name;
private int age;
private String address;
private String email;
private int deleted;
@Column(definition = "text")
@TypeHandler(JsonTextTypeHandler.class)
private Map attributes;
@Column(updatable = false)
private LocalDateTime createAt;
@Column(insertable = false)
private LocalDateTime updateAt;
}
```
```java [JsonTextTypeHandler.java]
// 用于在 h2 数据库中转换 map 格式字段
public class JsonTextTypeHandler implements FieldTypeHandler