-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show method for render statements #988
Open
GrigoriiBerezin
wants to merge
2
commits into
zio:master
Choose a base branch
from
GrigoriiBerezin:add_show_and_tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
mysql/src/test/scala/zio/sql/mysql/MySqlQueryShowSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package zio.sql.mysql | ||
|
||
import zio.Scope | ||
import zio.schema.DeriveSchema | ||
import zio.sql.table.Table._ | ||
import zio.test._ | ||
|
||
import java.time._ | ||
import java.util.UUID | ||
|
||
object MySqlQueryShowSpec extends ZIOSpecDefault with MysqlRenderModule { | ||
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("MySqlQueryShow")( | ||
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 LIMIT 5 OFFSET 10" | ||
|
||
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 = '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) | ||
} | ||
) | ||
} |
86 changes: 86 additions & 0 deletions
86
oracle/src/test/scala/zio/sql/oracle/OracleSqlQueryShowSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
) | ||
} |
86 changes: 86 additions & 0 deletions
86
postgres/src/test/scala/zio/sql/postgresql/PostgresSqlQueryShowSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package zio.sql.postgresql | ||
|
||
import zio.Scope | ||
import zio.schema.DeriveSchema | ||
import zio.sql.table.Table._ | ||
import zio.test._ | ||
|
||
import java.time._ | ||
import java.util.UUID | ||
|
||
object PostgresSqlQueryShowSpec extends ZIOSpecDefault with PostgresRenderModule { | ||
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("PostgresSqlQueryShow")( | ||
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\" LIMIT 5 OFFSET 10" | ||
|
||
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 \"name\" = 'foo', \"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) | ||
} | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems that this implicit class should extend AnyVal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, thx, will fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, can't do it due to show method dependency on realization of trait, which is prohibited for value class