|
| 1 | +/* |
| 2 | + * Copyright 2016-2021 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +@file:Suppress("TooManyFunctions") |
| 17 | +package org.mybatis.dynamic.sql.util.kotlin.model |
| 18 | + |
| 19 | +import org.mybatis.dynamic.sql.BasicColumn |
| 20 | +import org.mybatis.dynamic.sql.SqlBuilder |
| 21 | +import org.mybatis.dynamic.sql.SqlTable |
| 22 | +import org.mybatis.dynamic.sql.insert.BatchInsertDSL |
| 23 | +import org.mybatis.dynamic.sql.insert.GeneralInsertDSL |
| 24 | +import org.mybatis.dynamic.sql.insert.InsertDSL |
| 25 | +import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL |
| 26 | +import org.mybatis.dynamic.sql.util.kotlin.BatchInsertCompleter |
| 27 | +import org.mybatis.dynamic.sql.util.kotlin.CountCompleter |
| 28 | +import org.mybatis.dynamic.sql.util.kotlin.DeleteCompleter |
| 29 | +import org.mybatis.dynamic.sql.util.kotlin.GeneralInsertCompleter |
| 30 | +import org.mybatis.dynamic.sql.util.kotlin.InsertCompleter |
| 31 | +import org.mybatis.dynamic.sql.util.kotlin.InsertSelectCompleter |
| 32 | +import org.mybatis.dynamic.sql.util.kotlin.KotlinCountBuilder |
| 33 | +import org.mybatis.dynamic.sql.util.kotlin.KotlinDeleteBuilder |
| 34 | +import org.mybatis.dynamic.sql.util.kotlin.KotlinInsertSelectSubQueryBuilder |
| 35 | +import org.mybatis.dynamic.sql.util.kotlin.KotlinSelectBuilder |
| 36 | +import org.mybatis.dynamic.sql.util.kotlin.KotlinUpdateBuilder |
| 37 | +import org.mybatis.dynamic.sql.util.kotlin.MultiRowInsertCompleter |
| 38 | +import org.mybatis.dynamic.sql.util.kotlin.SelectCompleter |
| 39 | +import org.mybatis.dynamic.sql.util.kotlin.UpdateCompleter |
| 40 | + |
| 41 | +fun count(column: BasicColumn, completer: CountCompleter) = |
| 42 | + KotlinCountBuilder(SqlBuilder.countColumn(column)).apply(completer).build() |
| 43 | + |
| 44 | +fun countDistinct(column: BasicColumn, completer: CountCompleter) = |
| 45 | + KotlinCountBuilder(SqlBuilder.countDistinctColumn(column)).apply(completer).build() |
| 46 | + |
| 47 | +fun countFrom(table: SqlTable, completer: CountCompleter) = |
| 48 | + KotlinCountBuilder(SqlBuilder.countColumn(SqlBuilder.constant<Long>("*"))) |
| 49 | + .from(table).apply(completer).build() |
| 50 | + |
| 51 | +fun deleteFrom(table: SqlTable, completer: DeleteCompleter) = |
| 52 | + KotlinDeleteBuilder(SqlBuilder.deleteFrom(table)).apply(completer).build() |
| 53 | + |
| 54 | +fun insertInto(table: SqlTable, completer: GeneralInsertCompleter) = |
| 55 | + GeneralInsertDSL.insertInto(table).apply(completer).build() |
| 56 | + |
| 57 | +fun insertSelect(table: SqlTable, completer: InsertSelectCompleter) = |
| 58 | + with(KotlinInsertSelectSubQueryBuilder().apply(completer)) { |
| 59 | + SqlBuilder.insertInto(table) |
| 60 | + .withColumnList(columnList) |
| 61 | + .withSelectStatement(this) |
| 62 | + .build() |
| 63 | + } |
| 64 | + |
| 65 | +fun <T> BatchInsertDSL.IntoGatherer<T>.into(table: SqlTable, completer: BatchInsertCompleter<T>) = |
| 66 | + into(table).apply(completer).build() |
| 67 | + |
| 68 | +fun <T> InsertDSL.IntoGatherer<T>.into(table: SqlTable, completer: InsertCompleter<T>) = |
| 69 | + into(table).apply(completer).build() |
| 70 | + |
| 71 | +fun <T> MultiRowInsertDSL.IntoGatherer<T>.into(table: SqlTable, completer: MultiRowInsertCompleter<T>) = |
| 72 | + into(table).apply(completer).build() |
| 73 | + |
| 74 | +fun select(vararg columns: BasicColumn, completer: SelectCompleter) = |
| 75 | + select(columns.asList(), completer) |
| 76 | + |
| 77 | +fun select(columns: List<BasicColumn>, completer: SelectCompleter) = |
| 78 | + KotlinSelectBuilder(SqlBuilder.select(columns)).apply(completer).build() |
| 79 | + |
| 80 | +fun selectDistinct(vararg columns: BasicColumn, completer: SelectCompleter) = |
| 81 | + selectDistinct(columns.asList(), completer) |
| 82 | + |
| 83 | +fun selectDistinct(columns: List<BasicColumn>, completer: SelectCompleter) = |
| 84 | + KotlinSelectBuilder(SqlBuilder.selectDistinct(columns)).apply(completer).build() |
| 85 | + |
| 86 | +fun update(table: SqlTable, completer: UpdateCompleter) = |
| 87 | + KotlinUpdateBuilder(SqlBuilder.update(table)).apply(completer).build() |
0 commit comments