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

概要

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 の同名プロパティよりもこちらに明示的に設定した値が優先的に利用されます。

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