ZioJdbcContext

abstract class ZioJdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] extends ZioContext[Dialect, Naming] with JdbcContextTypes[Dialect, Naming] with ProtoContextSecundus[Dialect, Naming] with ContextVerbStream[Dialect, Naming] with ZioPrepareContext[Dialect, Naming] with ZioTranslateContext[Dialect, Naming]

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 = Quill.DataSource.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.

trait ZioTranslateContext[Dialect, Naming]
trait ContextTranslateMacro[Dialect, Naming]
trait ContextTranslateProto[Dialect, Naming]
trait ZioPrepareContext[Dialect, Naming]
trait ContextVerbPrepare[Dialect, Naming]
trait JdbcContextTypes[Dialect, Naming]
trait Decoders
trait Encoders
trait SqlContext[Dialect, Naming]
trait ZioContext[Dialect, Naming]
trait ContextVerbStream[Dialect, Naming]
trait ProtoStreamContext[Dialect, Naming]
trait Context[Dialect, Naming]
trait Closeable
trait AutoCloseable
trait EncodingDsl
trait LowPriorityImplicits
trait ProtoContextSecundus[Dialect, Naming]
trait RowContext
class Object
trait Matchable
class Any

Type members

Inherited classlikes

case class BatchGroup(string: String, prepare: List[Prepare])
Inherited from:
RowContext
case class BatchGroupReturning(string: String, returningBehavior: ReturnAction, prepare: List[Prepare])
Inherited from:
RowContext
Inherited from:
Context
case class JdbcDecoder[T](decoder: () => T) extends BaseDecoder[T]
Inherited from:
Decoders
case class JdbcEncoder[T](sqlType: Int, encoder: () => T) extends BaseEncoder[T]
Inherited from:
Encoders
class JdbcNullChecker extends BaseNullChecker
Inherited from:
JdbcContextTypes

Types

override type Environment = DataSource
override type Error = SQLException
override type PrepareRow = PreparedStatement
override type Result[T] = ZIO[Environment, Error, T]
override type ResultRow = ResultSet
override type RunActionResult = Long
override type RunActionReturningResult[T] = T
override type RunBatchActionResult = List[Long]
override type RunBatchActionReturningResult[T] = List[T]
override type RunQueryResult[T] = List[T]
override type RunQuerySingleResult[T] = T
override type Runner = Unit
override type Session = Connection
override type StreamResult[T] = ZStream[Environment, Error, T]
override type TranslateResult[T] = ZIO[Environment, Error, T]
override type TranslateRunner = Unit

Inherited types

type BaseDecoder[T] = GenericDecoder[ResultRow, Session, T, Specific]
Inherited from:
EncodingDsl
type BaseEncoder[T] = GenericEncoder[T, PrepareRow, Session]
Inherited from:
EncodingDsl
type BaseNullChecker = GenericNullChecker[ResultRow, Session]
Inherited from:
EncodingDsl
type ColumnResolver = GenericColumnResolver[ResultRow]
Inherited from:
EncodingDsl
type Decoder[T] = JdbcDecoder[T]
Inherited from:
Decoders
type DecoderMethod[T] = (Int, ResultRow, Session) => T
Inherited from:
EncodingDsl
type Encoder[T] = JdbcEncoder[T]
Inherited from:
Encoders
type EncoderMethod[T] = (Int, T, PrepareRow, Session) => PrepareRow
Inherited from:
EncodingDsl
type Extractor[T] = (ResultRow, Session) => T
Inherited from:
RowContext
type Index = Int
Inherited from:
JdbcContextTypes
Inherited from:
JdbcContextTypes
type Prepare = (PrepareRow, Session) => (List[Any], PrepareRow)
Inherited from:
RowContext
type RowTyper[T] = GenericRowTyper[ResultRow, T]
Inherited from:
EncodingDsl
type RunnerBehavior <: RunnerSummoningBehavior
Inherited from:
ContextTranslateMacro

Value members

Concrete methods

override def close(): Unit
Definition Classes
Context -> Closeable -> AutoCloseable
override protected def context: Runner
Definition Classes
Context
def executeAction(sql: String, prepare: Prepare)(info: ExecutionInfo, dc: Runner): QIO[Long]
def executeActionReturning[O](sql: String, prepare: Prepare, extractor: () => O, returningBehavior: ReturnAction)(info: ExecutionInfo, dc: Runner): QIO[O]
def executeActionReturningMany[O](sql: String, prepare: Prepare, extractor: () => O, returningBehavior: ReturnAction)(info: ExecutionInfo, dc: Runner): QIO[List[O]]
def executeBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): QIO[List[Long]]
def executeBatchActionReturning[T](groups: List[BatchGroupReturning], extractor: () => T)(info: ExecutionInfo, dc: Runner): QIO[List[T]]
def executeQuery[T](sql: String, prepare: Prepare, extractor: () => T)(info: ExecutionInfo, dc: Runner): QIO[List[T]]
override def executeQuerySingle[T](sql: String, prepare: Prepare, extractor: () => T)(info: ExecutionInfo, dc: Runner): QIO[T]
Definition Classes
ZioContext -> ProtoContextSecundus
override def prepareAction(sql: String, prepare: Prepare)(info: ExecutionInfo, dc: Runner): QCIO[PreparedStatement]
Definition Classes
ZioPrepareContext -> ContextVerbPrepare
override def prepareBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): QCIO[List[PreparedStatement]]
Definition Classes
ZioPrepareContext -> ContextVerbPrepare
override def prepareQuery(sql: String, prepare: Prepare)(info: ExecutionInfo, dc: Runner): QCIO[PreparedStatement]
Definition Classes
ZioPrepareContext -> ContextVerbPrepare
@targetName("runQueryDefault")
inline def run[T](inline quoted: Quoted[Query[T]]): ZIO[DataSource, SQLException, List[T]]
@targetName("runQuery")
inline def run[T](inline quoted: Quoted[Query[T]], inline wrap: OuterSelectWrap): ZIO[DataSource, SQLException, List[T]]
@targetName("runQuerySingle")
inline def run[T](inline quoted: Quoted[T]): ZIO[DataSource, SQLException, T]
@targetName("runAction")
inline def run[E](inline quoted: Quoted[Action[E]]): ZIO[DataSource, SQLException, Long]
@targetName("runActionReturning")
inline def run[E, T](inline quoted: Quoted[ActionReturning[E, T]]): ZIO[DataSource, SQLException, T]
@targetName("runActionReturningMany")
inline def run[E, T](inline quoted: Quoted[ActionReturning[E, List[T]]]): ZIO[DataSource, SQLException, List[T]]
@targetName("runBatchAction")
inline def run[I, A <: Action[I] & QAC[I, Nothing]](inline quoted: Quoted[BatchAction[A]], rowsPerBatch: Int): ZIO[DataSource, SQLException, List[Long]]
@targetName("runBatchActionDefault")
inline def run[I, A <: Action[I] & QAC[I, Nothing]](inline quoted: Quoted[BatchAction[A]]): ZIO[DataSource, SQLException, List[Long]]
@targetName("runBatchActionReturning")
inline def run[I, T, A <: Action[I] & QAC[I, T]](inline quoted: Quoted[BatchAction[A]], rowsPerBatch: Int): ZIO[DataSource, SQLException, List[T]]
@targetName("runBatchActionReturningDefault")
inline def run[I, T, A <: Action[I] & QAC[I, T]](inline quoted: Quoted[BatchAction[A]]): ZIO[DataSource, SQLException, List[T]]
def streamQuery[T](fetchSize: Option[Int], sql: String, prepare: Prepare, extractor: () => T)(info: ExecutionInfo, dc: Runner): QStream[T]
def transaction[R <: DataSource, A](op: ZIO[R, Throwable, A]): ZIO[R, Throwable, A]

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
override def translateBatchQueryEndpoint(groups: List[BatchGroup], prettyPrint: Boolean)(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[List[String]]
Definition Classes
ContextTranslateProto
override def translateQueryEndpoint[T](statement: String, prepare: Prepare, extractor: () => T, prettyPrint: Boolean)(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[String]
Definition Classes
ContextTranslateProto

Inherited methods

inline def _streamInternal[T](inline quoted: Quoted[Query[T]], fetchSize: Option[Int]): StreamResult[T]

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
Inherited from:
ContextVerbPrepare

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
def decoder[T](f: ResultRow => Index => T): JdbcDecoder[T]
Inherited from:
Decoders
def decoder[T](d: (Int, ResultRow, Session) => T): JdbcDecoder[T]
Inherited from:
Decoders
def encoder[T](sqlType: Int, f: PrepareRow => (Index, T) => Unit): JdbcEncoder[T]
Inherited from:
Encoders
def encoder[T](sqlType: Int, f: (Index, T, PrepareRow) => Unit): JdbcEncoder[T]
Inherited from:
Encoders
protected def handleSingleResult[T](sql: String, list: List[T]): T
Inherited from:
Context
def idiom: Dialect
Inherited from:
ProtoContextSecundus
inline def lift[T](inline runtimeValue: T): T
Inherited from:
Context
inline def liftQuery[U <: (Iterable), T](inline runtimeValue: U[T]): Query[T]
Inherited from:
Context
protected def mappedBaseDecoder[Base, Mapped](mapped: MappedEncoding[Base, Mapped], decoder: () => Base): () => Mapped
Inherited from:
EncodingDsl
protected def mappedBaseEncoder[Mapped, Base](mapped: MappedEncoding[Mapped, Base], encoder: () => Base): () => Mapped
Inherited from:
EncodingDsl
def naming: Naming
Inherited from:
ProtoContextSecundus
def parseJdbcType(intType: Int): String

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 parameters:
intType

one of java.sql.Types

Returns:

JDBC type in string form

Inherited from:
JdbcContextTypes
@targetName("runPrepareBatchAction")
inline def prepare[I, A <: Action[I] & QAC[I, Nothing]](inline quoted: Quoted[BatchAction[A]]): PrepareBatchActionResult
Inherited from:
ContextVerbPrepare
@targetName("runPrepareAction")
inline def prepare[E](inline quoted: Quoted[Action[E]]): PrepareActionResult
Inherited from:
ContextVerbPrepare
@targetName("runPrepareQuerySingle")
inline def prepare[T](inline quoted: Quoted[T]): PrepareQueryResult
Inherited from:
ContextVerbPrepare
@targetName("runPrepareQuery")
inline def prepare[T](inline quoted: Quoted[Query[T]]): PrepareQueryResult
Inherited from:
ContextVerbPrepare
@tailrec
final protected def prepareParam(param: Any): String
Inherited from:
ContextTranslateProto
def prepareSingle(sql: String, prepare: Prepare)(info: ExecutionInfo, dc: Runner): QCIO[PreparedStatement]

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
override def push[A, B](result: TranslateResult[A])(f: A => B): TranslateResult[B]
Definition Classes
ZioTranslateContext -> ContextTranslateProto
Inherited from:
ZioTranslateContext
override def seq[A](list: List[TranslateResult[A]]): TranslateResult[List[A]]
Definition Classes
ZioTranslateContext -> ContextTranslateProto
Inherited from:
ZioTranslateContext
@targetName("streamQueryWithFetchSize")
inline def stream[T](inline quoted: Quoted[Query[T]], fetchSize: Int): StreamResult[T]
Inherited from:
ContextVerbStream
@targetName("streamQuery")
inline def stream[T](inline quoted: Quoted[Query[T]]): StreamResult[T]
Inherited from:
ContextVerbStream
@targetName("translateBatchActionReturning")
inline def translate[I, T, A <: Action[I] & QAC[I, T]](inline quoted: Quoted[BatchAction[A]], inline prettyPrint: Boolean): TranslateResult[List[String]]
Inherited from:
ContextTranslateMacro
@targetName("translateBatchActionReturning")
inline def translate[I, T, A <: Action[I] & QAC[I, T]](inline quoted: Quoted[BatchAction[A]]): TranslateResult[List[String]]
Inherited from:
ContextTranslateMacro
@targetName("translateBatchAction")
inline def translate[I, A <: Action[I] & QAC[I, Nothing]](inline quoted: Quoted[BatchAction[A]], inline prettyPrint: Boolean): TranslateResult[List[String]]
Inherited from:
ContextTranslateMacro
@targetName("translateBatchAction")
inline def translate[I, A <: Action[I] & QAC[I, Nothing]](inline quoted: Quoted[BatchAction[A]]): TranslateResult[List[String]]
Inherited from:
ContextTranslateMacro
@targetName("translateActionReturning")
inline def translate[E, T](inline quoted: Quoted[ActionReturning[E, T]], inline prettyPrint: Boolean): TranslateResult[String]
Inherited from:
ContextTranslateMacro
@targetName("translateActionReturning")
inline def translate[E, T](inline quoted: Quoted[ActionReturning[E, T]]): TranslateResult[String]
Inherited from:
ContextTranslateMacro
@targetName("translateAction")
inline def translate[E](inline quoted: Quoted[Action[E]], inline prettyPrint: Boolean): TranslateResult[String]
Inherited from:
ContextTranslateMacro
@targetName("translateAction")
inline def translate[E](inline quoted: Quoted[Action[E]]): TranslateResult[String]
Inherited from:
ContextTranslateMacro
@targetName("translateQuerySingle")
inline def translate[T](inline quoted: Quoted[T], inline prettyPrint: Boolean): TranslateResult[String]
Inherited from:
ContextTranslateMacro
@targetName("translateQuerySingle")
inline def translate[T](inline quoted: Quoted[T]): TranslateResult[String]
Inherited from:
ContextTranslateMacro
@targetName("translateQuery")
inline def translate[T](inline quoted: Quoted[Query[T]], inline prettyPrint: Boolean): TranslateResult[String]
Inherited from:
ContextTranslateMacro
@targetName("translateQuery")
inline def translate[T](inline quoted: Quoted[Query[T]]): TranslateResult[String]
Inherited from:
ContextTranslateMacro
def translateBatchQueryReturningEndpoint(groups: List[BatchGroupReturning], prettyPrint: Boolean)(executionInfo: ExecutionInfo, dc: TranslateRunner): TranslateResult[List[String]]
Inherited from:
ContextTranslateProto
override def wrap[T](t: => T): TranslateResult[T]
Definition Classes
ZioTranslateContext -> ContextTranslateProto
Inherited from:
ZioTranslateContext

Concrete fields

val currentConnection: FiberRef[Option[Connection]]

Since we are immediately executing the ZIO that creates this fiber ref whether it is global is not really relevant since it does not really use scope However if it were used for something else it would be scoped to the fiber-ref of the zio-jdbc context's creator i.e. the global scope.

Since we are immediately executing the ZIO that creates this fiber ref whether it is global is not really relevant since it does not really use scope However if it were used for something else it would be scoped to the fiber-ref of the zio-jdbc context's creator i.e. the global scope.

final lazy val underlying: ZioJdbcUnderlyingContext[Dialect, Naming]

Inherited fields

protected val dateTimeZone: TimeZone
Inherited from:
JdbcContextTypes
Inherited from:
RowContext
protected val identityPrepare: Prepare
Inherited from:
RowContext

Extensions

Inherited extensions

extension [T](dynamicQuery: DynamicEntityQuery[T])
inline def insertValue(value: T): DynamicInsert[T]
Inherited from:
Context
inline def updateValue(value: T): DynamicUpdate[T]
Inherited from:
Context
extension [T](entity: EntityQuery[T])
inline def insertValue(inline value: T): Insert[T]
Inherited from:
Context
inline def updateValue(inline value: T): Update[T]
Inherited from:
Context
extension [T](q: Query[T])
inline def filterByKeys(inline map: Map[String, Any]): Query[T]

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
inline def filterColumns(inline columns: List[String]): Query[T]
Inherited from:
Context
extension [T](quotedEntity: Quoted[EntityQuery[T]])
inline def insertValue(inline value: T): Insert[T]
Inherited from:
Context
inline def updateValue(inline value: T): Update[T]
Inherited from:
Context

Implicits

Inherited implicits

implicit inline def anyValDecoder[Cls <: AnyVal]: JdbcDecoder[Cls]
Inherited from:
LowPriorityImplicits
implicit inline def anyValEncoder[Cls <: AnyVal]: JdbcEncoder[Cls]
Inherited from:
LowPriorityImplicits
implicit val bigDecimalDecoder: JdbcDecoder[BigDecimal]
Inherited from:
Decoders
implicit val bigDecimalEncoder: JdbcEncoder[BigDecimal]
Inherited from:
Encoders
implicit val booleanDecoder: JdbcDecoder[Boolean]
Inherited from:
SqlContext
implicit val booleanEncoder: JdbcEncoder[Boolean]
Inherited from:
SqlContext
implicit val byteArrayDecoder: JdbcDecoder[Array[Byte]]
Inherited from:
Decoders
implicit val byteArrayEncoder: JdbcEncoder[Array[Byte]]
Inherited from:
Encoders
implicit val byteDecoder: JdbcDecoder[Byte]
Inherited from:
Decoders
implicit val byteEncoder: JdbcEncoder[Byte]
Inherited from:
Encoders
implicit val dateDecoder: JdbcDecoder[Date]
Inherited from:
Decoders
implicit val dateEncoder: JdbcEncoder[Date]
Inherited from:
Encoders
implicit inline def dec[T]: GenericDecoder[ResultRow, Session, T, Generic]
Inherited from:
Context
implicit val doubleDecoder: JdbcDecoder[Double]
Inherited from:
Decoders
implicit val doubleEncoder: JdbcEncoder[Double]
Inherited from:
Encoders
implicit val floatDecoder: JdbcDecoder[Float]
Inherited from:
Decoders
implicit val floatEncoder: JdbcEncoder[Float]
Inherited from:
Encoders
implicit val intDecoder: JdbcDecoder[Int]
Inherited from:
Decoders
implicit val intEncoder: JdbcEncoder[Int]
Inherited from:
Encoders
implicit val localDateDecoder: JdbcDecoder[LocalDate]
Inherited from:
SqlContext
implicit val localDateEncoder: JdbcEncoder[LocalDate]
Inherited from:
SqlContext
implicit val longDecoder: JdbcDecoder[Long]
Inherited from:
Decoders
implicit val longEncoder: JdbcEncoder[Long]
Inherited from:
Encoders
implicit def mappedDecoder[I, O](implicit mapped: MappedEncoding[I, O], d: JdbcDecoder[I]): JdbcDecoder[O]
Inherited from:
Decoders
implicit override def mappedEncoder[I, O](implicit mapped: MappedEncoding[I, O], e: JdbcEncoder[O]): JdbcEncoder[I]
Definition Classes
Encoders -> EncodingDsl
Inherited from:
Encoders
Inherited from:
JdbcContextTypes
implicit val nullEncoder: JdbcEncoder[Null]
Inherited from:
Encoders
implicit def optionDecoder[T](implicit d: JdbcDecoder[T]): JdbcDecoder[Option[T]]
Inherited from:
Decoders
implicit def optionEncoder[T](implicit d: JdbcEncoder[T]): JdbcEncoder[Option[T]]
Inherited from:
Encoders
implicit val shortDecoder: JdbcDecoder[Short]
Inherited from:
Decoders
implicit val shortEncoder: JdbcEncoder[Short]
Inherited from:
Encoders
implicit val sqlDateDecoder: JdbcDecoder[Date]
Inherited from:
Decoders
implicit val sqlDateEncoder: JdbcEncoder[Date]
Inherited from:
Encoders
implicit val sqlTimeDecoder: JdbcDecoder[Time]
Inherited from:
Decoders
implicit val sqlTimeEncoder: JdbcEncoder[Time]
Inherited from:
Encoders
implicit val sqlTimestampDecoder: JdbcDecoder[Timestamp]
Inherited from:
Decoders
implicit val sqlTimestampEncoder: JdbcEncoder[Timestamp]
Inherited from:
Encoders
implicit val stringDecoder: JdbcDecoder[String]
Inherited from:
Decoders
implicit val stringEncoder: JdbcEncoder[String]
Inherited from:
Encoders
implicit val uuidDecoder: JdbcDecoder[UUID]
Inherited from:
SqlContext
implicit val uuidEncoder: JdbcEncoder[UUID]
Inherited from:
SqlContext