Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 80f7afd

Browse files
- add show method for statements
- add tests on `show` for all sql dialects - add `show` info in README
1 parent d465799 commit 80f7afd

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

README.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
ZIO SQL lets you write type-safe, type-inferred, and composable SQL queries in ordinary Scala, helping you prevent persistence bugs before they happen, and leverage your IDE to make writing SQL productive, safe, and fun.
88

9-
[![Development](https://img.shields.io/badge/Project%20Stage-Development-green.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-sql/workflows/CI/badge.svg) [![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-sql_2.13.svg?label=Sonatype%20Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-sql_2.13/) [![ZIO SQL](https://img.shields.io/github/stars/zio/zio-sql?style=social)](https://github.com/zio/zio-sql)
9+
[![Development](https://img.shields.io/badge/Project%20Stage-Development-green.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-sql/workflows/CI/badge.svg) [![Sonatype Releases](https://img.shields.io/nexus/r/https/oss.sonatype.org/dev.zio/zio-sql_2.13.svg?label=Sonatype%20Release)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-sql_2.13/) [![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-sql_2.13.svg?label=Sonatype%20Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-sql_2.13/) [![javadoc](https://javadoc.io/badge2/dev.zio/zio-sql-docs_2.13/javadoc.svg)](https://javadoc.io/doc/dev.zio/zio-sql-docs_2.13) [![ZIO SQL](https://img.shields.io/github/stars/zio/zio-sql?style=social)](https://github.com/zio/zio-sql)
1010

1111
## Introduction
1212

@@ -63,16 +63,16 @@ ZIO SQL is packaged into separate modules for different databases. Depending on
6363

6464
```scala
6565
//PostgreSQL
66-
libraryDependencies += "dev.zio" %% "zio-sql-postgres" % "<version>"
66+
libraryDependencies += "dev.zio" %% "zio-sql-postgres" % "0.1.2"
6767

6868
//MySQL
69-
libraryDependencies += "dev.zio" %% "zio-sql-mysql" % "<version>"
69+
libraryDependencies += "dev.zio" %% "zio-sql-mysql" % "0.1.2"
7070

7171
//Oracle
72-
libraryDependencies += "dev.zio" %% "zio-sql-oracle" % "<version>"
72+
libraryDependencies += "dev.zio" %% "zio-sql-oracle" % "0.1.2"
7373

7474
//SQL Server
75-
libraryDependencies += "dev.zio" %% "zio-sql-sqlserver" % "<version>"
75+
libraryDependencies += "dev.zio" %% "zio-sql-sqlserver" % "0.1.2"
7676
```
7777

7878
## Imports and modules
@@ -225,7 +225,52 @@ TODO: details
225225

226226
## Printing queries
227227

228-
TODO: details
228+
### Select
229+
230+
```scala
231+
select(orderId, name)
232+
.from(products.join(orders)
233+
.on(productId === id))
234+
.limit(5)
235+
.offset(10)
236+
.show
237+
// val res0: String = SELECT "order"."id", "products"."name" FROM "products" INNER JOIN "order" ON "order"."product_id" = "products"."id" LIMIT 5 OFFSET 10
238+
```
239+
240+
### Insert
241+
242+
```scala
243+
def insertProduct(uuid: UUID) =
244+
insertInto(products)(id, name, price)
245+
.values((uuid, "Zionomicon", 10.5))
246+
247+
insertProduct(UUID.fromString("dd5a7ae7-de19-446a-87a4-576d79de5c83")).show
248+
// val res0: String = INSERT INTO "products" ("id", "name", "price") VALUES (?, ?, ?);
249+
```
250+
251+
### Update
252+
253+
```scala
254+
def updateProduct(uuid: UUID) =
255+
update(products)
256+
.set(name, "foo")
257+
.set(price, price * 1.1)
258+
.where(id === uuid)
259+
260+
updateProduct(UUID.fromString("f1e69839-964f-44b7-b90d-bd5f51700540")).show
261+
// val res0: String = UPDATE "products" SET "name" = 'foo', "price" = "products"."price" * 1.1 WHERE "products"."id" = 'f1e69839-964f-44b7-b90d-bd5f51700540'
262+
```
263+
264+
### Delete
265+
266+
```scala
267+
def deleteProduct(uuid: UUID) =
268+
deleteFrom(products)
269+
.where(id === uuid)
270+
271+
deleteProduct(UUID.fromString("95625b37-e785-4b4f-86b1-69affaf5f848")).show
272+
// val res0: String = DELETE FROM "products" WHERE "products"."id" = '95625b37-e785-4b4f-86b1-69affaf5f848'
273+
```
229274

230275
## Running queries
231276

0 commit comments

Comments
 (0)