ZioJdbcContext

abstract class ZioJdbcContext[Dialect <: SqlIdiom, Naming <: NamingStrategy] extends ZioContext[Dialect, Naming] with JdbcRunContext[Dialect, Naming] with StreamingContext[Dialect, Naming] with ZioPrepareContext[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).

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 not just a Connection since JDBC requires blocking. Instead it is a Has[Connection] with Has[Blocking.Service] which is type-alised as QConnection hence methods in this context return ZIO[QConnection, Throwable, T]. The type QIO[T] i.e. Quill-IO is an alias for this.

If you have a zio-app, using this context is fairly straightforward but requires some setup: {{ val zioConn = ZLayer.fromManaged(for { ds <- ZManaged.fromAutoCloseable(Task(JdbcContextConfig(LoadConfig("testPostgresDB")).dataSource)) conn <- ZManaged.fromAutoCloseable(Task(ds.getConnection)) } yield conn)

MyZioContext.run(query[Person]).provideCustomLayer(zioConn) }}

Various methods in the io.getquill.context.ZioJdbc can assist in simplifying it's creation, for example, you can provide a DataSource instead of a Connection like this (note that the resulting Connection has a closing bracket). {{ import ZioJdbc._ val zioConn = QDataSource.fromPrefix("testPostgresDB") >>> QDataSource.toConnection MyZioContext.run(query[Person]).provideCustomLayer(zioConn) }}

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]).provideCustomLayer(zioConn)) }}

trait ZioPrepareContext[Dialect, Naming]
trait PrepareContext[Dialect, Naming]
trait JdbcRunContext[Dialect, Naming]
trait Decoders
trait Encoders
trait SqlContext[Dialect, Naming]
trait ZioContext[Dialect, Naming]
trait StreamingContext[Dialect, Naming]
trait ProtoStreamContext[Dialect, Naming]
trait Context[Dialect, Naming]
trait Closeable
trait AutoCloseable
trait EncodingDsl
trait LowPriorityImplicits
trait ProtoContext[Dialect, Naming]
trait RowContext
class Object
trait Matchable
class Any

Type members

Classlikes

class ResultSetIterator[T](rs: ResultSet, extractor: () => T) extends BufferedIterator[T]

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.

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.

Inherited classlikes

case class BatchGroup(string: String, prepare: List[Prepare])
Inherited from
ProtoContext
case class BatchGroupReturning(string: String, returningBehavior: ReturnAction, prepare: List[Prepare])
Inherited from
ProtoContext
case class JdbcDecoder[T](decoder: () => T)
Inherited from
Decoders
case class JdbcEncoder[T](sqlType: Int, encoder: () => T)
Inherited from
Encoders

Types

override type Environment = Has[Session] & Blocking
override type Error = SQLException
override type PrepareRow = PreparedStatement
override type Result[T] = ZIO[Has[Session] & Blocking, SQLException, 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]

Inherited types

type BaseDecoder[T] = GenericDecoder[ResultRow, T, Specific]
Inherited from
EncodingDsl
type BaseEncoder[T] = GenericEncoder[T, PrepareRow]
Inherited from
EncodingDsl
type ColumnResolver = GenericColumnResolver[ResultRow]
Inherited from
EncodingDsl
override type DatasourceContext = Unit
Inherited from
JdbcRunContext
type DatasourceContextBehavior <: DatasourceContextInjection
Inherited from
Context
type Decoder[T] = JdbcDecoder[T]
Inherited from
Decoders
type DecoderMethod[T] = (Int, ResultRow) => T
Inherited from
EncodingDsl
type Encoder[T] = JdbcEncoder[T]
Inherited from
Encoders
type EncoderMethod[T] = (Int, T, PrepareRow) => PrepareRow
Inherited from
EncodingDsl
type Extractor[T] = ResultRow => T
Inherited from
ProtoStreamContext
type Index = Int
Inherited from
JdbcRunContext
type Prepare = PrepareRow => (List[Any], PrepareRow)
Inherited from
ProtoStreamContext
Inherited from
ZioPrepareContext
override type PrepareBatchActionResult = QIO[List[PrepareRow]]
Inherited from
ZioPrepareContext
Inherited from
ZioPrepareContext
type RowTyper[T] = GenericRowTyper[ResultRow, T]
Inherited from
EncodingDsl
override type RunQueryResult[T] = List[T]
Inherited from
JdbcRunContext
override type RunQuerySingleResult[T] = T
Inherited from
JdbcRunContext
override type Session = Connection
Inherited from
JdbcRunContext
override type StreamResult[T] = ZStream[Environment, Error, T]
Inherited from
ZioContext

Value members

Concrete methods

def chunkedFetch[T](iter: ResultSetIterator[T], fetchSize: Int): ZStream[Any, Throwable, T]
override def close(): Unit

ZIO Contexts do not managed DB connections so this is a no-op

ZIO Contexts do not managed DB connections so this is a no-op

Definition Classes
Context -> Closeable -> AutoCloseable
def guardedChunkFill[A](n: Int)(hasNext: => Boolean, elem: => A): Chunk[A]
protected def prepareStatementForStreaming(sql: String, conn: Connection, fetchSize: Option[Int]): PreparedStatement

Override to enable specific vendor options needed for streaming

Override to enable specific vendor options needed for streaming

def streamQuery[T](fetchSize: Option[Int], sql: String, prepare: Prepare, extractor: () => T)(executionInfo: ExecutionInfo, dc: DatasourceContext): QStream[T]
def transaction[A](f: ZIO[QConnection, Throwable, A]): ZIO[QConnection, Throwable, A]
protected def withConnection[T](f: Connection => Result[T]): Result[T]
override protected def withConnectionWrapped[T](f: Connection => T): QIO[T]
Definition Classes
JdbcRunContext

Inherited methods

override def context: DatasourceContext
Definition Classes
JdbcRunContext -> Context
Inherited from
JdbcRunContext
def decoder[T](f: ResultRow => Index => T): JdbcDecoder[T]
Inherited from
Decoders
def decoder[T](d: (Int, ResultRow) => 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
override def executeAction[T](sql: String, prepare: Prepare)(executionInfo: ExecutionInfo, dc: DatasourceContext): Result[Long]
Definition Classes
JdbcRunContext -> ProtoContext
Inherited from
JdbcRunContext
override def executeActionReturning[O](sql: String, prepare: Prepare, extractor: () => O, returningBehavior: ReturnAction)(executionInfo: ExecutionInfo, dc: DatasourceContext): Result[O]
Definition Classes
JdbcRunContext -> ProtoContext
Inherited from
JdbcRunContext
override def executeBatchAction(groups: List[BatchGroup])(executionInfo: ExecutionInfo, dc: DatasourceContext): Result[List[Long]]
Definition Classes
JdbcRunContext -> ProtoContext
Inherited from
JdbcRunContext
def executeBatchActionReturning[T](groups: List[BatchGroupReturning], extractor: () => T)(executionInfo: ExecutionInfo, dc: DatasourceContext): Result[List[T]]
Inherited from
JdbcRunContext
override def executeQuery[T](sql: String, prepare: Prepare, extractor: () => T)(executionInfo: ExecutionInfo, dc: DatasourceContext): Result[List[T]]
Definition Classes
JdbcRunContext -> ProtoContext
Inherited from
JdbcRunContext
override def executeQuerySingle[T](sql: String, prepare: Prepare, extractor: () => T)(executionInfo: ExecutionInfo, dc: DatasourceContext): Result[T]
Definition Classes
JdbcRunContext -> ProtoContext
Inherited from
JdbcRunContext
protected def handleSingleResult[T](list: List[T]): T
Inherited from
Context
protected def handleSingleWrappedResult[T](list: Result[List[T]]): Result[T]
Inherited from
JdbcRunContext
def idiom: Dialect
Inherited from
ProtoContext
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
ProtoContext
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 Params
intType

one of java.sql.Types

Returns

JDBC type in string form

Inherited from
JdbcRunContext
@targetName("runPrepareBatchAction")
inline def prepare[I, A <: Action[I] & QAC[I, Nothing]](inline quoted: Quoted[BatchAction[A]]): PrepareBatchActionResult
Inherited from
PrepareContext
@targetName("runPrepareAction")
inline def prepare[E](inline quoted: Quoted[Action[E]]): PrepareActionResult
Inherited from
PrepareContext
@targetName("runPrepareQuerySingle")
inline def prepare[T](inline quoted: Quoted[T]): PrepareQueryResult
Inherited from
PrepareContext
@targetName("runPrepareQuery")
inline def prepare[T](inline quoted: Quoted[Query[T]]): PrepareQueryResult
Inherited from
PrepareContext
def prepareAction(sql: String, prepare: Prepare)(executionInfo: ExecutionInfo, dc: DatasourceContext): PrepareActionResult
Inherited from
ZioPrepareContext
def prepareBatchAction(groups: List[BatchGroup])(executionInfo: ExecutionInfo, dc: DatasourceContext): PrepareBatchActionResult
Inherited from
ZioPrepareContext
def prepareQuery(sql: String, prepare: Prepare)(executionInfo: ExecutionInfo, dc: DatasourceContext): PrepareQueryResult
Inherited from
ZioPrepareContext
def prepareSingle(sql: String, prepare: Prepare)(executionInfo: ExecutionInfo, dc: DatasourceContext): QIO[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
protected def prepareWithReturning(sql: String, conn: Connection, returningBehavior: ReturnAction): PreparedStatement
Inherited from
JdbcRunContext
@targetName("runBatchActionReturning")
inline def run[I, T, A <: Action[I] & QAC[I, T]](inline quoted: Quoted[BatchAction[A]]): Result[List[T]]
Inherited from
Context
@targetName("runBatchAction")
inline def run[I, A <: Action[I] & QAC[I, Nothing]](inline quoted: Quoted[BatchAction[A]]): Result[RunBatchActionResult]
Inherited from
Context
@targetName("runActionReturning")
inline def run[E, T](inline quoted: Quoted[ActionReturning[E, T]]): Result[RunActionReturningResult[T]]
Inherited from
Context
@targetName("runAction")
inline def run[E](inline quoted: Quoted[Action[E]]): Result[RunActionResult]
Inherited from
Context
@targetName("runQuerySingle")
inline def run[T](inline quoted: Quoted[T]): Result[RunQuerySingleResult[T]]
Inherited from
Context
@targetName("runQuery")
inline def run[T](inline quoted: Quoted[Query[T]]): Result[List[T]]
Inherited from
Context
@targetName("streamQueryWithFetchSize")
inline def stream[T](inline quoted: Quoted[Query[T]], fetchSize: Int): StreamResult[T]
Inherited from
StreamingContext
@targetName("streamQuery")
inline def stream[T](inline quoted: Quoted[Query[T]]): StreamResult[T]
Inherited from
StreamingContext

Concrete fields

override protected val effect: ContextEffect[Result]
val streamBlocker: ZStream[Blocking, Nothing, Any]

Inherited fields

Inherited from
RowContext
val identityPrepare: Prepare
Inherited from
RowContext

Extensions

Inherited extensions

extension (q: Query[T])
inline def filterByKeys[T](inline map: Map[String, String]): Query[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, 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
Decoders
implicit val localDateEncoder: JdbcEncoder[LocalDate]
Inherited from
Encoders
implicit val localDateTimeDecoder: JdbcDecoder[LocalDateTime]
Inherited from
Decoders
implicit val localDateTimeEncoder: JdbcEncoder[LocalDateTime]
Inherited from
Encoders
implicit val longDecoder: JdbcDecoder[Long]
Inherited from
Decoders
implicit val longEncoder: JdbcEncoder[Long]
Inherited from
Encoders
implicit def mappedDecoder[I, O](mapped: MappedEncoding[I, O], d: JdbcDecoder[I]): JdbcDecoder[O]
Inherited from
Decoders
implicit override def mappedEncoder[I, O](mapped: MappedEncoding[I, O], e: JdbcEncoder[O]): JdbcEncoder[I]
Definition Classes
Encoders -> EncodingDsl
Inherited from
Encoders
implicit def optionDecoder[T](d: JdbcDecoder[T]): JdbcDecoder[Option[T]]
Inherited from
Decoders
implicit def optionEncoder[T](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 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