Ray
03/07/2021, 7:44 PMjava.util.NoSuchElementException: List is empty.
and i'm pretty certain the list is not empty. Also please note l'm relatively new to working with ktor/exposed. I'll really appreciate any help cos it's really difficult to find helpful post or video tutorials on ktor/exposed.
var statement: InsertStatement<Number>? = null
var addOnStatement: List<ResultRow>?
var foodSizeStatement: List<ResultRow>?
var foodAddOns = emptyList<com.df.backend.model.FoodAddOn>()
var foodSizes = emptyList<com.df.backend.model.FoodSize>()
dbQuery {
statement = Foods.insert { food ->
food[name] = foodRequest.name
food[description] = foodRequest.description
food[category] = foodRequest.category
food[foodImage] = foodRequest.foodImage
food[createdAt] = foodRequest.createdAt
food[updatedAt] = foodRequest.updatedAt
}
val resultRow = statement?.resultedValues?.get(0)
println("Food count ${statement?.resultedValues?.size}")
println("Addon List ${foodRequest.foodAddOns.size}")
addOnStatement = FoodAddOn.batchInsert(foodRequest.foodAddOns) { addOn ->
this[FoodAddOn.name] = addOn.name
this[FoodAddOn.addOnPrice] = addOn.addOnPrice
this[FoodAddOn.foodAddOnImage] = addOn.foodAddOnImage
this[FoodAddOn.foodId] = resultRow?.get(Foods.foodId)!!
}
foodAddOns = rowToAddOns(addOnStatement!!)
foodSizeStatement = FoodSize.batchInsert(foodRequest.foodSizes) { foodSize ->
this[FoodSize.size] = foodSize.size
this[FoodSize.sizePrice] = foodSize.sizePrice.toInt()
this[FoodSize.foodId] = resultRow?.get(Foods.foodId)!!
}
foodSizes = rowToSizes(foodSizeStatement!!)
}
return rowToFood(statement?.resultedValues?.get(0),foodAddOns, foodSizes )
Ray
03/07/2021, 7:44 PMobject Foods : UUIDTable() {
val foodId = uuid("food_id").autoGenerate().primaryKey().uniqueIndex()
val name = varchar("name", 50).uniqueIndex()
val foodImage = varchar("food_image", 70)
val description = varchar("description", 500)
val category = varchar("category", 50)
val createdAt = varchar("created_at", 50)
val updatedAt = varchar("updated_at", 50)
}
object FoodAddOn : UUIDTable() {
val addOnId = uuid("food_add_on_id").autoGenerate().primaryKey()
val name = varchar("name", 70)
val foodAddOnImage = varchar("food_add_on_image", 70)
val foodId = uuid("food_id")
.references(Foods.foodId)
val addOnPrice = integer("add_price")
val createdAt = varchar("created_at", 50)
val updatedAt = varchar("updated_at", 50)
}
object FoodSize : UUIDTable() {
val foodSizeId = uuid("food_size_id").autoGenerate().primaryKey()
val size = varchar("name", 70)
val foodId = uuid("food_id")
.references(Foods.foodId)
val sizePrice = integer("size_price")
val createdAt = varchar("created_at", 50)
val updatedAt = varchar("updated_at", 50)
}
Ray
03/07/2021, 7:53 PMJoel
03/08/2021, 9:46 PMfirstOrNull
). Also have a gander at the Exposed wiki and make sure that your usage is correct. UUIDTable
will automatically create the ID column for you and provides a constructor to specify the column name if desired.Ray
03/08/2021, 10:44 PMaddOnStatement = FoodAddOn.batchInsert(listOf(FoodAddOn(
values....
),FoodAddOn(
values...
)) { addOn ->
this[FoodAddOn.name] = addOn.name
this[FoodAddOn.addOnPrice] = addOn.addOnPrice
this[FoodAddOn.foodAddOnImage] = addOn.foodAddOnImage
this[FoodAddOn.foodId] = resultRow?.get(Foods.foodId)!!
}
Ray
03/08/2021, 10:44 PMRay
03/08/2021, 10:46 PMThere are some helper functions that are not provided.
Ray
03/08/2021, 10:48 PMAlso have a gander at the Exposed wiki and make sure that your usage is correct.