Functions for Data Access
Learn how to implement functions to manipulate data and carry out main service.
We'll cover the following...
Loading a product
Press + to interact
override def loadProduct(id: ProductId) =sql"""SELECT products.id, names.lang_code, names.nameFROM productsJOIN names ON products.id = names.product_idWHERE products.id = $id""".query[(ProductId, LanguageCode, ProductName)].to[Seq].transact(tx)
The loadProduct
function simply returns all rows for a single product from the database, exactly like its Slick counterpart. The parameter will be correctly interpolated by Doobie ...