|
6 | 6 |
|
7 | 7 | 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. |
8 | 8 |
|
9 | | -[](https://github.com/zio/zio/wiki/Project-Stages)  [](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-sql_2.13/) [](https://github.com/zio/zio-sql) |
| 9 | +[](https://github.com/zio/zio/wiki/Project-Stages)  [](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-sql_2.13/) [](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-sql_2.13/) [](https://javadoc.io/doc/dev.zio/zio-sql-docs_2.13) [](https://github.com/zio/zio-sql) |
10 | 10 |
|
11 | 11 | ## Introduction |
12 | 12 |
|
@@ -63,16 +63,16 @@ ZIO SQL is packaged into separate modules for different databases. Depending on |
63 | 63 |
|
64 | 64 | ```scala |
65 | 65 | //PostgreSQL |
66 | | -libraryDependencies += "dev.zio" %% "zio-sql-postgres" % "<version>" |
| 66 | +libraryDependencies += "dev.zio" %% "zio-sql-postgres" % "0.1.2" |
67 | 67 |
|
68 | 68 | //MySQL |
69 | | -libraryDependencies += "dev.zio" %% "zio-sql-mysql" % "<version>" |
| 69 | +libraryDependencies += "dev.zio" %% "zio-sql-mysql" % "0.1.2" |
70 | 70 |
|
71 | 71 | //Oracle |
72 | | -libraryDependencies += "dev.zio" %% "zio-sql-oracle" % "<version>" |
| 72 | +libraryDependencies += "dev.zio" %% "zio-sql-oracle" % "0.1.2" |
73 | 73 |
|
74 | 74 | //SQL Server |
75 | | -libraryDependencies += "dev.zio" %% "zio-sql-sqlserver" % "<version>" |
| 75 | +libraryDependencies += "dev.zio" %% "zio-sql-sqlserver" % "0.1.2" |
76 | 76 | ``` |
77 | 77 |
|
78 | 78 | ## Imports and modules |
@@ -225,7 +225,52 @@ TODO: details |
225 | 225 |
|
226 | 226 | ## Printing queries |
227 | 227 |
|
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 | +``` |
229 | 274 |
|
230 | 275 | ## Running queries |
231 | 276 |
|
|
0 commit comments