forked from zio/zio-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShopSchema.scala
39 lines (31 loc) · 1.28 KB
/
ShopSchema.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package zio.sql
trait ShopSchema extends Jdbc { self =>
import self.ColumnSet._
object Users {
val users =
(uuid("id") ++ int("age") ++ localDate("dob") ++ string("first_name") ++ string("last_name")).table("users")
val (userId, age, dob, fName, lName) = users.columns
}
object Orders {
val orders = (uuid("id") ++ uuid("usr_id") ++ localDate("order_date")).table("orders")
val (orderId, fkUserId, orderDate) = orders.columns
}
object Products {
val products =
(int("id") ++ string("name") ++ string("description") ++ string("image_url")).table("products")
val (productId, name, description, imageURL) = products.columns
}
object ProductPrices {
val productPrices =
(int("product_id") ++ offsetDateTime("effective") ++ bigDecimal("price")).table("product_prices")
val (fkProductId, effective, price) = productPrices.columns
}
object OrderDetails {
val orderDetails =
(int("order_id") ++ int("product_id") ++ double("quantity") ++ double("unit_price"))
.table(
"order_details"
) // todo fix #3 quantity should be int, unit price should be bigDecimal, numeric operators only support double ATM.
val (fkOrderId, fkProductId, quantity, unitPrice) = orderDetails.columns
}
}