@zio.dev/zio-blocks 0.0.55 → 0.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/guides/async-getting-started.md +1 -1
- package/guides/query-dsl-extending.md +1 -1
- package/guides/query-dsl-fluent-builder.md +1 -1
- package/guides/query-dsl-reified-optics.md +1 -1
- package/guides/query-dsl-sql.md +1 -1
- package/guides/telemetry-guide.md +3 -3
- package/guides/zio-schema-migration.md +6 -6
- package/index.md +58 -34
- package/package.json +1 -1
- package/reference/async.md +2 -2
- package/reference/chunk.md +3 -3
- package/reference/codegen/index.md +1 -1
- package/reference/combinators.md +4 -4
- package/reference/config/config-source.md +2 -2
- package/reference/config/formats.md +3 -3
- package/reference/config/index.md +7 -7
- package/reference/config/rollout.md +1 -1
- package/reference/context.md +1 -1
- package/reference/data-migration.md +1 -1
- package/reference/datastar/index.md +2 -2
- package/reference/datastar.md +2 -2
- package/reference/docs.md +2 -2
- package/reference/endpoint/endpoint.md +1 -0
- package/reference/endpoint/index.md +4 -4
- package/reference/html.md +2 -2
- package/reference/htmx/index.md +2 -2
- package/reference/http-model/model.md +2 -2
- package/reference/http-model/schema-codecs.md +1 -1
- package/reference/http-model/schema.md +2 -2
- package/reference/jwt.md +1 -1
- package/reference/maybe.md +2 -2
- package/reference/media-type.md +2 -2
- package/reference/mux.mdx +2 -2
- package/reference/openapi.md +3 -3
- package/reference/projection.md +3 -3
- package/reference/resource-management/index.md +1 -1
- package/reference/resource-management/resource.md +2 -2
- package/reference/resource-management/scope.md +1 -1
- package/reference/resource-management/wire.md +2 -2
- package/reference/ringbuffer/index.mdx +2 -2
- package/reference/schema/built-in-codecs/avro.md +2 -2
- package/reference/schema/built-in-codecs/bson.md +9 -9
- package/reference/schema/built-in-codecs/csv.md +2 -2
- package/reference/schema/built-in-codecs/json/index.md +2 -2
- package/reference/schema/built-in-codecs/json/json.md +1 -0
- package/reference/schema/built-in-codecs/messagepack.md +3 -3
- package/reference/schema/built-in-codecs/thrift.md +2 -2
- package/reference/schema/built-in-codecs/toon.md +3 -3
- package/reference/schema/built-in-codecs/yaml.md +2 -2
- package/reference/schema/codec.md +10 -10
- package/reference/schema/dynamic-schema.md +3 -3
- package/reference/schema/schema-evolution/as.md +4 -4
- package/reference/schema/schema-evolution/into.md +2 -2
- package/reference/schema/schema-expr.md +2 -2
- package/reference/schema/type-class-derivation.md +1 -1
- package/reference/smithy.md +1 -1
- package/reference/sql/db-codec-deriver.md +3 -3
- package/reference/sql/db-codec.md +11 -11
- package/reference/sql/db-con.md +4 -4
- package/reference/sql/db-connection.md +1 -1
- package/reference/sql/db-tx.md +2 -2
- package/reference/sql/ddl.md +1 -1
- package/reference/sql/index.md +6 -6
- package/reference/sql/repo.md +5 -5
- package/reference/sql/sql-dialect.md +1 -1
- package/reference/sql/sql-logger.md +1 -1
- package/reference/sql/sql-name-mapper.md +3 -3
- package/reference/sql/table-metadata.md +3 -3
- package/reference/sql/table.md +10 -10
- package/reference/sql/transactor-zio.md +1 -1
- package/reference/sql/transactor.md +8 -8
- package/reference/sql-zio.md +2 -2
- package/reference/streams/core/pipeline.md +17 -17
- package/reference/streams/core/sink.md +4 -4
- package/reference/streams/core/stream.md +3 -3
- package/reference/streams/execution-and-compatibility/async-execution.md +1 -1
- package/reference/streams/index.md +3 -3
- package/reference/streams/primitives/reader.md +25 -25
- package/reference/streams/primitives/writer.md +18 -18
- package/reference/telemetry/index.md +3 -3
- package/reference/telemetry/otel/index.md +1 -1
- package/sidebars.js +261 -219
- package/reference/mux.md +0 -254
|
@@ -78,7 +78,7 @@ import zio.blocks.schema.Schema
|
|
|
78
78
|
case class User(id: Int, name: String, email: Option[String]) derives DbCodec
|
|
79
79
|
|
|
80
80
|
val codec = DbCodec[User]
|
|
81
|
-
// codec: DbCodec[User] = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
81
|
+
// codec: DbCodec[User] = zio.blocks.sql.DbCodecDeriver$$anon$10@28731048
|
|
82
82
|
|
|
83
83
|
codec.columns
|
|
84
84
|
// res1: IndexedSeq[String] = Vector("id", "name", "email")
|
|
@@ -100,7 +100,7 @@ val nullParams = codec.toDbValues(User(2, "Bob", None))
|
|
|
100
100
|
// Adapt any codec to a newtype with transform — no full Schema needed
|
|
101
101
|
case class UserId(value: Int)
|
|
102
102
|
val userIdCodec: DbCodec[UserId] = DbCodec[Int].transform(UserId(_))(_.value)
|
|
103
|
-
// userIdCodec: DbCodec[UserId] = zio.blocks.sql.DbCodec$$anon$1@
|
|
103
|
+
// userIdCodec: DbCodec[UserId] = zio.blocks.sql.DbCodec$$anon$1@7c9318fc
|
|
104
104
|
|
|
105
105
|
userIdCodec.columns
|
|
106
106
|
// res3: IndexedSeq[String] = Vector("value")
|
|
@@ -173,13 +173,13 @@ object Product { implicit val schema: Schema[Product] = Schema.derived }
|
|
|
173
173
|
// tags is stored as a JSON string in the "tags" column
|
|
174
174
|
val tagsCodec: DbCodec[Tags] =
|
|
175
175
|
DbCodec[String].transform(json => Tags(json.split(",").toList))(_.values.mkString(","))
|
|
176
|
-
// tagsCodec: DbCodec[Tags] = zio.blocks.sql.DbCodec$$anon$1@
|
|
176
|
+
// tagsCodec: DbCodec[Tags] = zio.blocks.sql.DbCodec$$anon$1@5596e273
|
|
177
177
|
|
|
178
178
|
val productCodec: DbCodec[Product] =
|
|
179
179
|
DbCodec.derivedWith[Product](
|
|
180
180
|
_.instance(TypeId.of[Product], "tags", tagsCodec)
|
|
181
181
|
)
|
|
182
|
-
// productCodec: DbCodec[Product] = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
182
|
+
// productCodec: DbCodec[Product] = zio.blocks.sql.DbCodecDeriver$$anon$10@34140b70
|
|
183
183
|
|
|
184
184
|
productCodec.columns
|
|
185
185
|
// res7: IndexedSeq[String] = Vector("id", "tags")
|
|
@@ -213,7 +213,7 @@ object Address {
|
|
|
213
213
|
|
|
214
214
|
// Address is stored as a JSON string in a single TEXT/JSONB column
|
|
215
215
|
val codec: DbCodec[Address] = DbCodec.jsonb[Address]
|
|
216
|
-
// codec: DbCodec[Address] = zio.blocks.sql.DbCodec$$anon$1@
|
|
216
|
+
// codec: DbCodec[Address] = zio.blocks.sql.DbCodec$$anon$1@43b1650c
|
|
217
217
|
|
|
218
218
|
codec.columns
|
|
219
219
|
// res10: IndexedSeq[String] = Vector("value")
|
|
@@ -235,7 +235,7 @@ val pointCodec: DbCodec[Point] = DbCodec.jsonb[Point](
|
|
|
235
235
|
p => s"${p.x},${p.y}",
|
|
236
236
|
s => { val parts = s.split(","); Point(parts(0).toDouble, parts(1).toDouble) }
|
|
237
237
|
)
|
|
238
|
-
// pointCodec: DbCodec[Point] = zio.blocks.sql.DbCodec$$anon$1@
|
|
238
|
+
// pointCodec: DbCodec[Point] = zio.blocks.sql.DbCodec$$anon$1@2634e34a
|
|
239
239
|
|
|
240
240
|
pointCodec.toDbValues(Point(1.0, 2.0))
|
|
241
241
|
// res12: IndexedSeq[DbValue] = Vector(DbString("1.0,2.0"))
|
|
@@ -260,7 +260,7 @@ import zio.blocks.schema.json.JsonCodec
|
|
|
260
260
|
|
|
261
261
|
// Assume JsonCodec[Address] is in scope from the previous example
|
|
262
262
|
val nullableCodec: DbCodec[Option[Address]] = DbCodec.jsonbOption[Address]
|
|
263
|
-
// nullableCodec: DbCodec[Option[Address]] = zio.blocks.sql.DbCodec$$anon$1@
|
|
263
|
+
// nullableCodec: DbCodec[Option[Address]] = zio.blocks.sql.DbCodec$$anon$1@5a2ab2eb
|
|
264
264
|
|
|
265
265
|
nullableCodec.toDbValues(Some(Address("Elm St", "LA")))
|
|
266
266
|
// res13: IndexedSeq[DbValue] = Vector(
|
|
@@ -293,7 +293,7 @@ object ProductId {
|
|
|
293
293
|
|
|
294
294
|
// DbCodec[ProductId] is resolved automatically — no explicit given needed
|
|
295
295
|
val codec = DbCodec[ProductId]
|
|
296
|
-
// codec: DbCodec[ProductId] = zio.blocks.sql.DbCodec$$anon$6@
|
|
296
|
+
// codec: DbCodec[ProductId] = zio.blocks.sql.DbCodec$$anon$6@7ba8fb55
|
|
297
297
|
codec.columns
|
|
298
298
|
// res16: IndexedSeq[String] = Vector("value")
|
|
299
299
|
```
|
|
@@ -344,7 +344,7 @@ case class Order(id: Long, status: String) derives DbCodec
|
|
|
344
344
|
|
|
345
345
|
// Summon the derived codec
|
|
346
346
|
val codec: DbCodec[Order] = DbCodec[Order]
|
|
347
|
-
// codec: DbCodec[Order] = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
347
|
+
// codec: DbCodec[Order] = zio.blocks.sql.DbCodecDeriver$$anon$10@5b7defec
|
|
348
348
|
codec.columns
|
|
349
349
|
// res19: IndexedSeq[String] = Vector("id", "status")
|
|
350
350
|
```
|
|
@@ -560,7 +560,7 @@ import zio.blocks.sql._
|
|
|
560
560
|
case class Item(id: Int, name: String, price: Option[BigDecimal]) derives DbCodec
|
|
561
561
|
|
|
562
562
|
val codec = DbCodec[Item]
|
|
563
|
-
// codec: DbCodec[Item] = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
563
|
+
// codec: DbCodec[Item] = zio.blocks.sql.DbCodecDeriver$$anon$10@25059cd7
|
|
564
564
|
|
|
565
565
|
codec.toDbValues(Item(1, "Widget", Some(BigDecimal("9.99"))))
|
|
566
566
|
// res29: IndexedSeq[DbValue] = Vector(
|
|
@@ -595,7 +595,7 @@ case class ProductId(value: String)
|
|
|
595
595
|
// Adapt the String codec to ProductId without a Schema
|
|
596
596
|
val productIdCodec: DbCodec[ProductId] =
|
|
597
597
|
DbCodec[String].transform(ProductId(_))(_.value)
|
|
598
|
-
// productIdCodec: DbCodec[ProductId] = zio.blocks.sql.DbCodec$$anon$1@
|
|
598
|
+
// productIdCodec: DbCodec[ProductId] = zio.blocks.sql.DbCodec$$anon$1@41471826
|
|
599
599
|
|
|
600
600
|
productIdCodec.columns
|
|
601
601
|
// res32: IndexedSeq[String] = Vector("value")
|
package/reference/sql/db-con.md
CHANGED
|
@@ -46,7 +46,7 @@ object User {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
val tx: Transactor = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
49
|
-
// tx: Transactor = zio.blocks.sql.JdbcTransactor@
|
|
49
|
+
// tx: Transactor = zio.blocks.sql.JdbcTransactor@1fecb11a
|
|
50
50
|
|
|
51
51
|
// DbCon is supplied automatically by connect — no explicit argument needed
|
|
52
52
|
tx.connect {
|
|
@@ -179,7 +179,7 @@ The following example shows reading the dialect from a context to render a `Frag
|
|
|
179
179
|
import zio.blocks.sql._
|
|
180
180
|
|
|
181
181
|
val tx: Transactor = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
182
|
-
// tx: Transactor = zio.blocks.sql.JdbcTransactor@
|
|
182
|
+
// tx: Transactor = zio.blocks.sql.JdbcTransactor@51223a09
|
|
183
183
|
|
|
184
184
|
tx.connect {
|
|
185
185
|
val frag = sql"SELECT id FROM users WHERE id = ${42}"
|
|
@@ -209,7 +209,7 @@ val loggingLogger: SqlLogger = new SqlLogger {
|
|
|
209
209
|
def onError(event: SqlLogger.ErrorEvent): Unit =
|
|
210
210
|
println(s"ERR [${event.duration.toMillis} ms]: ${event.sql} — ${event.error.getMessage}")
|
|
211
211
|
}
|
|
212
|
-
// loggingLogger: SqlLogger = repl.MdocSession$MdocApp7$$anon$9@
|
|
212
|
+
// loggingLogger: SqlLogger = repl.MdocSession$MdocApp7$$anon$9@192cce5a
|
|
213
213
|
|
|
214
214
|
val tx: Transactor =
|
|
215
215
|
new JdbcTransactor(
|
|
@@ -217,7 +217,7 @@ val tx: Transactor =
|
|
|
217
217
|
SqlDialect.SQLite,
|
|
218
218
|
loggingLogger
|
|
219
219
|
)
|
|
220
|
-
// tx: Transactor = zio.blocks.sql.JdbcTransactor@
|
|
220
|
+
// tx: Transactor = zio.blocks.sql.JdbcTransactor@7407235d
|
|
221
221
|
|
|
222
222
|
tx.connect {
|
|
223
223
|
// Every Frag execution notifies loggingLogger automatically
|
|
@@ -133,7 +133,7 @@ transactor.connect {
|
|
|
133
133
|
import zio.blocks.sql._
|
|
134
134
|
|
|
135
135
|
val transactor: Transactor = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
136
|
-
// transactor: Transactor = zio.blocks.sql.JdbcTransactor@
|
|
136
|
+
// transactor: Transactor = zio.blocks.sql.JdbcTransactor@4f5f053
|
|
137
137
|
|
|
138
138
|
var capturedCon: DbConnection = null
|
|
139
139
|
// capturedCon: DbConnection = null
|
package/reference/sql/db-tx.md
CHANGED
|
@@ -51,9 +51,9 @@ object User {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
val repo = Repo.derived[User, Int]("users", "id", _.id)
|
|
54
|
-
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@
|
|
54
|
+
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@789742a3
|
|
55
55
|
val tx = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
56
|
-
// tx: JdbcTransactor = zio.blocks.sql.JdbcTransactor@
|
|
56
|
+
// tx: JdbcTransactor = zio.blocks.sql.JdbcTransactor@5276be33
|
|
57
57
|
|
|
58
58
|
// On normal return: transaction commits and connection closes.
|
|
59
59
|
// On any exception: transaction rolls back, then the exception propagates.
|
package/reference/sql/ddl.md
CHANGED
|
@@ -33,7 +33,7 @@ Create a `ColumnDef` for each column, then pass them to `Ddl.createTable`:
|
|
|
33
33
|
import zio.blocks.sql._
|
|
34
34
|
|
|
35
35
|
val transactor: Transactor = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
36
|
-
// transactor: Transactor = zio.blocks.sql.JdbcTransactor@
|
|
36
|
+
// transactor: Transactor = zio.blocks.sql.JdbcTransactor@13b61c12
|
|
37
37
|
|
|
38
38
|
val columns = IndexedSeq(
|
|
39
39
|
ColumnDef("id", "INTEGER", nullable = false),
|
package/reference/sql/index.md
CHANGED
|
@@ -39,10 +39,10 @@ The core SQL module and the ZIO integration module publish separately. Add the a
|
|
|
39
39
|
```scala
|
|
40
40
|
// Core SQL module (cross-built for JVM and Scala.js; the JDBC-backed
|
|
41
41
|
// JdbcTransactor implementation itself is JVM-only)
|
|
42
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-sql" % "0.0.
|
|
42
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-sql" % "0.0.56"
|
|
43
43
|
|
|
44
44
|
// ZIO integration (lifts JDBC into ZIO effects; JVM-only)
|
|
45
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-sql-zio" % "0.0.
|
|
45
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-sql-zio" % "0.0.56"
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
Both modules require a JDBC driver on the classpath (for example, `org.xerial:sqlite-jdbc` for SQLite or `org.postgresql:postgresql` for PostgreSQL). Swap the JDBC URL and `SqlDialect` constant to switch databases.
|
|
@@ -144,9 +144,9 @@ object User {
|
|
|
144
144
|
|
|
145
145
|
// 1. Create transactor and repository
|
|
146
146
|
val tx = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
147
|
-
// tx: JdbcTransactor = zio.blocks.sql.JdbcTransactor@
|
|
147
|
+
// tx: JdbcTransactor = zio.blocks.sql.JdbcTransactor@ec75b64
|
|
148
148
|
val repo = Repo.derived[User, Int]("users", "id", _.id)
|
|
149
|
-
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@
|
|
149
|
+
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@41c4138d
|
|
150
150
|
|
|
151
151
|
// 2. Set up schema and run a transactional workflow
|
|
152
152
|
tx.transact {
|
|
@@ -200,7 +200,7 @@ object BlogPost {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
val repo = Repo.derived[BlogPost, Int]("post_id", _.id)
|
|
203
|
-
// repo: Repo[BlogPost, Int] = zio.blocks.sql.Repo$DerivedRepo@
|
|
203
|
+
// repo: Repo[BlogPost, Int] = zio.blocks.sql.Repo$DerivedRepo@6abcba30
|
|
204
204
|
repo.table.name
|
|
205
205
|
// res3: String = "blog_post"
|
|
206
206
|
repo.table.codec.columns
|
|
@@ -298,7 +298,7 @@ case class Order(id: Int, tags: List[String], metadata: Map[String, String]) der
|
|
|
298
298
|
|
|
299
299
|
// `tags` and `metadata` are encoded via DbCodec.jsonb when read/written through Frag/Repo
|
|
300
300
|
val codec = DbCodec[Order]
|
|
301
|
-
// codec: DbCodec[Order] = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
301
|
+
// codec: DbCodec[Order] = zio.blocks.sql.DbCodecDeriver$$anon$10@4d46abe5
|
|
302
302
|
codec.columns
|
|
303
303
|
// res12: IndexedSeq[String] = Vector("id", "tags", "metadata")
|
|
304
304
|
```
|
package/reference/sql/repo.md
CHANGED
|
@@ -49,9 +49,9 @@ object User {
|
|
|
49
49
|
|
|
50
50
|
// All SQL is generated here, once, from User's Schema.
|
|
51
51
|
val repo = Repo.derived[User, Int]("users", "id", _.id)
|
|
52
|
-
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@
|
|
52
|
+
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@c90e314
|
|
53
53
|
val tx = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
54
|
-
// tx: JdbcTransactor = zio.blocks.sql.JdbcTransactor@
|
|
54
|
+
// tx: JdbcTransactor = zio.blocks.sql.JdbcTransactor@7c7933b1
|
|
55
55
|
|
|
56
56
|
tx.transact {
|
|
57
57
|
repo.table.createTable(summon[DbTx].dialect).update // CREATE TABLE IF NOT EXISTS users …
|
|
@@ -116,7 +116,7 @@ object Article {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
val repo = Repo.derived[Article, Int]("id", _.id)
|
|
119
|
-
// repo: Repo[Article, Int] = zio.blocks.sql.Repo$DerivedRepo@
|
|
119
|
+
// repo: Repo[Article, Int] = zio.blocks.sql.Repo$DerivedRepo@4462dfed
|
|
120
120
|
repo.table.name
|
|
121
121
|
// res3: String = "article"
|
|
122
122
|
repo.table.codec.columns
|
|
@@ -150,7 +150,7 @@ object OrderLine {
|
|
|
150
150
|
|
|
151
151
|
// Overrides the default "order_line" table name with the legacy one
|
|
152
152
|
val repo = Repo.derived[OrderLine, Int]("tbl_order_lines", "line_id", _.lineId)
|
|
153
|
-
// repo: Repo[OrderLine, Int] = zio.blocks.sql.Repo$DerivedRepo@
|
|
153
|
+
// repo: Repo[OrderLine, Int] = zio.blocks.sql.Repo$DerivedRepo@7cda6782
|
|
154
154
|
repo.table.name
|
|
155
155
|
// res6: String = "tbl_order_lines"
|
|
156
156
|
```
|
|
@@ -185,7 +185,7 @@ object Tag {
|
|
|
185
185
|
|
|
186
186
|
// Inspects Tag's Schema, finds the unique Long field "id", maps it to column "id"
|
|
187
187
|
val repo = Repo.derived[Tag, Long]
|
|
188
|
-
// repo: Repo[Tag, Long] = zio.blocks.sql.Repo$DerivedRepo@
|
|
188
|
+
// repo: Repo[Tag, Long] = zio.blocks.sql.Repo$DerivedRepo@3cdba0a6
|
|
189
189
|
repo.idColumn
|
|
190
190
|
// res8: String = "id"
|
|
191
191
|
```
|
|
@@ -42,7 +42,7 @@ The dialect is available through `DbCon#dialect` inside a transaction:
|
|
|
42
42
|
import zio.blocks.sql._
|
|
43
43
|
|
|
44
44
|
val tx = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
45
|
-
// tx: JdbcTransactor = zio.blocks.sql.JdbcTransactor@
|
|
45
|
+
// tx: JdbcTransactor = zio.blocks.sql.JdbcTransactor@4f23e58f
|
|
46
46
|
|
|
47
47
|
tx.connect {
|
|
48
48
|
val dialect = summon[DbCon].dialect
|
|
@@ -38,7 +38,7 @@ val myLogger: SqlLogger = new SqlLogger {
|
|
|
38
38
|
def onError(event: SqlLogger.ErrorEvent): Unit =
|
|
39
39
|
println(s"FAIL: ${event.error.getMessage}")
|
|
40
40
|
}
|
|
41
|
-
// myLogger: SqlLogger = repl.MdocSession$MdocApp0$$anon$1@
|
|
41
|
+
// myLogger: SqlLogger = repl.MdocSession$MdocApp0$$anon$1@3ea7a988
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Pass the logger when creating a `JdbcTransactor`:
|
|
@@ -41,7 +41,7 @@ SqlNameMapper.Identity("firstName")
|
|
|
41
41
|
|
|
42
42
|
val upper = SqlNameMapper.Custom(_.toUpperCase)
|
|
43
43
|
// upper: Custom = Custom(
|
|
44
|
-
// repl.MdocSession$MdocApp0$$Lambda/
|
|
44
|
+
// repl.MdocSession$MdocApp0$$Lambda/0x000000003afd1000@5050da69
|
|
45
45
|
// )
|
|
46
46
|
upper("firstName")
|
|
47
47
|
// res4: String = "FIRSTNAME"
|
|
@@ -58,9 +58,9 @@ object Order { given schema: Schema[Order] = Schema.derived }
|
|
|
58
58
|
|
|
59
59
|
// Use UPPERCASE column names instead of snake_case
|
|
60
60
|
val upperDeriver = DbCodecDeriver.withColumnNameMapper(SqlNameMapper.Custom(_.toUpperCase))
|
|
61
|
-
// upperDeriver: DbCodecDeriver = zio.blocks.sql.DbCodecDeriver@
|
|
61
|
+
// upperDeriver: DbCodecDeriver = zio.blocks.sql.DbCodecDeriver@282873df
|
|
62
62
|
val codec: DbCodec[Order] = Order.schema.deriving(upperDeriver).derive
|
|
63
|
-
// codec: DbCodec[Order] = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
63
|
+
// codec: DbCodec[Order] = zio.blocks.sql.DbCodecDeriver$$anon$10@6838c076
|
|
64
64
|
codec.columns
|
|
65
65
|
// res6: IndexedSeq[String] = Vector("ORDERID", "TOTALAMOUNT")
|
|
66
66
|
```
|
|
@@ -80,7 +80,7 @@ import zio.blocks.sql.{Table, TableNamingPolicy}
|
|
|
80
80
|
val table1 = Table.derived[Product]
|
|
81
81
|
// table1: Table[Product] = Table(
|
|
82
82
|
// name = "product",
|
|
83
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
83
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@30880538,
|
|
84
84
|
// columnsMeta = Vector(
|
|
85
85
|
// ColumnMeta(name = "id", dbValue = DbInt(0), nullable = false),
|
|
86
86
|
// ColumnMeta(name = "name", dbValue = DbString(""), nullable = false),
|
|
@@ -94,7 +94,7 @@ table1.name
|
|
|
94
94
|
val table2 = Table.derived[Product](TableNamingPolicy.Plural)
|
|
95
95
|
// table2: Table[Product] = Table(
|
|
96
96
|
// name = "products",
|
|
97
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
97
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@504beffa,
|
|
98
98
|
// columnsMeta = Vector(
|
|
99
99
|
// ColumnMeta(name = "id", dbValue = DbInt(0), nullable = false),
|
|
100
100
|
// ColumnMeta(name = "name", dbValue = DbString(""), nullable = false),
|
|
@@ -108,7 +108,7 @@ table2.name
|
|
|
108
108
|
val table3 = Table.derived[Product](TableNamingPolicy.Custom("t_" + _))
|
|
109
109
|
// table3: Table[Product] = Table(
|
|
110
110
|
// name = "t_Product",
|
|
111
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
111
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@32e4f8e3,
|
|
112
112
|
// columnsMeta = Vector(
|
|
113
113
|
// ColumnMeta(name = "id", dbValue = DbInt(0), nullable = false),
|
|
114
114
|
// ColumnMeta(name = "name", dbValue = DbString(""), nullable = false),
|
package/reference/sql/table.md
CHANGED
|
@@ -46,7 +46,7 @@ object User {
|
|
|
46
46
|
val table = Table.derived[User]("users")
|
|
47
47
|
// table: Table[User] = Table(
|
|
48
48
|
// name = "users",
|
|
49
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
49
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@6651357c,
|
|
50
50
|
// columnsMeta = Vector(
|
|
51
51
|
// ColumnMeta(name = "id", dbValue = DbInt(0), nullable = false),
|
|
52
52
|
// ColumnMeta(name = "name", dbValue = DbString(""), nullable = false),
|
|
@@ -97,7 +97,7 @@ object BlogPost {
|
|
|
97
97
|
val table = Table.derived[BlogPost]
|
|
98
98
|
// table: Table[BlogPost] = Table(
|
|
99
99
|
// name = "blog_post",
|
|
100
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
100
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@6d450c2f,
|
|
101
101
|
// columnsMeta = Vector(
|
|
102
102
|
// ColumnMeta(name = "title", dbValue = DbString(""), nullable = false),
|
|
103
103
|
// ColumnMeta(name = "body", dbValue = DbString(""), nullable = false)
|
|
@@ -133,7 +133,7 @@ object UserProfile {
|
|
|
133
133
|
val table = Table.derived[UserProfile]("profiles")
|
|
134
134
|
// table: Table[UserProfile] = Table(
|
|
135
135
|
// name = "profiles",
|
|
136
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
136
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@55ca7a37,
|
|
137
137
|
// columnsMeta = Vector(
|
|
138
138
|
// ColumnMeta(name = "first_name", dbValue = DbString(""), nullable = false),
|
|
139
139
|
// ColumnMeta(name = "last_name", dbValue = DbString(""), nullable = false)
|
|
@@ -173,7 +173,7 @@ object Category {
|
|
|
173
173
|
val singular = Table.derived[Category](TableNamingPolicy.Singular)
|
|
174
174
|
// singular: Table[Category] = Table(
|
|
175
175
|
// name = "category",
|
|
176
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
176
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@b14761,
|
|
177
177
|
// columnsMeta = Vector(
|
|
178
178
|
// ColumnMeta(name = "name", dbValue = DbString(""), nullable = false)
|
|
179
179
|
// )
|
|
@@ -184,7 +184,7 @@ singular.name
|
|
|
184
184
|
val plural = Table.derived[Category](TableNamingPolicy.Plural)
|
|
185
185
|
// plural: Table[Category] = Table(
|
|
186
186
|
// name = "categories",
|
|
187
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
187
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@27c3ea48,
|
|
188
188
|
// columnsMeta = Vector(
|
|
189
189
|
// ColumnMeta(name = "name", dbValue = DbString(""), nullable = false)
|
|
190
190
|
// )
|
|
@@ -195,7 +195,7 @@ plural.name
|
|
|
195
195
|
val custom = Table.derived[Category](TableNamingPolicy.Custom(n => s"tbl_$n"))
|
|
196
196
|
// custom: Table[Category] = Table(
|
|
197
197
|
// name = "tbl_Category",
|
|
198
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
198
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@6e6a1e8c,
|
|
199
199
|
// columnsMeta = Vector(
|
|
200
200
|
// ColumnMeta(name = "name", dbValue = DbString(""), nullable = false)
|
|
201
201
|
// )
|
|
@@ -232,7 +232,7 @@ val meta = IndexedSeq(
|
|
|
232
232
|
val table = Table[Tag]("tag", DbCodec[Tag], meta)
|
|
233
233
|
// table: Table[Tag] = Table(
|
|
234
234
|
// name = "tag",
|
|
235
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
235
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@1b362cb8,
|
|
236
236
|
// columnsMeta = Vector(
|
|
237
237
|
// ColumnMeta(name = "id", dbValue = DbInt(0), nullable = false),
|
|
238
238
|
// ColumnMeta(name = "label", dbValue = DbString(""), nullable = false)
|
|
@@ -278,7 +278,7 @@ object OrderLine {
|
|
|
278
278
|
val table = Table.derived[OrderLine]
|
|
279
279
|
// table: Table[OrderLine] = Table(
|
|
280
280
|
// name = "order_line",
|
|
281
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
281
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@59d9d745,
|
|
282
282
|
// columnsMeta = Vector(
|
|
283
283
|
// ColumnMeta(name = "product_id", dbValue = DbInt(0), nullable = false),
|
|
284
284
|
// ColumnMeta(name = "quantity", dbValue = DbInt(0), nullable = false),
|
|
@@ -317,7 +317,7 @@ object Product {
|
|
|
317
317
|
val table = Table.derived[Product]
|
|
318
318
|
// table: Table[Product] = Table(
|
|
319
319
|
// name = "product",
|
|
320
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
320
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@13a46a35,
|
|
321
321
|
// columnsMeta = Vector(
|
|
322
322
|
// ColumnMeta(name = "sku", dbValue = DbString(""), nullable = false),
|
|
323
323
|
// ColumnMeta(name = "price", dbValue = DbBigDecimal(0), nullable = false),
|
|
@@ -366,7 +366,7 @@ object Session {
|
|
|
366
366
|
val table = Table.derived[Session]
|
|
367
367
|
// table: Table[Session] = Table(
|
|
368
368
|
// name = "session",
|
|
369
|
-
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
369
|
+
// codec = zio.blocks.sql.DbCodecDeriver$$anon$10@72e9a985,
|
|
370
370
|
// columnsMeta = Vector(
|
|
371
371
|
// ColumnMeta(name = "token", dbValue = DbString(""), nullable = false),
|
|
372
372
|
// ColumnMeta(name = "user_id", dbValue = DbInt(0), nullable = false)
|
|
@@ -95,7 +95,7 @@ val transactorLayer: ZLayer[Any, Nothing, TransactorZIO] =
|
|
|
95
95
|
Add the `zio-blocks-sql-zio` artifact to your build. It depends on `zio-blocks-sql`, so you do not need to declare both:
|
|
96
96
|
|
|
97
97
|
```scala
|
|
98
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-sql-zio" % "0.0.
|
|
98
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-sql-zio" % "0.0.56"
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
The artifact is JVM-only and requires Scala 3.
|
|
@@ -125,7 +125,7 @@ import zio.blocks.sql._
|
|
|
125
125
|
// Without credentials — useful for SQLite or URL-embedded auth
|
|
126
126
|
val sqlite: JdbcTransactor =
|
|
127
127
|
JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
128
|
-
// sqlite: JdbcTransactor = zio.blocks.sql.JdbcTransactor@
|
|
128
|
+
// sqlite: JdbcTransactor = zio.blocks.sql.JdbcTransactor@fa1ea01
|
|
129
129
|
```
|
|
130
130
|
|
|
131
131
|
Use the three-argument overload when the database requires a username and password supplied separately:
|
|
@@ -141,7 +141,7 @@ val postgres: JdbcTransactor =
|
|
|
141
141
|
"secret",
|
|
142
142
|
SqlDialect.PostgreSQL
|
|
143
143
|
)
|
|
144
|
-
// postgres: JdbcTransactor = zio.blocks.sql.JdbcTransactor@
|
|
144
|
+
// postgres: JdbcTransactor = zio.blocks.sql.JdbcTransactor@6fff1b52
|
|
145
145
|
```
|
|
146
146
|
|
|
147
147
|
:::caution
|
|
@@ -252,12 +252,12 @@ case class User(id: Int, name: String, email: String)
|
|
|
252
252
|
object User { implicit val schema: Schema[User] = Schema.derived }
|
|
253
253
|
|
|
254
254
|
implicit val userCodec: DbCodec[User] = User.schema.deriving(DbCodecDeriver).derive
|
|
255
|
-
// userCodec: DbCodec[User] = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
255
|
+
// userCodec: DbCodec[User] = zio.blocks.sql.DbCodecDeriver$$anon$10@74798ce9
|
|
256
256
|
|
|
257
257
|
val repo = Repo.derived[User, Int]("users", "id", _.id)
|
|
258
|
-
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@
|
|
258
|
+
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@25a2fe55
|
|
259
259
|
val transactor = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
260
|
-
// transactor: JdbcTransactor = zio.blocks.sql.JdbcTransactor@
|
|
260
|
+
// transactor: JdbcTransactor = zio.blocks.sql.JdbcTransactor@57b2f789
|
|
261
261
|
|
|
262
262
|
transactor.transact {
|
|
263
263
|
repo.table.createTable(summon[DbTx].dialect).update
|
|
@@ -333,12 +333,12 @@ case class User(id: Int, name: String, email: String)
|
|
|
333
333
|
object User { implicit val schema: Schema[User] = Schema.derived }
|
|
334
334
|
|
|
335
335
|
implicit val userCodec: DbCodec[User] = User.schema.deriving(DbCodecDeriver).derive
|
|
336
|
-
// userCodec: DbCodec[User] = zio.blocks.sql.DbCodecDeriver$$anon$10@
|
|
336
|
+
// userCodec: DbCodec[User] = zio.blocks.sql.DbCodecDeriver$$anon$10@3454ab4b
|
|
337
337
|
|
|
338
338
|
val repo = Repo.derived[User, Int]("users", "id", _.id)
|
|
339
|
-
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@
|
|
339
|
+
// repo: Repo[User, Int] = zio.blocks.sql.Repo$DerivedRepo@bab4308
|
|
340
340
|
val transactor = JdbcTransactor.fromUrl("jdbc:sqlite::memory:", SqlDialect.SQLite)
|
|
341
|
-
// transactor: JdbcTransactor = zio.blocks.sql.JdbcTransactor@
|
|
341
|
+
// transactor: JdbcTransactor = zio.blocks.sql.JdbcTransactor@74ce711c
|
|
342
342
|
|
|
343
343
|
// Helper that composes two Repo calls — requires only DbCon, not Transactor
|
|
344
344
|
def upsertUser(user: User)(using DbCon): Unit = {
|
package/reference/sql-zio.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: sql-zio
|
|
3
|
-
title: "
|
|
3
|
+
title: "ZIO Integration"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
`zio-blocks-sql-zio` is the ZIO adapter for `zio-blocks-sql`. It wraps the
|
|
@@ -16,7 +16,7 @@ and effect-aware methods. For a full method-by-method reference on
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
18
18
|
```scala
|
|
19
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-sql-zio" % "0.0.
|
|
19
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-sql-zio" % "0.0.56"
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Quick Start
|
|
@@ -126,9 +126,9 @@ This is the most common pipeline constructor:
|
|
|
126
126
|
import zio.blocks.streams.*
|
|
127
127
|
|
|
128
128
|
val doubler = Pipeline.map[Int, Int](_ * 2)
|
|
129
|
-
// doubler: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$MapPipeline@
|
|
129
|
+
// doubler: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$MapPipeline@7812cfb3
|
|
130
130
|
val toStr = Pipeline.map[Int, String](_.toString)
|
|
131
|
-
// toStr: Pipeline[Int, String] = zio.blocks.streams.Pipeline$MapPipeline@
|
|
131
|
+
// toStr: Pipeline[Int, String] = zio.blocks.streams.Pipeline$MapPipeline@2eb14e30
|
|
132
132
|
|
|
133
133
|
val result = Stream(1, 2, 3).via(doubler).runCollect
|
|
134
134
|
// result: Either[Nothing, Chunk[Int]] = Right(IndexedSeq(2, 4, 6))
|
|
@@ -151,10 +151,10 @@ import zio.blocks.async.*
|
|
|
151
151
|
import zio.blocks.streams.*
|
|
152
152
|
|
|
153
153
|
val lookup = Pipeline.mapAsync[Int, String](id => Async.succeed(s"user-$id"))
|
|
154
|
-
// lookup: Pipeline[Int, String] = zio.blocks.streams.Pipeline$$anon$4@
|
|
154
|
+
// lookup: Pipeline[Int, String] = zio.blocks.streams.Pipeline$$anon$4@6ff83c57
|
|
155
155
|
|
|
156
156
|
val result = Stream(1, 2, 3).via(lookup).runCollectAsync
|
|
157
|
-
// result: Async[Either[Nothing, Chunk[String]]] = zio.blocks.async.Async$slowPath$FoldCausePollable@
|
|
157
|
+
// result: Async[Either[Nothing, Chunk[String]]] = zio.blocks.async.Async$slowPath$FoldCausePollable@23bc9013
|
|
158
158
|
```
|
|
159
159
|
|
|
160
160
|
### `Pipeline.filter[A]` — Keep Matching Elements
|
|
@@ -173,7 +173,7 @@ Note that the output type is the same as the input type — filtering does not c
|
|
|
173
173
|
import zio.blocks.streams.*
|
|
174
174
|
|
|
175
175
|
val positives = Pipeline.filter[Int](_ > 0)
|
|
176
|
-
// positives: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$FilterPipeline@
|
|
176
|
+
// positives: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$FilterPipeline@536fca6a
|
|
177
177
|
|
|
178
178
|
val result = Stream(-2, -1, 0, 1, 2).via(positives).runCollect
|
|
179
179
|
// result: Either[Nothing, Chunk[Int]] = Right(IndexedSeq(1, 2))
|
|
@@ -196,10 +196,10 @@ import zio.blocks.async.*
|
|
|
196
196
|
import zio.blocks.streams.*
|
|
197
197
|
|
|
198
198
|
val allowed = Pipeline.filterAsync[Int](n => Async.succeed(n % 3 == 0))
|
|
199
|
-
// allowed: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$$anon$2@
|
|
199
|
+
// allowed: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$$anon$2@6e07367b
|
|
200
200
|
|
|
201
201
|
val result = Stream(1, 2, 3, 4, 5, 6).via(allowed).runCollectAsync
|
|
202
|
-
// result: Async[Either[Nothing, Chunk[Int]]] = zio.blocks.async.Async$slowPath$FoldCausePollable@
|
|
202
|
+
// result: Async[Either[Nothing, Chunk[Int]]] = zio.blocks.async.Async$slowPath$FoldCausePollable@6ac76f8d
|
|
203
203
|
```
|
|
204
204
|
|
|
205
205
|
### `Pipeline.collect[A, B]` — Partial Function Transformation
|
|
@@ -218,7 +218,7 @@ Use `collect` when you need to filter and transform simultaneously:
|
|
|
218
218
|
import zio.blocks.streams.*
|
|
219
219
|
|
|
220
220
|
val extractInts = Pipeline.collect[Any, Int] { case n: Int => n }
|
|
221
|
-
// extractInts: Pipeline[Any, Int] = zio.blocks.streams.Pipeline$CollectPipeline@
|
|
221
|
+
// extractInts: Pipeline[Any, Int] = zio.blocks.streams.Pipeline$CollectPipeline@2b6f73e7
|
|
222
222
|
|
|
223
223
|
val result = Stream(1, "a", 2, "b", 3).via(extractInts).runCollect
|
|
224
224
|
// result: Either[Nothing, Chunk[Int]] = Right(IndexedSeq(1, 2, 3))
|
|
@@ -243,10 +243,10 @@ import zio.blocks.streams.*
|
|
|
243
243
|
val parsePort = Pipeline.collectAsync[String, Int] { raw =>
|
|
244
244
|
Async.succeed(raw.toIntOption.filter(p => p > 0 && p <= 65535))
|
|
245
245
|
}
|
|
246
|
-
// parsePort: Pipeline[String, Int] = zio.blocks.streams.Pipeline$$anon$1@
|
|
246
|
+
// parsePort: Pipeline[String, Int] = zio.blocks.streams.Pipeline$$anon$1@2452cef
|
|
247
247
|
|
|
248
248
|
val result = Stream("80", "not-a-port", "8080", "99999").via(parsePort).runCollectAsync
|
|
249
|
-
// result: Async[Either[Nothing, Chunk[Int]]] = zio.blocks.async.Async$slowPath$FoldCausePollable@
|
|
249
|
+
// result: Async[Either[Nothing, Chunk[Int]]] = zio.blocks.async.Async$slowPath$FoldCausePollable@3501e962
|
|
250
250
|
```
|
|
251
251
|
|
|
252
252
|
### `Pipeline.take[A]` — First N Elements
|
|
@@ -265,7 +265,7 @@ This naturally short-circuits — upstream stops producing once `n` elements hav
|
|
|
265
265
|
import zio.blocks.streams.*
|
|
266
266
|
|
|
267
267
|
val firstFive = Pipeline.take[Int](5)
|
|
268
|
-
// firstFive: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$TakePipeline@
|
|
268
|
+
// firstFive: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$TakePipeline@4393dd60
|
|
269
269
|
|
|
270
270
|
val result = Stream.range(0, 1000).via(firstFive).runCollect
|
|
271
271
|
// result: Either[Nothing, Chunk[Int]] = Right(IndexedSeq(0, 1, 2, 3, 4))
|
|
@@ -287,7 +287,7 @@ Use `drop` to skip headers, metadata, or warm-up elements:
|
|
|
287
287
|
import zio.blocks.streams.*
|
|
288
288
|
|
|
289
289
|
val skipHeader = Pipeline.drop[String](1)
|
|
290
|
-
// skipHeader: Pipeline[String, String] = zio.blocks.streams.Pipeline$DropPipeline@
|
|
290
|
+
// skipHeader: Pipeline[String, String] = zio.blocks.streams.Pipeline$DropPipeline@5842a009
|
|
291
291
|
|
|
292
292
|
val result = Stream("header", "row1", "row2").via(skipHeader).runCollect
|
|
293
293
|
// result: Either[Nothing, Chunk[String]] = Right(IndexedSeq("row1", "row2"))
|
|
@@ -309,7 +309,7 @@ You rarely construct `identity` explicitly, but it is important as a base case i
|
|
|
309
309
|
import zio.blocks.streams.*
|
|
310
310
|
|
|
311
311
|
val noOp = Pipeline.identity[Int]
|
|
312
|
-
// noOp: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$$anon$3@
|
|
312
|
+
// noOp: Pipeline[Int, Int] = zio.blocks.streams.Pipeline$$anon$3@4adb1db2
|
|
313
313
|
|
|
314
314
|
// These are equivalent:
|
|
315
315
|
// stream.via(noOp) == stream
|
|
@@ -392,7 +392,7 @@ import zio.blocks.streams.*
|
|
|
392
392
|
val cleanSensorData: Pipeline[Double, Double] =
|
|
393
393
|
Pipeline.filter[Double](d => !d.isNaN && !d.isInfinite)
|
|
394
394
|
.andThen(Pipeline.filter(d => d >= -100.0 && d <= 100.0))
|
|
395
|
-
// cleanSensorData: Pipeline[Double, Double] = zio.blocks.streams.Pipeline$Composed@
|
|
395
|
+
// cleanSensorData: Pipeline[Double, Double] = zio.blocks.streams.Pipeline$Composed@3eef15c8
|
|
396
396
|
|
|
397
397
|
// Apply to different sensor streams
|
|
398
398
|
val sensorStream1 = Stream(45.5, 67.2, Double.NaN, 23.1)
|
|
@@ -443,13 +443,13 @@ import zio.blocks.streams.*
|
|
|
443
443
|
|
|
444
444
|
// A pipeline that normalizes strings
|
|
445
445
|
val normalize = Pipeline.map[String, String](_.trim.toLowerCase)
|
|
446
|
-
// normalize: Pipeline[String, String] = zio.blocks.streams.Pipeline$MapPipeline@
|
|
446
|
+
// normalize: Pipeline[String, String] = zio.blocks.streams.Pipeline$MapPipeline@6b47f596
|
|
447
447
|
|
|
448
448
|
// Apply to different sinks
|
|
449
449
|
val collectNormalized = normalize.andThenSink(Sink.collectAll[String])
|
|
450
|
-
// collectNormalized: Sink[Nothing, String, Chunk[String]] = zio.blocks.streams.Sink$Contramapped@
|
|
450
|
+
// collectNormalized: Sink[Nothing, String, Chunk[String]] = zio.blocks.streams.Sink$Contramapped@5198142e
|
|
451
451
|
val countNormalized = normalize.andThenSink(Sink.count)
|
|
452
|
-
// countNormalized: Sink[Nothing, String, Long] = zio.blocks.streams.Sink$Contramapped@
|
|
452
|
+
// countNormalized: Sink[Nothing, String, Long] = zio.blocks.streams.Sink$Contramapped@3effe2fa
|
|
453
453
|
|
|
454
454
|
val result = Stream(" Hello ", " WORLD ").run(collectNormalized)
|
|
455
455
|
// result: Either[Nothing, Chunk[String]] = Right(IndexedSeq("hello", "world"))
|
|
@@ -473,7 +473,7 @@ import zio.blocks.streams._
|
|
|
473
473
|
val sink: Sink[String, Int, Long] =
|
|
474
474
|
if (false) Sink.count
|
|
475
475
|
else Sink.fail("not ready")
|
|
476
|
-
// sink: Sink[String, Int, Long] = zio.blocks.streams.Sink$$anon$7@
|
|
476
|
+
// sink: Sink[String, Int, Long] = zio.blocks.streams.Sink$$anon$7@43056e8d
|
|
477
477
|
|
|
478
478
|
val result = Stream(1, 2, 3).run(sink)
|
|
479
479
|
// result: Either[String, Long] = Left("not ready")
|
|
@@ -618,7 +618,7 @@ import zio.blocks.streams._
|
|
|
618
618
|
// A sink that counts the length of strings
|
|
619
619
|
val totalLength: Sink[Nothing, String, Long] =
|
|
620
620
|
Sink.sumInt.contramap[Int, String](_.length)
|
|
621
|
-
// totalLength: Sink[Nothing, String, Long] = zio.blocks.streams.Sink$Contramapped@
|
|
621
|
+
// totalLength: Sink[Nothing, String, Long] = zio.blocks.streams.Sink$Contramapped@73659487
|
|
622
622
|
|
|
623
623
|
val result = Stream("hello", "world").run(totalLength)
|
|
624
624
|
// result: Either[Nothing, Long] = Right(10L)
|
|
@@ -641,7 +641,7 @@ import zio.blocks.streams._
|
|
|
641
641
|
|
|
642
642
|
val countAsString: Sink[Nothing, Any, String] =
|
|
643
643
|
Sink.count.map(n => s"Total: $n elements")
|
|
644
|
-
// countAsString: Sink[Nothing, Any, String] = zio.blocks.streams.Sink$Mapped@
|
|
644
|
+
// countAsString: Sink[Nothing, Any, String] = zio.blocks.streams.Sink$Mapped@3164630
|
|
645
645
|
|
|
646
646
|
val result = Stream(1, 2, 3).run(countAsString)
|
|
647
647
|
// result: Either[Nothing, String] = Right("Total: 3 elements")
|
|
@@ -772,7 +772,7 @@ import zio.blocks.chunk.Chunk
|
|
|
772
772
|
val cleanAndCollect: Sink[Nothing, String, Chunk[String]] =
|
|
773
773
|
Pipeline.map[String, String](_.trim.toLowerCase)
|
|
774
774
|
.andThenSink(Sink.collectAll[String])
|
|
775
|
-
// cleanAndCollect: Sink[Nothing, String, Chunk[String]] = zio.blocks.streams.Sink$Contramapped@
|
|
775
|
+
// cleanAndCollect: Sink[Nothing, String, Chunk[String]] = zio.blocks.streams.Sink$Contramapped@6cb23b20
|
|
776
776
|
|
|
777
777
|
val result = Stream(" Hello ", " WORLD ").run(cleanAndCollect)
|
|
778
778
|
// result: Either[Nothing, Chunk[String]] = Right(IndexedSeq("hello", "world"))
|