Packages

  • package root
    Definition Classes
    root
  • package skunk

    Skunk is a functional data access layer for Postgres.

    Skunk is a functional data access layer for Postgres.

    Design principles:

    • Skunk doesn't use JDBC. It speaks the Postgres wire protocol. It will not work with any other database back end.
    • Skunk is asynchronous all the way down, via cats-effect, fs2, and ultimately nio. The high-level network layers (Protocol and Session) are safe to use concurrently.
    • Serialization to and from schema types is not typeclass-based, so there are no implicit derivations. Codecs are explicit, like parser combinators.
    • I'm not sweating arity abstraction that much. Pass a ~ b ~ c for three args and Void if there are no args. This may change in the future but it's fine for now.
    • Skunk uses Resource for lifetime-managed objects, which means it takes some discipline to avoid leaks, especially when working concurrently. May or may not end up being problematic.
    • I'm trying to write good Scaladoc this time.

    A minimal example follows. We construct a Resource that yields a Session, then use it.

    package example
    
    import cats.effect._
    import skunk._
    import skunk.implicits._
    import skunk.codec.numeric._
    
    object Minimal extends IOApp {
    
      val session: Resource[IO, Session[IO]] =
        Session.single(
          host     = "localhost",
          port     = 5432,
          user     = "postgres",
          database = "world",
        )
    
      def run(args: List[String]): IO[ExitCode] =
        session.use { s =>
          for {
            n <- s.unique(sql"select 42".query(int4))
            _ <- IO(println(s"The answer is $n."))
          } yield ExitCode.Success
        }
    
    }

    Continue reading for an overview of the library. It's pretty small.

    Definition Classes
    root
  • package codec
    Definition Classes
    skunk
  • package data
    Definition Classes
    skunk
  • package exception
    Definition Classes
    skunk
  • package net

    Skunk network stack, starting with BitVectorSocket at the bottom and ending with Protocol at the top (Session delegates all its work to Protocol).

    Skunk network stack, starting with BitVectorSocket at the bottom and ending with Protocol at the top (Session delegates all its work to Protocol). Everything is non-blocking.

    Definition Classes
    skunk
  • package syntax
    Definition Classes
    skunk
  • package util
    Definition Classes
    skunk
  • Channel
  • Codec
  • Command
  • Cursor
  • Decoder
  • Encoder
  • Fragment
  • PreparedCommand
  • PreparedQuery
  • Query
  • Session
  • SqlState
  • Statement
  • Transaction
  • Void
  • implicits
  • ~

trait Codec[A] extends Encoder[A] with Decoder[A]

Symmetric encoder and decoder of Postgres text-format data to and from Scala types.

Self Type
Codec[A]
Source
Codec.scala
Linear Supertypes
Decoder[A], Encoder[A], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Codec
  2. Decoder
  3. Encoder
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def decode(offset: Int, ss: List[Option[String]]): Either[Error, A]
    Definition Classes
    Decoder
  2. abstract def encode(a: A): List[Option[String]]

    Encode a value of type A, yielding a list of Postgres text-formatted strings, lifted to Option to handle NULL values.

    Encode a value of type A, yielding a list of Postgres text-formatted strings, lifted to Option to handle NULL values. Encoding failures raise unrecoverable errors.

    Definition Classes
    Encoder
  3. abstract def sql: State[Int, String]

    Given an initial parameter index, yield a hunk of sql containing placeholders, and a new index.

    Given an initial parameter index, yield a hunk of sql containing placeholders, and a new index.

    Definition Classes
    Encoder
  4. abstract def types: List[Type]
    Definition Classes
    Decoder

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def asDecoder: Decoder[A]

    Forget this value is a Codec and treat it as a Decoder.

  5. def asEncoder: Encoder[A]

    Forget this value is a Codec and treat it as an Encoder.

  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  8. def contramap[B](f: (B) ⇒ A): Encoder[B]

    Contramap inputs from a new type B, yielding an Encoder[B].

    Contramap inputs from a new type B, yielding an Encoder[B].

    Definition Classes
    Encoder
  9. lazy val empty: List[Option[String]]
    Attributes
    protected
    Definition Classes
    Encoder
  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. def gcontramap[B](implicit ev: Aux[B, A]): Encoder[B]

    Adapt this Encoder from twiddle-list type A to isomorphic case-class type B.

    Adapt this Encoder from twiddle-list type A to isomorphic case-class type B.

    Definition Classes
    Encoder
  14. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. def gimap[B](implicit ev: Aux[B, A]): Codec[B]

    Adapt this Codec from twiddle-list type A to isomorphic case-class type B.

  16. def gmap[B](implicit ev: Aux[B, A]): Decoder[B]

    Adapt this Decoder from twiddle-list type A to isomorphic case-class type B.

    Adapt this Decoder from twiddle-list type A to isomorphic case-class type B.

    Definition Classes
    Decoder
  17. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  18. def imap[B](f: (A) ⇒ B)(g: (B) ⇒ A): Codec[B]

    Contramap inputs from, and map outputs to, a new type B, yielding a Codec[B].

  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. def length: Int
    Definition Classes
    Decoder
  21. def list(n: Int): Encoder[List[A]]

    Derive an encoder for a list of size n that expands to a comma-separated list of placeholders.

    Derive an encoder for a list of size n that expands to a comma-separated list of placeholders.

    Definition Classes
    Encoder
  22. def map[B](f: (A) ⇒ B): Decoder[B]

    Map decoded results to a new type B, yielding a Decoder[B].

    Map decoded results to a new type B, yielding a Decoder[B].

    Definition Classes
    Decoder
  23. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  24. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  25. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  26. def oids(ty: Typer): Either[List[(Type, Option[Int])], List[Int]]

    Oids of types, or mismatches.

    Oids of types, or mismatches.

    Definition Classes
    Encoder
  27. def opt: Codec[Option[A]]

    Lift this Codec into Option, where None is mapped to and from a vector of NULL.

    Lift this Codec into Option, where None is mapped to and from a vector of NULL.

    Definition Classes
    CodecDecoderEncoder
  28. def product[B](fb: Codec[B]): Codec[(A, B)]

    Codec is semigroupal: a pair of codecs make a codec for a pair.

  29. def product[B](fb: Decoder[B]): Decoder[(A, B)]

    Decoder is semigroupal: a pair of decoders make a decoder for a pair.

    Decoder is semigroupal: a pair of decoders make a decoder for a pair.

    Definition Classes
    Decoder
  30. def product[B](fb: Encoder[B]): Encoder[(A, B)]

    Encoder is semigroupal: a pair of encoders make a encoder for a pair.

    Encoder is semigroupal: a pair of encoders make a encoder for a pair.

    Definition Classes
    Encoder
  31. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  32. def toString(): String
    Definition Classes
    CodecDecoderEncoder → AnyRef → Any
  33. def values: Encoder[A]

    Derive an equivalent encoder for a row type; i.e., its placeholders will be surrounded by parens.

    Derive an equivalent encoder for a row type; i.e., its placeholders will be surrounded by parens.

    Definition Classes
    Encoder
  34. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  35. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  37. def ~[B](fb: Codec[B]): Codec[~[A, B]]

    Shorthand for product.

  38. def ~[B](fb: Decoder[B]): Decoder[~[A, B]]

    Shorthand for product.

    Shorthand for product.

    Definition Classes
    Decoder
  39. def ~[B](fb: Encoder[B]): Encoder[~[A, B]]

    Shorthand for product.

    Shorthand for product.

    Definition Classes
    Encoder

Inherited from Decoder[A]

Inherited from Encoder[A]

Inherited from AnyRef

Inherited from Any

Ungrouped