Skip to content

Instantly share code, notes, and snippets.

@bufferings
Last active April 2, 2018 06:42
Show Gist options
  • Save bufferings/5bb9b6a6f9eb3967bea8e7b787b199e6 to your computer and use it in GitHub Desktop.
Save bufferings/5bb9b6a6f9eb3967bea8e7b787b199e6 to your computer and use it in GitHub Desktop.
実際に書いて比べてみようと思って
項目 現状 案1 案2 案3
Select: ファイルから
@Select
Employee selectByNameAndSalary(String name, Salary salary);
デフォルトの動作は変更なし(ファイルから):
@Select
Employee selectByNameAndSalary(String name, Salary salary);
明示的にこういう書き方もできるようになる:
@Sql(useFile = true)
@Select
Employee selectByNameAndSalary(String name, Salary salary);
デフォルトの動作は変更なし(ファイルから):
@Select
Employee selectByNameAndSalary(String name, Salary salary);
明示的にこういう書き方もできるようになる:
@SqlFile
@Select
Employee selectByNameAndSalary(String name, Salary salary);
変更なし:
@Select
Employee selectByNameAndSalary(String name, Salary salary);
Select: SQL直接指定
@Sql(`
    select
      *
    from
      employee
    where
      employee_name = /* name */'hoge'
      and salary > /* salary */100
`)
@Select
Employee selectByNameAndSalary(String name, Salary salary);
@Sql(`
    select
      *
    from
      employee
    where
      employee_name = /* name */'hoge'
      and salary > /* salary */100
`)
@Select
Employee selectByNameAndSalary(String name, Salary salary);
@Select(sql = `
    select
      *
    from
      employee
    where
      employee_name = /* name */'hoge'
      and salary > /* salary */100
`)
Employee selectByNameAndSalary(String name, Salary salary);
Insert: 自動生成
@Insert
int insert(Employee employee);
変更なし:
@Insert
int insert(Employee employee);
変更なし:
@Insert
int insert(Employee employee);
変更なし:
@Insert
int insert(Employee employee);
Insert: ファイルから
@Insert(sqlFile = true)
int insert(Employee employee);
要変更:
@Sql(useFile = true)
@Insert
int insert(Employee employee);
要変更:
@SqlFile
@Insert
int insert(Employee employee);
変更なし:
@Insert(sqlFile = true)
int insert(Employee employee);
Insert: SQL直接指定
@Sql(`
  insert into employee (
    id, name, salary, version
  ) values (
    /* employee.id */0,
    /* employee.name */'hoge',
    /* employee.salary */100,
    /* employee.version */0
  )
`)
@Insert
int insert(Employee employee);
@Sql(`
  insert into employee (
    id, name, salary, version
  ) values (
    /* employee.id */0,
    /* employee.name */'hoge',
    /* employee.salary */100,
    /* employee.version */0
  )
`)
@Insert
int insert(Employee employee);
@Insert(sql = `
  insert into employee (
    id, name, salary, version
  ) values (
    /* employee.id */0,
    /* employee.name */'hoge',
    /* employee.salary */100,
    /* employee.version */0
  )
`)
int insert(Employee employee);
@bufferings
Copy link
Author

どれもいいと思うけど、案1がいちばん好きかな。

Select/InsertのDBへの操作を表すアノテーションと、SQLを表すアノテーションに役割がキレイに別れてるのと、Sqlアノテーション1つで表すことができてる。から。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment