ZioJdbcContext
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]).ContextTranslateProtoprovideLayer(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.
Value members
Concrete methods
- Definition Classes
- ZioContext -> ProtoContext
- Definition Classes
- ZioPrepareContext -> ContextVerbPrepare
- Definition Classes
- ZioPrepareContext -> ContextVerbPrepare
- Definition Classes
- ZioPrepareContext -> ContextVerbPrepare
Execute instructions in a transaction. For example, to add a Person row to the database and return the contents of the Person table immediately after that:
Execute instructions in a transaction. For example, to add a Person row to the database and return the contents of the Person table immediately after that:
val a = run(query[Person].insert(Person(...)): ZIO[Has[DataSource], SQLException, Long]
val b = run(query[Person]): ZIO[Has[DataSource], SQLException, Person]
transaction(a *> b): ZIO[Has[DataSource], SQLException, Person]
The order of operations run in the case that a new connection needs to be aquired are as follows:
getDS from env, acquire-connection, set-no-autocommit(connection), put-into-fiberref(connection), op - the corresponding execute_ method which will execute and pull connection from the fiberref, remove-from-fiberref(connection), set-prev-autocommit(connection), release-conn
- Definition Classes
- ContextTranslateProto
- Definition Classes
- ContextTranslateProto
Inherited methods
Internal API that cannot be made private due to how inline functions
Internal API that cannot be made private due to how inline functions
- Inherited from
- ContextVerbStream
Internal API that cannot be made private due to how inline functions
Internal API that cannot be made private due to how inline functions
- Inherited from
- ContextTranslateMacro
- Inherited from
- EncodingDsl
- Inherited from
- EncodingDsl
Parses instances of java.sql.Types to string form so it can be used in creation of sql arrays. Some databases does not support each of generic types, hence it's welcome to override this method and provide alternatives to non-existent types.
Parses instances of java.sql.Types to string form so it can be used in creation of sql arrays. Some databases does not support each of generic types, hence it's welcome to override this method and provide alternatives to non-existent types.
- Value Params
- intType
one of java.sql.Types
- Returns
JDBC type in string form
- Inherited from
- JdbcContextTypes
- Inherited from
- ContextVerbPrepare
Execute SQL on connection and return prepared statement. Closes the statement in a bracket.
Execute SQL on connection and return prepared statement. Closes the statement in a bracket.
- Inherited from
- ZioPrepareContext
- Definition Classes
- ZioTranslateContext -> ContextTranslateProto
- Inherited from
- ZioTranslateContext
- Definition Classes
- ZioTranslateContext -> ContextTranslateProto
- Inherited from
- ZioTranslateContext
- Inherited from
- ContextTranslateMacro
- Inherited from
- ContextTranslateMacro
- Inherited from
- ContextTranslateMacro
- Inherited from
- ContextTranslateMacro
- Inherited from
- ContextTranslateMacro
- Inherited from
- ContextTranslateMacro
- Inherited from
- ContextTranslateMacro
- Inherited from
- ContextTranslateProto
Abstract fields
Concrete fields
Inherited fields
Extensions
Inherited extensions
When using this with FilterColumns make sure it comes FIRST. Otherwise the columns are you filtering may have been nullified in the SQL before the filteration has actually happened.
When using this with FilterColumns make sure it comes FIRST. Otherwise the columns are you filtering may have been nullified in the SQL before the filteration has actually happened.
- Inherited from
- Context