diff --git a/.gitignore b/.gitignore index e177e798..fd462f07 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ out /.apt_generated_tests/ .vscode +/.claude/settings.local.json diff --git a/example-sql-annotation/src/main/java/example/sql/annotation/EmployeeDao.java b/example-sql-annotation/src/main/java/example/sql/annotation/EmployeeDao.java index 5072db14..33c69e7c 100644 --- a/example-sql-annotation/src/main/java/example/sql/annotation/EmployeeDao.java +++ b/example-sql-annotation/src/main/java/example/sql/annotation/EmployeeDao.java @@ -25,288 +25,229 @@ public interface EmployeeDao { @Sql( """ - select - /*%expand*/* - from - employee - where - id = /* id */0 - """) + SELECT /*%expand*/* + FROM employee + WHERE id = /* id */0 + """) @Select Employee selectById(Integer id); @Sql( """ - select - /*%expand*/* - from - employee - where - /*%if min != null */ - age >= /* min */10 - /*%end */ - /*%if max != null */ - and - age <= /* max */70 - /*%end */ - order by - age - """) + SELECT /*%expand*/* + FROM employee + WHERE + /*%if min != null */ + age >= /* min */10 + /*%end */ + /*%if max != null */ + AND age <= /* max */70 + /*%end */ + ORDER BY age + """) @Select List selectByAgeRange(Age min, Age max); @Sql( """ - select - /*%expand*/* - from - employee - where - /*%for age : ages */ - age = /* age */30 - /*%if age_has_next */ - /*# "or" */ - /*%end */ - /*%end */ - """) + SELECT /*%expand*/* + FROM employee + WHERE + /*%for age : ages */ + age = /* age */30 + /*%if age_has_next */ + /*# "or" */ + /*%end */ + /*%end */ + """) @Select List selectByAges(List ages); @Sql( """ - select - /*%expand*/* - from - employee - where - /*%if name != null*/ - name = /*name*/'hoge' - /*%else */ - and - name is null - /*%end */ - """) + SELECT /*%expand*/* + FROM employee + WHERE + /*%if name != null*/ + name = /* name */'hoge' + /*%else */ + AND name IS NULL + /*%end */ + """) @Select List selectByName(String name); @Sql( """ - select - /*%expand*/* - from - employee - where - name in /* names */('aaa', 'bbb') - """) + SELECT /*%expand*/* + FROM employee + WHERE name IN /* names */('aaa', 'bbb') + """) @Select List selectByNames(List names); @Sql( """ - select - /*%expand*/* - from - employee - where - /*%if @isNotEmpty(name) */ name = /* name */'hoge' /*%end*/ - """) + SELECT /*%expand*/* + FROM employee + WHERE + /*%if @isNotEmpty(name) */ + name = /* name */'hoge' + /*%end*/ + """) @Select List selectByNotEmptyName(String name); @Sql( """ - select - /*%expand*/* - from - employee - where - name like /* @prefix(prefix) */'X%' escape '$' - """) + SELECT /*%expand*/* + FROM employee + WHERE name LIKE /* @prefix(prefix) */'X%' escape '$' + """) @Select List selectByNameWithPrefixMatching(String prefix); @Sql( """ - select - /*%expand*/* - from - employee - where - name like /* @suffix(suffix) */'%X' escape '$' - """) + SELECT /*%expand*/* + FROM employee + WHERE name LIKE /* @suffix(suffix) */'%X' escape '$' + """) @Select List selectByNameWithSuffixMatching(String suffix); @Sql( """ - select - /*%expand*/* - from - employee - where - name like /* @infix(inside) */'%X%' escape '$' - """) + SELECT /*%expand*/* + FROM employee + WHERE name LIKE /* @infix(inside) */'%X%' escape '$' + """) @Select List selectByNameWithInfixMatching(String inside); @Sql( """ - select - /*%expand*/* - from - employee - where - hiredate >= /* @roundDownTimePart(from) */'2001-01-01 12:34:56' - and - hiredate < /* @roundUpTimePart(to) */'2001-01-01 12:34:56' - """) + SELECT /*%expand*/* + FROM employee + WHERE hiredate >= /* @roundDownTimePart(from) */'2001-01-01 12:34:56' + AND hiredate < /* @roundUpTimePart(to) */'2001-01-01 12:34:56' + """) @Select List selectByHiredateRange(Timestamp from, Timestamp to); @Sql( """ - select - /*%expand*/* - from - employee - where - salary > /* salary */0 - """) + SELECT /*%expand*/* + FROM employee + WHERE salary > /* salary */0 + """) @Select List selectBySalary(Salary salary); @Sql( """ - select - sum(salary) - from - employee - """) + SELECT sum(salary) + FROM employee + """) @Select Salary selectSummedSalary(); @Sql( """ - select - /*%expand*/* - from - employee - where - name = /* e.name */'aaa' - """) + SELECT /*%expand*/* + FROM employee + WHERE name = /* e.name */'aaa' + """) @Select List selectByExample(Employee e); @Sql( """ - select - /*%expand*/* - from - employee - order by - id - """) + SELECT /*%expand*/* + FROM employee + ORDER BY id + """) @Select List selectAll(); @Sql( """ - select - /*%expand*/* - from - employee - order by - id - """) + SELECT /*%expand*/* + FROM employee + ORDER BY id + """) @Select List selectAll(SelectOptions options); @Sql( """ - select - /*%expand*/* - from - employee - where - age > /* age */0 - order by - age - """) + SELECT /*%expand*/* + FROM employee + WHERE age > /* age */0 + ORDER BY age + """) @Select(strategy = SelectType.STREAM) R selectByAge(int age, Function, R> mapper); @Sql( """ - select - /*%expand */* - from - employee e - left outer join - department d - on - e.department_id = d.id - order by - e.id - """) + SELECT /*%expand */* + FROM employee e + LEFT OUTER JOIN department d + ON e.department_id = d.id + ORDER BY e.id + """) @Select(aggregateStrategy = EmployeeAggregateStrategy.class) List selectAllEmployeeDepartment(); @Sql( """ - insert into Employee ( - ID, - NAME, - AGE, - DEPARTMENT_ID, - HIREDATE, - JOB_TYPE, - SALARY, - INSERT_TIMESTAMP, - UPDATE_TIMESTAMP, - VERSION - ) values ( - /* employee.id */1, - /* employee.name */'test', - /* employee.age */10, - /* employee.departmentId */1, - /* employee.hiredate */'2010-01-01', - /* employee.jobType */'SALESMAN', - /* employee.salary */300, - /* employee.insertTimestamp */'2010-01-01 12:34:56', - /* employee.updateTimestamp */'2010-01-01 12:34:56', - /* employee.version */1 - ) - """) + INSERT INTO Employee + (ID + , NAME + , AGE + , DEPARTMENT_ID + , HIREDATE + , JOB_TYPE + , SALARY + , INSERT_TIMESTAMP + , UPDATE_TIMESTAMP + , VERSION) + VALUES ( /* employee.id */1 + , /* employee.name */'test' + , /* employee.age */10 + , /* employee.departmentId */1 + , /* employee.hiredate */'2010-01-01' + , /* employee.jobType */'SALESMAN' + , /* employee.salary */300 + , /* employee.insertTimestamp */'2010-01-01 12:34:56' + , /* employee.updateTimestamp */'2010-01-01 12:34:56' + , /* employee.version */1 ) + """) @Insert int insert(Employee employee); @Sql( """ - update - Employee - set - NAME = /* employee.name */'test', - AGE = /* employee.age */10, - DEPARTMENT_ID = /* employee.departmentId */1, - HIREDATE = /* employee.hiredate */date'2010-01-01', - JOB_TYPE = /* employee.jobType */'SALESMAN', - SALARY = /* employee.salary */300, - UPDATE_TIMESTAMP = /* employee.updateTimestamp */timestamp'2010-01-01 12:34:56', - VERSION = /* employee.version */1 - where - ID = /* employee.id */1 - """) + UPDATE Employee + SET NAME = /* employee.name */'test' + , AGE = /* employee.age */10 + , DEPARTMENT_ID = /* employee.departmentId */1 + , HIREDATE = /* employee.hiredate */'2010-01-01' + , JOB_TYPE = /* employee.jobType */'SALESMAN' + , SALARY = /* employee.salary */300 + , UPDATE_TIMESTAMP = /* employee.updateTimestamp */'2010-01-01 12:34:56' + , VERSION = /* employee.version */1 + WHERE ID = /* employee.id */1 + """) @Update int update(Employee employee); @Sql( """ - delete - from - Employee - where - ID = /* employee.id */0 - """) + DELETE FROM Employee + WHERE ID = /* employee.id */0 + """) @Delete int delete(Employee employee); }