### SQLToy Quickstart Application Entry Point
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/README.md
The main application class for the SQLToy quickstart project. It enables Spring Boot auto-configuration, component scanning, and transaction management.
```java
package com.sqltoy.quickstart;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
*
* @project sqltoy-quickstart
* @description quickstart 主程序入口
* @author zhongxuchen
* @version v1.0, Date:2020年7月17日
* @modify 2020年7月17日,修改说明
*/
@SpringBootApplication
@ComponentScan(basePackages = { "com.sqltoy.config", "com.sqltoy.quickstart" })
@EnableTransactionManagement
public class SqlToyApplication {
/**
* @param args
*/
public static void main(String[] args) {
SpringApplication.run(SqlToyApplication.class, args);
}
}
```
--------------------------------
### Database Sharding SQL Example
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/README.md
Demonstrates SQL configuration for database sharding using a hash strategy based on userId. Ensure userId is provided for correct routing.
```xml
=:beginDate]
#[and t.log_date<=:endDate]
]]>
```
--------------------------------
### SQLToy Configuration in application.properties
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/README.md
Example properties for configuring SQLToy within a Spring Boot application. Includes settings for SQL resource directories, translation configuration, and debugging.
```properties
# sqltoy config
spring.sqltoy.sqlResourcesDir=classpath:com/sqltoy/quickstart
spring.sqltoy.translateConfig=classpath:sqltoy-translate.xml
spring.sqltoy.debug=true
#spring.sqltoy.reservedWords=status,sex_type
#dataSourceSelector: org.sagacity.sqltoy.plugins.datasource.impl.DefaultDataSourceSelector
#spring.sqltoy.defaultDataSource=dataSource
spring.sqltoy.unifyFieldsHandler=com.sqltoy.plugins.SqlToyUnifyFieldsHandler
#spring.sqltoy.printSqlTimeoutMillis=200000
```
--------------------------------
### Table Sharding SQL Example
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/README.md
Shows SQL configuration for table sharding using a real-time historical table strategy based on beginDate. The table name 'sqltoy_trans_info_15d' is a placeholder for dynamic table routing.
```xml
=:beginDate
#[and t.trans_date<=:endDate]
]]>
```
--------------------------------
### SQLToy Mapper - Paginated User Query
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of performing a paginated query for UserVo objects using the 'userList' SQL ID and providing a Page object for pagination parameters.
```java
// 也可分页
@Sql("userList")
Page pageUser(UserVo query,Page page);
```
--------------------------------
### SQLToy Mapper - Default Method Example
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Demonstrates a default method in a mapper interface. Default methods are not processed by SQLToy and are called directly. They can be used to invoke other mapper methods or business logic.
```java
//default 方法不处理,直接调用,可在default方法中调用本接口方法处理一些业务
default long doSomeThingElse(){
// Aop.get(XX.class) 获取其他bean来处理业务
//dao().xxx 或通过SqlToyLazyDao来处理其他业务
return count()+1;
}
```
--------------------------------
### SQLToy Mapper - Delete User Operation by Username
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of using a SQLToy mapper to delete a user by providing the username directly as a parameter.
```java
@Sql("DELETE FROM T_USER WHERE USER_NAME=:username")
long deleteUser1(String username);
```
--------------------------------
### SQLToy Mapper - Query User List by Method Name
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of a SQLToy mapper interface method where the SQL ID is inferred from the method name ('userList').
```java
//不用@Sql注解的时候,就匹配方法名(userList)
List userList(String username);
```
--------------------------------
### Generated OrderInfo Entity Class
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
Example of an OrderInfo entity class generated by the QuickVO plugin. It includes JPA annotations for database mapping and Lombok annotations for concise code.
```java
@Data
@Accessors(chain = true)
@Entity(tableName="sqltoy_order_info",comment="sqltoy订单信息演示表",pk_constraint="PRIMARY")
public class OrderInfo implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7200696852961513069L;
/*---begin-auto-generate-don't-update-this-area--*/
/**
* 订单编号
*/
@Id(strategy="generator",generator="org.sagacity.sqltoy.plugins.id.impl.NanoTimeIdGenerator")
@Column(name="ORDER_ID",comment="订单编号",length=32L,type=java.sql.Types.VARCHAR,nativeType="VARCHAR",nullable=false)
private String orderId;
/**
* 订单类别
*/
@Column(name="ORDER_TYPE",comment="订单类别",length=32L,type=java.sql.Types.VARCHAR,nativeType="VARCHAR",nullable=true)
private String orderType;
/**
* 商品代码
*/
@Column(name="PRODUCT_CODE",comment="商品代码",length=32L,type=java.sql.Types.VARCHAR,nativeType="VARCHAR",nullable=true)
private String productCode;
/**
* 计量单位
*/
@Column(name="UOM",comment="计量单位",length=30L,type=java.sql.Types.VARCHAR,nativeType="VARCHAR",nullable=true)
private String uom;
/**
* 价格
*/
@Column(name="PRICE",comment="价格",length=24L,scale=6,type=java.sql.Types.DECIMAL,nativeType="DECIMAL",nullable=true)
private BigDecimal price;
/**
* 数量
*/
@Column(name="QUANTITY",comment="数量",length=24L,scale=6,type=java.sql.Types.DECIMAL,nativeType="DECIMAL",nullable=true)
private BigDecimal quantity;
/**
* 订单总金额
*/
@Column(name="TOTAL_AMT",comment="订单总金额",length=24L,scale=6,type=java.sql.Types.DECIMAL,nativeType="DECIMAL",nullable=true)
private BigDecimal totalAmt;
/**
* 销售员
*/
@Column(name="STAFF_CODE",comment="销售员",length=32L,type=java.sql.Types.VARCHAR,nativeType="VARCHAR",nullable=true)
private String staffCode;
/**
* 销售部门
*/
@Column(name="ORGAN_ID",comment="销售部门",length=32L,type=java.sql.Types.VARCHAR,nativeType="VARCHAR",nullable=true)
private String organId;
/**
* 订单状态
*/
@Column(name="STATUS",comment="订单状态",length=10L,type=java.sql.Types.INTEGER,nativeType="INT",nullable=true)
private Integer status;
/**
* 创建人
*/
@Column(name="CREATE_BY",comment="创建人",length=32L,type=java.sql.Types.VARCHAR,nativeType="VARCHAR",nullable=true)
private String createBy;
/**
* 创建时间
*/
@Column(name="CREATE_TIME",comment="创建时间",length=19L,type=java.sql.Types.DATE,nativeType="DATETIME",nullable=true)
private LocalDateTime createTime;
/**
* 更新人
*/
@Column(name="UPDATE_BY",comment="更新人",length=32L,type=java.sql.Types.VARCHAR,nativeType="VARCHAR",nullable=true)
private String updateBy;
/**
* 更新时间
*/
@Column(name="UPDATE_TIME",comment="更新时间",length=19L,type=java.sql.Types.DATE,nativeType="DATETIME",nullable=true)
private LocalDateTime updateTime;
/** default constructor */
public OrderInfo() {
}
/** pk constructor */
public OrderInfo(String orderId)
{
this.orderId=orderId;
}
/*---end-auto-generate-don't-update-this-area--*/
}
```
--------------------------------
### SQLToy Mapper - Accessing SqlToyLazyDao
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of a mapper method that returns an instance of SqlToyLazyDao, allowing direct access to default DAO operations within the mapper interface.
```java
/**
* 返回值为SqlToyLazyDao的方法可获取默认的dao
* @return
*/
SqlToyLazyDao dao();
```
--------------------------------
### MyBatis Equivalent Query with Dynamic Where Clause
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/README.md
Demonstrates how the same dynamic filtering logic as SQLToy's XML example is implemented in MyBatis using and tags within a clause.
```xml
```
--------------------------------
### Solon Service with Injected SQLToy Components
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of a Solon service class demonstrating injection of SqlToyLazyDao and DemoMapper using the @Db annotation. Supports injecting multiple data sources by specifying the bean name.
```java
import org.noear.solon.extend.sqltoy.annotation.Db;
//应用
@ProxyComponent
public class AppService{
@Db
private SqlToyLazyDao sqlToyLazyDao;
@Db("tow")//多数据源
private SqlToyLazyDao sqlToyLazyDao2;
@Db
private DemoMapper demoMapper;
@Db("tow")//Mapper 使用多数据
private DemoMapper demoMapper2;
//@Tran 使用Transaction
public void test(){
demoMapper.doSomeThingElse();
sqlToyLazyDao.save(entity);
//其他dao操作
}
}
```
--------------------------------
### SQLToy Mapper - Delete User Operation by User Object
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of using a SQLToy mapper to delete a user based on a User object. The SQL uses named parameters from the object.
```java
@Sql("DELETE FROM T_USER WHERE USER_NAME=:username")
long deleteUser(User user);
```
--------------------------------
### SQLToy Mapper - Update User Operation
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of using a SQLToy mapper to update an existing user. This method returns the number of affected rows.
```java
@Sql("UPDATE T_USER set gender=:gender where USER_NAME=:username")
long updateUser(User user);
```
--------------------------------
### SQLToy Mapper - Query User List with Entity Parameter
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of querying a list of UserVo objects using an entity (UserVo) as a query parameter. Parameters within the SQL can be accessed using dot notation (e.g., ':query.username').
```java
// 可查list,可以直接用Map或entity 做查询参数
@Sql("SELECT * FROM T_USER WHERE WHERE USER_NAME=:username #[and GENDER=:gender]")
List queryUser(UserVo query);
```
--------------------------------
### SQLToy Mapper - Query Single Value (Count)
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of querying a single value, such as a count, from the database. Ensure the return type matches the database value type.
```java
//可查询单值,这里要注意返回值,需要和数据库中值类型对应
@Sql("select count(*) from t_user")
Long count();
```
--------------------------------
### SQLToy Mapper - Query User with Named Parameters
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of a SQLToy mapper interface method using a custom SQL query with named parameters like ':username' and conditional parameters like '#[and GENDER=:gender]'.
```java
// 也可直接写sql,由于参数列表中有String等类型,可在sql中直接使用参数名称
@Sql("SELECT * FROM T_USER WHERE WHERE USER_NAME=:username #[and GENDER=:gender]")
UserVo getByUserName2(String username,Integer gender);
```
--------------------------------
### Complex SQL Translation Example
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
This SQL snippet demonstrates complex translation logic using the translate tag. It defines conditional translations for 'deliver_type' based on 'order_type', caching the translations in 'dictCache'.
```xml
```
--------------------------------
### SQLToy Mapper - Query Single User by Username
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of a SQLToy mapper interface method to query a single UserVo by username. It uses the @Sql annotation to specify the SQL ID 'userList'.
```java
// 查询单个User,getByUserName这个名字不重要,以@sql注解中内容为准
@Sql("userList")
UserVo getByUserName(String username);
```
--------------------------------
### SQLToy Mapper - Query User List with Nested Entity Parameter
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of querying a list of UserVo objects using a nested entity parameter. Parameters are accessed using dot notation (e.g., ':user.username').
```java
//由于使用了Integer类型参数,user的值需要使用user.这样的前缀
@Sql("SELECT * FROM T_USER WHERE WHERE USER_NAME=:user.username #[and GENDER=:gender]")
List queryUser(UserVo user,Integer gender);
```
--------------------------------
### Configure SQLToyContext Bean
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
This XML snippet defines the SQLToyContext bean within a Spring application context. It specifies the class, initialization method ('initialize'), and destruction method ('destroy'), ensuring proper setup and cleanup of SQLToy resources.
```xml
```
--------------------------------
### SQLToy Mapper - Save User Operation
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Example of using a SQLToy mapper to insert a new user. This method returns the number of affected rows. For auto-increment primary keys, using SqlToyLazyDao.save() is recommended to retrieve the generated key.
```java
//下面操作建议直接调使用dao接口调用,比如:insert操作,调用dao.save(user)还以返回user的主键(主键自增时比较有用)
//但是使用mapper的语句时,返回的是影响数据的条数
//更新返回影响数据条数
@Sql("INSERT INTO T_USER(USER_NAME,GENDER) VALUES(:username,:gender)")
long saveUser(User user);
```
--------------------------------
### SQLToy Configuration Comparison (Spring Boot vs. Solon)
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Understand the configuration differences between SQLToy in Spring Boot and Solon. Solon simplifies configuration by removing the 'spring.' prefix.
```properties
# sqltoy 在spring boot中的配置方式
spring.sqltoy.sqlResourcesDir=classpath:com/sqltoy/quickstart
spring.sqltoy.translateConfig=classpath:sqltoy-translate.xml
# sqltoy 在solon中的配置方式及默认值
sqltoy.sqlResourcesDir=classpath:sqltoy
sqltoy.translateConfig=classpath:sqltoy-translate.xml
# 当solon在debug模式下时,这个值会强制设置为true
sqltoy.debug=false
# 缓存类型,默认为Solon提供的缓存,即由CacheService提供
sqltoy.cacheType=solon
```
--------------------------------
### Get Slowest SQL Information
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Retrieve information about the slowest SQL queries executed. This method is useful for performance monitoring and debugging.
```java
lazyDao.getSqlToyContext().getSlowestSql(10,true)
```
--------------------------------
### QuickVO XML Configuration File
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
Define database connection details, project properties, and generation tasks for POJOs and DTOs in this XML configuration file.
```xml
```
--------------------------------
### Generate POJO and DTO with QuickVO
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
Execute this Maven command in your project's root directory to generate POJOs and DTOs. The generated files will appear in the specified package structure under src/main/java.
```bash
mvn quickvo:quickvo
```
--------------------------------
### Solon Application Entry Point
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Standard Java application entry point for Solon applications. Use Solon.start to initialize and run your application.
```java
//启动应用
public class DemoApp {
public static void main(String[] args) {
Solon.start(DemoApp.class, args);
}
}
```
--------------------------------
### QuickVO Maven Plugin Configuration
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
Configure the quickvo-maven-plugin in your pom.xml to generate POJOs and DTOs from your database schema. Ensure the MySQL connector is available.
```xml
com.sagframequickvo-maven-plugin1.0.7./src/main/resources/quickvo.xml${project.basedir}com.mysqlmysql-connector-j${mysql.version}
```
--------------------------------
### Multiple SQL Resource Directories Configuration
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Configure multiple directories for SQL resources by separating paths with a semicolon.
```xml
```
--------------------------------
### Save Staff Information using SqlToyCRUDService
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/README.md
Demonstrates saving a new employee record using SqlToy's CRUD service. Ensure StaffInfoVO and FileUtil are correctly implemented and the classpath resource exists.
```java
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SqlToyApplication.class)
public class CrudCaseServiceTest {
@Autowired
private SqlToyCRUDService sqlToyCRUDService;
/**
* 创建一条员工记录
*/
@Test
public void saveStaffInfo() {
StaffInfoVO staffInfo = new StaffInfoVO();
staffInfo.setStaffId("S190715005");
staffInfo.setStaffCode("S190715005");
staffInfo.setStaffName("测试员工4");
staffInfo.setSexType("M");
staffInfo.setEmail("test3@aliyun.com");
staffInfo.setEntryDate(LocalDate.now());
staffInfo.setStatus(1);
staffInfo.setOrganId("C0001");
staffInfo.setPhoto(FileUtil.readAsBytes("classpath:/mock/staff_photo.jpg"));
staffInfo.setCountry("86");
sqlToyCRUDService.save(staffInfo);
}
}
```
--------------------------------
### Spring Boot JDBC Starter Dependency
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
Include this dependency to enable Spring's JDBC support, typically used for database connectivity.
```xml
org.springframework.bootspring-boot-starter-jdbc3.4.6
```
--------------------------------
### Maven Dependency for Spring Boot Starter
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/README.md
Add this dependency to your Maven project for integrating SqlToy with Spring Boot. Ensure you use the correct artifactId for your project type (e.g., spring-starter, solon-plugin, spring, or just sqltoy). The version should match your project's requirements, with specific versions like '5.6.81.jre8' available for JDK 8 compatibility.
```xml
com.sagframesagacity-sqltoy-spring-starter5.6.81
```
--------------------------------
### SQLToy ORM Core - Version 5.6.38 Changelog
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Adds support for /* @fast_start */ and /* @fast_end */ markers for fast pagination debugging. Improves matching for @fast with spaces before the opening parenthesis.
```markdown
1、增加通过/* @fast_start */ 和 /* @fast_end */代替@fast标记快速分页的开始和结束位置,从而便于sql调试
2、@fast支持@fast (sql) 左括号跟@fast之间存在空格情况的匹配
```
--------------------------------
### Cache Translation Multiple Configuration Files
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-spring/changelog.md
Cache translation configuration now supports multiple configuration files, with default configurations specified as `classpath:sqltoy-translate.xml;classpath:translates`.
```java
Cache translation configuration supports multiple configuration files, default configuration is: classpath:sqltoy-translate.xml;classpath:translates
```
--------------------------------
### Get Translated Cache Data as VO/DTO List
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-spring/changelog.md
Retrieves cached translation data and returns it as a list of objects of a specified type. Useful for accessing cached configurations or translations in a structured object format.
```java
public List getTranslateCache(String cacheName, String cacheType,Class reusltType);
```
--------------------------------
### Application Configuration for Datasource and SQLToy
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
Configure your application's data source using HikariCP and set up SQLToy properties, including the SQL resources directory and debug mode.
```yaml
spring:
datasource:
name: dataSource
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: helloworld
password: helloworld
isAutoCommit: false
url: jdbc:mysql://127.0.0.1:3306/helloworld?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true
sqltoy:
#非必选项,设置sql.xml文件存放路径(会自动向下扫描,多路径范例:classpath:com/sqltoy/helloworld,classpath:com/sqltoy/system
sqlResourcesDir: classpath:com/sqltoy/helloworld
# 默认为false,debug模式将打印执行sql,并自动检测sql文件更新并重新加载
debug: true
```
--------------------------------
### Spring Boot Application Entry Point
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
The main class for a Spring Boot application, responsible for bootstrapping the application context.
```java
@SpringBootApplication
@ComponentScan(basePackages = { "com.sqltoy.helloworld" })
@EnableTransactionManagement
public class SqlToyApplication {
/**
* @param args
*/
public static void main(String[] args) {
SpringApplication.run(SqlToyApplication.class, args);
}
}
```
--------------------------------
### SQLToy ORM Core - Version 5.6.39 Changelog
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Optimizes @fast_start and @fast_end markers to support only @fast_start. Enhances lightDao.Store().resultTypes() to replace .moreResult(true). Improves loadAll for large-scale parallel execution. Adjusts slow SQL time standard to 8 seconds.
```markdown
1、优化5.6.38 -- @fast_start 和 -- @fast_end的标记,支持只需要-- @fast_start即可标记
2、优化支持lightDao.Store().resultTypes(Class...clasess)多个结果类型即可替代.moreResult(true)的设置
3、优化loadAll,改进大批量并行执行(之前是先分批后拆分并行,导致并行实际并未生效或无法起到实质效果)
4、调整提示慢sql的时间标准,默认值从30秒改为8秒
```
--------------------------------
### MapKit for Map Construction
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-spring/changelog.md
Provides a `MapKit` utility for quickly constructing Maps, useful for passing parameters to queries or methods.
```java
add MapKit for quick construction of Map for parameter passing
```
--------------------------------
### Solon Data Source Configuration
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Configure multiple data sources for your Solon application using the provided YAML format. Each data source requires JDBC URL, driver class, username, and password.
```yaml
demo.db1:
schema: rock
jdbcUrl: jdbc:mysql://localhost:3306/rock?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: 123456
demo.db2:
schema: rock
jdbcUrl: jdbc:mysql://localhost:3306/rock?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: 123456
```
--------------------------------
### Dynamic Query with Filters and Values
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Demonstrates how to dynamically build a query using EntityQuery, including WHERE clauses with named parameters, values, and filters. This is useful for constructing queries programmatically where conditions might change.
```java
@Test
public void findEntityByVO() {
List staffVOs = sqlToyLazyDao.findEntity(StaffInfoVO.class,
EntityQuery.create().where("#[staffId=:staffId]#[and staffName like :staffName] #[ and status=:status]")
.values(new StaffInfoVO().setStatus(-1).setStaffName("陈").setStaffId("S0005"))
.filters(new ParamsFilter("status").eq(-1)).filters(new ParamsFilter("staffName").rlike())
.filters(new ParamsFilter("staffId").primary()));
System.err.println(JSON.toJSONString(staffVOs));
}
```
--------------------------------
### SQLToy ORM Core - Version 5.6.29 Changelog
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Adds support for vastbase database, mapping it to gaussdb by default. Sets pageFetchSizeLimit to less than 0 for no limit. Optimizes rs.close() behavior to be handled in finally blocks.
```markdown
1、增加海量数据库(vastbase)支持,默认映射成gaussdb执行
2、分页最大单页记录pageFetchSizeLimit(对应参数:spring.sqltoy.pageFetchSizeLimit)小于0表示不做限制
3、优化个别rs.close()行为,统一放入finally块中处理
```
--------------------------------
### SQLToy ORM Core - Version 5.6.30 Changelog
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Adds support for opengauss and stardb databases. Modifies vastbase and mogdb to inherit from opengauss.
```markdown
1、增加opengauss、stardb数据库的支持,将vastbase、mogdb改为继承opengauss模式
```
--------------------------------
### SQLToy-ORM Spring Boot Starter Dependency
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
Add this dependency to your pom.xml to integrate SQLToy-ORM with your Spring Boot application.
```xml
com.sagframesagacity-sqltoy-spring-starter5.6.49
```
--------------------------------
### One-to-One Relationship Configuration
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Demonstrates how to define a one-to-one relationship with custom fields and cascade delete option. This is useful for complex object mappings.
```java
// 可以自行定义oneToMany 和oneToOne
// fields:表示当前表字段(当单字段关联且是主键时可不填)
// mappedFields:表示对应关联表的字段
// delete:表示是否执行级联删除,考虑安全默认为false(有实际外键时quickvo生成会是true)
@OneToOne(fields = { "transDate", "transCode" }, mappedFields = { "transDate", "transId" }, delete = true)
private ComplexpkItemVO complexpkItemVO;
```
--------------------------------
### Dynamic SQL Conditional Logic
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
This SQL snippet illustrates dynamic conditional logic using @if, @elseif, and @else. It shows how conditions are evaluated and applied, including scenarios where dynamic parameters are null or absent, and how to handle non-if logic with dynamic parameters.
```sql
select * from table where name='测试'
-- 非if逻辑场景下,内部动态参数为null,最终为and status=1 也要自动剔除
#[and status=1 #[and type=:type] #[and orderName like :orderName] ]
-- flag==1成立,因为内容存在动态参数,所以继续变成#[and status=:status]参数为null剔除,不为null则保留
#[@if(:flag==1) and status=:status]
-- 成立,因为and status=1 没有动态参数,则保留and status=1
#[@if(:flag==1) and status=1 ]
#[@elseif(:flag==2) and status in (2,4) ]
#[@else and status in (1,2)]
```
--------------------------------
### Solon Data Source Bean Configuration
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Configure DataSource beans in Solon using the @Configuration and @Bean annotations. Inject properties using @Inject.
```java
//配置数据源
@Configuration
public class Config {
@Bean
public DataSource db1(@Inject("${demo.db1}") HikariDataSource ds) {
return ds;
}
//多数据源
@Bean("tow")
public DataSource db2(@Inject("${demo.db2}") HikariDataSource ds) {
return ds;
}
}
```
--------------------------------
### Page Optimization Configuration
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Configure page optimization settings, including alive maximum count and alive seconds.
```xml
```
--------------------------------
### Cross-Database Function Nesting Support
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-spring/changelog.md
Optimizes SQL function adaptation across different databases to support nested function calls.
```sql
Optimized sql cross-database function adaptation to support function nesting
```
--------------------------------
### ExecuteSql with Sharding
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-spring/changelog.md
Optimizes `executeSql` to handle scenarios involving database sharding and table partitioning.
```java
Optimized executeSql to add scenarios with sharding and partitioning
```
--------------------------------
### SQLToy ORM Core - Version 5.2.8 Changelog
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Introduces support for dynamically adding cache translation configurations and cache update detection.
```markdown
1、支持动态增加缓存翻译配置和缓存更新检测
```
--------------------------------
### Cache Translation Configuration with Split Regex
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Configure cache translation for a column, specifying the cache name, columns to translate, and a regex for splitting and linking values.
```xml
```
--------------------------------
### SQL with Question Mark Parameters and @fast()
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Addresses a defect in handling parameter positions for Top record selection and random record selection in SQL statements that use question mark (?) for parameters and the @fast() annotation.
```sql
sql with '?' parameter and @fast() scenario
```
--------------------------------
### Dynamic Cache Configuration and Update Detection
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-spring/changelog.md
Supports dynamic addition of cache translation configurations and enables detection of cache updates. This allows for real-time adjustments to cached data.
```java
Support dynamic addition of cache translation configuration and cache update detection
```
--------------------------------
### Spring XML Configuration for SQLToy
Source: https://github.com/sagframe/sagacity-sqltoy/wiki/如何在spring中配置使用sqltoy
Defines the SQLToyContext bean in Spring, specifying resources, packages, handlers, and database-specific settings. Includes configurations for common DAOs and services.
```xml
com.sagframe.portal.modules.business.vocom.sagframe.portal.modules.common.vocom.sagframe.portal.modules.system.vocom.sagframe.portal.modules.sagacity.vo
```
--------------------------------
### SQLToy Order Info Table Schema
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
Defines the schema for the SQLTOY_ORDER_INFO table, including columns for order details, pricing, and timestamps.
```sql
DROP TABLE IF EXISTS SQLTOY_ORDER_INFO;
CREATE TABLE SQLTOY_ORDER_INFO(
`ORDER_ID` VARCHAR(32) NOT NULL COMMENT '订单编号' ,
`ORDER_TYPE` VARCHAR(32) COMMENT '订单类别' ,
`PRODUCT_CODE` VARCHAR(32) COMMENT '商品代码' ,
`UOM` VARCHAR(30) COMMENT '计量单位' ,
`PRICE` DECIMAL(24,6) COMMENT '价格' ,
`QUANTITY` DECIMAL(24,6) COMMENT '数量' ,
`TOTAL_AMT` DECIMAL(24,6) COMMENT '订单总金额' ,
`STAFF_CODE` VARCHAR(32) COMMENT '销售员' ,
`ORGAN_ID` VARCHAR(32) COMMENT '销售部门' ,
`STATUS` INT COMMENT '订单状态' ,
`CREATE_BY` VARCHAR(32) COMMENT '创建人' ,
`CREATE_TIME` DATETIME COMMENT '创建时间' ,
`UPDATE_BY` VARCHAR(32) COMMENT '更新人' ,
`UPDATE_TIME` DATETIME COMMENT '更新时间' ,
PRIMARY KEY (ORDER_ID)
) COMMENT = 'sqltoy订单信息演示表';
```
--------------------------------
### Dynamic URL Generation in SQL
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/src/test/resources/scripts/markSql.txt
This SQL snippet demonstrates how to dynamically construct a URL string by concatenating literal strings with a column value (RPT_ID) and a wildcard. It's useful for generating report URLs based on database records.
```sql
SELECT
CONCAT(CONCAT('mobile/report_mobile/*.do\?(*&){0,1}rptDeployVO.rptId=', RPT_ID), '*') URL,
ROLE_CODE
FROM A
```
--------------------------------
### Basic CRUD Operations with LightDao
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/README.md
Perform save, delete, update, and deep update operations using LightDao. Supports batch operations and parallel saving.
```java
//三步曲:1、quickvo生成pojo,2、完成yml配置;3、service中注入dao(无需自定义各种dao)
@Autowired
LightDao lightDao;
StaffInfoVO staffInfo = new StaffInfoVO();
//保存
lightDao.save(staffInfo);
//删除
lightDao.delete(new StaffInfoVO("S2007"));
//public Long update(Serializable entity, String... forceUpdateProps);
// 这里对photo 属性进行强制修改,其他为null自动会跳过
lightDao.update(staffInfo, "photo");
//只更新指定字段
lightDao.update().updateFields("name","status").one(entity);
lightDao.update().updateFields("name","status").many(entities);
//深度修改,不管是否null全部字段修改
lightDao.updateDeeply(staffInfo);
//批量保存或修改
lightDao.saveOrUpdateAll(staffList);
//批量保存
lightDao.saveAll(staffList);
//并行保存
lightDao.save().parallelConfig(ParallelConfig.create().groupSize(5000).maxThreads(10)).many(entities)
...............
lightDao.loadByIds(StaffInfoVO.class,"S2007")
//唯一性验证
lightDao.isUnique(staffInfo, "staffCode");
```
--------------------------------
### SQLToy ORM Core - Version 5.6.28 Changelog
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Standardizes if/elseif/else logic, preventing dynamic parameters from being removed in certain historical scenarios. Demonstrates conditional SQL execution based on parameter values and the presence of dynamic parameters.
```markdown
1、规范if/elseif/else的逻辑(历史版本:if场景,sql中无动态参数也会被剔除)
```
--------------------------------
### SQL Completion Enhancement
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-spring/changelog.md
Improves SQL completion, such as automatically adding `select *` when the statement is `from table where xxx`.
```sql
SQL completion optimization, such as automatically completing select * in the case of from table where xxx
```
--------------------------------
### Update/Delete/UpdateFetch with Sharding
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-spring/changelog.md
Enhances `updateByQuery`, `deleteByQuery`, and `updateFetch` to correctly handle scenarios involving database sharding and table partitioning.
```java
updateByQuery, deleteByQuery, updateFetch improved sharding and partitioning scenarios
```
--------------------------------
### SQLToy-ORM Solon Plugin Dependency
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/docs/helloworld.md
Include this dependency if you are using SQLToy-ORM with the Solon framework.
```xml
com.sagframesagacity-sqltoy-solon-plugin5.6.49
```
--------------------------------
### SQLToy ORM Core - Version 5.2.9 Changelog
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-core/changelog.md
Addresses the requirement for testing cross-database compatibility of features within a single database scenario for productized software.
```markdown
1、针对一下产品化的软件(适配多种数据库:mysql\oracle\postgres\db2\mssql),要求在一个数据库场景下可以测试相同的功能是否可以适配不同数据库
```
--------------------------------
### Dynamic SQL Fragment Inclusion
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-spring/changelog.md
Allows SQL fragments to be included dynamically using `@value(:sqlPart)`. This supports cross-database function adaptation, especially in special scenarios.
```sql
enhance sql in special scenarios to use @value(:sqlPart) to introduce sql fragments, doing cross-database function adaptation
```
--------------------------------
### SQLToy ORM Plugin Dependency
Source: https://github.com/sagframe/sagacity-sqltoy/blob/5.6/trunk/sqltoy-orm-solon-plugin/README.md
Add the sagacity-sqltoy-solon-plugin dependency to your project to enable SQLToy ORM support.
```xml
com.sagframesagacity-sqltoy-solon-plugin
```