forked from maiora/backend-api
senza parametri recupera tutta la lista, con il parametro implicito recupera solo l'id selezionato
81 lines
2.5 KiB
Kotlin
81 lines
2.5 KiB
Kotlin
package eu.maiora.db
|
|
|
|
import com.fasterxml.jackson.databind.deser.impl.CreatorCandidate.Param
|
|
import eu.maiora.model.Accounts
|
|
import eu.maiora.model.Parametri
|
|
import eu.maiora.model.ViewEcommerceArticoli
|
|
import kotlinx.coroutines.Dispatchers
|
|
import org.jetbrains.exposed.dao.IntEntity
|
|
import org.jetbrains.exposed.dao.IntEntityClass
|
|
import org.jetbrains.exposed.dao.LongEntity
|
|
import org.jetbrains.exposed.dao.LongEntityClass
|
|
import org.jetbrains.exposed.dao.id.EntityID
|
|
import org.jetbrains.exposed.dao.id.IdTable
|
|
import org.jetbrains.exposed.sql.Transaction
|
|
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
|
|
|
object AccountsTable : IdTable<Int>("accounts"){
|
|
override val id = integer("id").entityId()
|
|
val username = varchar("username", 255)
|
|
val password = varchar("password", 255)
|
|
|
|
override val primaryKey = PrimaryKey(id)
|
|
}
|
|
|
|
object ParametriTable : IdTable<Int>("parametri"){
|
|
override val id = integer("id").entityId()
|
|
val chiave = varchar("chiave", 255)
|
|
val valore = varchar("valore", 255)
|
|
|
|
override val primaryKey = PrimaryKey(id)
|
|
}
|
|
|
|
object ViewEcommerceArticoliTable : IdTable<Long>("view_ecommerce_articoli"){
|
|
override val id = long("id").entityId()
|
|
val codice = varchar("codice", 20)
|
|
val descrizione = varchar("descrizione", 255)
|
|
}
|
|
|
|
class AccountsDAO(id: EntityID<Int>) :IntEntity(id) {
|
|
companion object : IntEntityClass<AccountsDAO>(AccountsTable)
|
|
|
|
var username by AccountsTable.username
|
|
var password by AccountsTable.password
|
|
}
|
|
|
|
class ParametriDAO(id: EntityID<Int>) :IntEntity(id) {
|
|
companion object : IntEntityClass<ParametriDAO>(ParametriTable)
|
|
|
|
var chiave by ParametriTable.chiave
|
|
var valore by ParametriTable.valore
|
|
}
|
|
|
|
class ViewEcommerceArticoliDAO(id:EntityID<Long>) : LongEntity(id){
|
|
companion object : LongEntityClass<ViewEcommerceArticoliDAO>(ViewEcommerceArticoliTable)
|
|
|
|
var codice by ViewEcommerceArticoliTable.codice
|
|
var descrizione by ViewEcommerceArticoliTable.descrizione
|
|
}
|
|
|
|
|
|
fun accountsDaoToModel(dao: AccountsDAO) = Accounts(
|
|
dao.id.value,
|
|
dao.username,
|
|
dao.password
|
|
)
|
|
|
|
fun parametriDaoToModel(dao: ParametriDAO) = Parametri(
|
|
dao.id.value,
|
|
dao.chiave,
|
|
dao.valore
|
|
)
|
|
|
|
fun viewEcommerceArticoliDaoToModel(dao: ViewEcommerceArticoliDAO) = ViewEcommerceArticoli(
|
|
dao.id.value,
|
|
dao.codice,
|
|
dao.descrizione
|
|
)
|
|
|
|
|
|
suspend fun <T> suspendTransaction(block: Transaction.() -> T): T =
|
|
newSuspendedTransaction(Dispatchers.IO, statement = block) |