This repository was archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathOracleSqlQueryShowSpec.scala
More file actions
86 lines (67 loc) · 2.64 KB
/
OracleSqlQueryShowSpec.scala
File metadata and controls
86 lines (67 loc) · 2.64 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package zio.sql.oracle
import zio.Scope
import zio.schema.DeriveSchema
import zio.sql.table.Table._
import zio.test._
import java.time._
import java.util.UUID
object OracleSqlQueryShowSpec extends ZIOSpecDefault with OracleRenderModule {
final case class Product(id: UUID, name: String, price: Double)
object Product {
implicit val productSchema = DeriveSchema.gen[Product]
val products = defineTableSmart[Product]
val (id, name, price) = products.columns
}
final case class Order(id: UUID, productId: UUID, quantity: Int, orderDate: LocalDate)
object Order {
implicit val orderSchema = DeriveSchema.gen[Order]
val orders = defineTable[Order]
val (orderId, productId, quantity, date) = orders.columns
}
override def spec: Spec[TestEnvironment with Scope, Any] = suite("OracleSqlQueryShow")(
test("rendering select") {
import Order._
import Product._
val selectQueryRender =
select(orderId, name)
.from(
products
.join(orders)
.on(productId === id)
)
.limit(5)
.offset(10)
.show
val expectedQuery =
"SELECT order.id, products.name FROM products INNER JOIN order ON order.product_id = products.id WHERE rownum <= 5"
assertTrue(selectQueryRender == expectedQuery)
},
test("rendering insert") {
import Product._
def insertProduct(uuid: UUID) =
insertInto(products)(id, name, price)
.values((uuid, "Zionomicon", 10.5))
val expectedQuery = "INSERT INTO products (id, name, price) VALUES (?, ?, ?)"
assertTrue(insertProduct(UUID.fromString("dd5a7ae7-de19-446a-87a4-576d79de5c83")).show == expectedQuery)
},
test("rendering update") {
import Product._
def updateProduct(uuid: UUID) =
update(products)
.set(name, "foo")
.set(price, price * 1.1)
.where(id === uuid)
val expectedQuery =
"UPDATE products SET products.name = N'foo', products.price = products.price * 1.1 WHERE products.id = 'f1e69839-964f-44b7-b90d-bd5f51700540'"
assertTrue(updateProduct(UUID.fromString("f1e69839-964f-44b7-b90d-bd5f51700540")).show == expectedQuery)
},
test("rendering delete") {
import Product._
def deleteProduct(uuid: UUID) =
deleteFrom(products)
.where(id === uuid)
val expectedQuery = "DELETE FROM products WHERE products.id = '95625b37-e785-4b4f-86b1-69affaf5f848'"
assertTrue(deleteProduct(UUID.fromString("95625b37-e785-4b4f-86b1-69affaf5f848")).show == expectedQuery)
}
)
}