Version v0.26 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.

Schema DSL

SQLのDDLを組み立てるためのDSL

概要

Schema DSLはマッピング定義から以下のDDLを組み立てます。

  • エンティティに対応するテーブルのCREATE文/DROP文
  • エンティティのIDを生成するシーケンスのCREATE文/DROP文

create

CREATE文を生成するにはcreateを呼び出します。

val query: Query<Unit> = SchemaDsl.create(Meta.address, Meta.employee)
/*
create table if not exists ADDRESS (ADDRESS_ID integer not null, STREET varchar(500) not null, VERSION integer not null, constraint pk_ADDRESS primary key(ADDRESS_ID));
create table if not exists EMPLOYEE (EMPLOYEE_ID integer not null, EMPLOYEE_NO integer not null, EMPLOYEE_NAME varchar(500) not null, MANAGER_ID integer, HIREDATE date not null, SALARY bigint not null, DEPARTMENT_ID integer not null, ADDRESS_ID integer not null, VERSION integer not null, constraint pk_EMPLOYEE primary key(EMPLOYEE_ID));
*/

drop

DROP文を生成するにはdropを呼び出します。

val query: Query<Unit> = SchemaDsl.drop(Meta.address, Meta.employee)
/*
drop table if exists ADDRESS;
drop table if exists EMPLOYEE;
*/

dropAll

全てのオブジェクトを削除するためのDROP文を生成するにはdropAllを呼び出します。

val query: Query<Unit> = SchemaDsl.dropAll()
/*
drop all objects;
*/

options

クエリの挙動をカスタマイズするにはoptionsを呼び出します。 ラムダ式のパラメータはデフォルトのオプションを表します。 変更したいプロパティを指定してcopyメソッドを呼び出してください。

val query: Query<Unit> = SchemaDsl.create(Meta.address, Meta.employee).options {
    it.copty(
      queryTimeoutSeconds = 5
    )
}

指定可能なオプションには以下のものがあります。

queryTimeoutSeconds
クエリタイムアウトの秒数です。デフォルトはnullでドライバの値を使うことを示します。
suppressLogging
SQLのログ出力を抑制するかどうかです。デフォルトはfalseです。

executionOptions の同名プロパティよりもこちらに明示的に設定した値が優先的に利用されます。

最終更新 November 27, 2021: Add descriptions about options (d0a38d6)