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.
Script DSL
任意のSQLスクリプトを実行するためのDSL
We are currently working on the translation from Japanese to English. We would appreciate your cooperation.
概要
Script DSLは任意のSQLスクリプトを実行できます。
execute
実行したいSQLスクリプトをexecute
に渡します。
クエリ実行時にキーが重複した場合、org.komapper.core.UniqueConstraintException
がスローされます。
val query: Query<Unit> = ScriptDsl.execute("""
drop table if exists example;
create table example (id integer not null primary key, value varchar(20));
insert into example (id, value) values(1, 'test');
""".trimIndent())
options
クエリの挙動をカスタマイズするにはoptions
を呼び出します。
ラムダ式のパラメータはデフォルトのオプションを表します。
変更したいプロパティを指定してcopy
メソッドを呼び出してください。
val query: Query<Unit> = ScriptDsl.execute("""
drop table if exists example;
create table example (id integer not null primary key, value varchar(20));
insert into example (id, value) values(1, 'test');
""".trimIndent()).options {
it.copty(
queryTimeoutSeconds = 5
)
}
指定可能なオプションには以下のものがあります。
- queryTimeoutSeconds
- クエリタイムアウトの秒数です。デフォルトは
null
でドライバの値を使うことを示します。 - suppressLogging
- SQLのログ出力を抑制するかどうかです。デフォルトは
false
です。
executionOptions の同名プロパティよりもこちらに明示的に設定した値が優先的に利用されます。
Last modified January 10, 2022: Prepare English contents (f426de7)