In order to allow a ResultSet to be consumed by an Observable, a ResultSet iterator must be created.
Quill context that executes JDBC queries inside of ZIO.
Quill context that executes JDBC queries inside of ZIO. Unlike most other contexts
that require passing in a Data Source, this context takes in a java.sql.Connection
as a resource dependency which can be provided later (see ZioJdbc
for helper methods
that assist in doing this).
The resource dependency itself is just a Has[Connection]
. Since this is frequently used
The type QIO[T]
i.e. Quill-IO has been defined as an alias for ZIO[Has[Connection], SQLException, T]
.
Since in most JDBC use-cases, a connection-pool datasource i.e. Hikari is used it would actually
be much more useful to interact with ZIO[Has[DataSource], SQLException, T]
.
The extension method .onDataSource
in io.getquill.context.ZioJdbc.QuillZioExt
will perform this conversion
(for even more brevity use onDS
which is an alias for this method).
{{
import ZioJdbc._
val zioDs = DataSourceLayer.fromPrefix("testPostgresDB")
MyZioContext.run(query[Person]).onDataSource.provideCustomLayer(zioDS)
}}
If you are using a Plain Scala app however, you will need to manually run it e.g. using zio.Runtime {{ Runtime.default.unsafeRun(MyZioContext.run(query[Person]).provideLayer(zioDS)) }}
Note however that the one exception to these cases are the prepare
methods where a ZIO[Has[Connection], SQLException, PreparedStatement]
is being returned. In those situations the acquire-action-release pattern does not make any sense because the PrepareStatement
is only held open while it's host-connection exists.
In order to allow a ResultSet to be consumed by an Observable, a ResultSet iterator must be created. Since Quill provides a extractor for an individual ResultSet row, a single row can easily be cached in memory. This allows for a straightforward implementation of a hasNext method.