com.skillw.pouvoir.internal.feature.database.sql.SQLTable.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Pouvoir Show documentation
Show all versions of Pouvoir Show documentation
Bukkit Script Engine Plugin.
package com.skillw.pouvoir.internal.feature.database.sql
import com.skillw.pouvoir.api.feature.database.sql.IPouTable
import com.zaxxer.hikari.HikariDataSource
import taboolib.module.database.*
import javax.sql.DataSource
/**
* @className PouTable
*
* @author Glom
* @date 2023/1/12 20:12 Copyright 2024 Glom.
*/
class SQLTable, E : ColumnBuilder>(private val table: Table) : IPouTable {
override val name: String = table.name
override val columns = table.columns
override val primaryKeyForLegacy = table.primaryKeyForLegacy
override val dataSource: DataSource = table.host.createDataSource(false)
constructor(name: String, host: Host) : this(Table(name, host))
override fun column(name: String?, func: E.() -> Unit): Table {
return table.add(name, func)
}
override fun select(func: ActionSelect.() -> Unit): ResultProcessorList {
return table.workspace(dataSource) { select(func) }
}
override fun find(func: ActionSelect.() -> Unit): Boolean {
return table.workspace(dataSource) { select(func) }.find()
}
override fun update(func: ActionUpdate.() -> Unit): Int {
return table.workspace(dataSource) { update(func) }.run()
}
override fun delete(func: ActionDelete.() -> Unit): Int {
return table.workspace(dataSource) { delete(func) }.run()
}
override fun insert(vararg keys: String, func: ActionInsert.() -> Unit): Int {
return table.workspace(dataSource) { insert(*keys) { func(this) } }.run()
}
override fun workspace(func: ExecutableSource.() -> Unit): ResultProcessorList {
return table.workspace(dataSource, func)
}
override fun createTable() {
table.createTable(dataSource)
}
override fun close() {
(dataSource as HikariDataSource).close()
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy