Database

harness.sql.Database
See theDatabase companion object
final class Database

This represents access to an SQL database. When accessing your database, it could be in one of 3 states:

  • Pool : you are not in a transaction, and are able to execute as many parallel fibers as your pool will allow.
  • Transaction : you are in a db transaction, and are only able to execute 1 parallel fiber at a time.
  • Savepoint : you are in a db transaction + savepoint, and are only able to execute 1 parallel fiber at a time.

You can get a Transaction/Savepoint by using Atomically.atomically/Atomically.atomicScope. These can also be accessed via: Atomically.Live$.atomically/Atomically.Live$.atomicScope. The reason Transaction/Savepoint only support a single parallel fiber is because anything happening atomically in the db needs to be on a single connection, and transactions/savepoints are scoped to the entire connection. Otherwise, you could end up with a scenario like:

  • in transaction
    • fiber-a : in savepoint
    • fiber-b : in savepoint
    • fiber-a : insert R1
    • fiber-b : insert R2
    • fiber-a : insert R3
    • fiber-a : rollback (insertion of R2 is also rolled back)

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def use[R, E, A](zio: ZIO[R & Database, E, A]): ZIO[R, E, A]
def use[R, E, A](zio: ZStream[R & Database, E, A]): ZStream[R, E, A]