Haruki
01/28/2023, 12:25 AMval client = KMongo.createClient().coroutine
val database = client.getDatabase("shoppingList")
val collection = database.getCollection<ShoppingListItem>()
get {
call.respond(collection.find().toList())
}
I am wondering if there is a way to do the same thing with Exposed. My current understanding is to create an object DatabaseFactory for setup in Server.kt, create a Table and then use select:
object DatabaseFactory {
fun init() {
Database.connect(
"jdbc:<postgresql://host>:port/5432",
driver = "org.postgresql.Driver",
user = "user",
password = "password"
)
}
}
object ShoppingListItems: Table() {
val id = integer("id").autoIncrement().primaryKey()
val name = varchar("name", length = 255)
val owners = varchar("owners", length = 255)
}
get {
call.respond(ShoppingListItems.select { ShoppingListItems.owners like user }.toList())
}
I am also wondering if we need to create a table. Instead, I want to use a data class like this:
val collection = database.getCollection<ShoppingListItem>.
Is this the correct approach for replacing MongoDB with Postgres and KMongo with Exposed?
I have added the necessary dependencies for this change, and I would really appreciate some guidance and help with this. Thank you in advance for your help!Aleksei Tirman [JB]
01/28/2023, 1:43 PM