3 ms·
Side Note: Slick has basic parameterized queries/statements/DDL. eg: val cachedPurchasesQuery = Q[String, (Int, AccountId, Timestamp)] + """
by ssmoot 12y ago
Side Note: Slick has basic parameterized queries/statements/DDL.
eg:
val cachedPurchasesQuery = Q[String, (Int, AccountId, Timestamp)] + """
|SELECT pi.purchasable_item_id, u.account_id, pi.created_at
|FROM purchased_items AS pi
|INNER JOIN users u ON pi.user_id = u.id
|WHERE purchasable_item_type = ? AND u.account_id IS NOT NULL
""".stripMargin
Then you call that like:
val magazinePurchases = cachedPurchasesQuery("Magazine").list
Or `foreach`, `firstOption`, etc. Most of the normal collection-y stuff.
I prefer this over the Table mapping DSL and for-comprehension stuff personally. But I've only used it in production on smaller projects that are limited to under a dozen queries/statements or so.