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
  • AppliedFragment
  • Channel
  • Codec
  • Command
  • Cursor
  • Decoder
  • Encoder
  • Fragment
  • PreparedCommand
  • PreparedQuery
  • Query
  • SSL
  • Session
  • SqlState
  • Statement
  • Transaction
  • Void
  • implicits
  • ~

trait Encoder[A] extends AnyRef

Encoder of Postgres text-format data from Scala types.

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

Abstract Value Members

  1. 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.

  2. abstract def sql: State[Int, String]

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

  3. abstract def types: List[Type]

    Types of encoded fields, in order.

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. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  6. def contramap[B](f: (B) ⇒ A): Encoder[B]

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

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

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

  12. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. def list(as: List[A]): Encoder[as.type]

    Derive an encoder for the specified list.

    Derive an encoder for the specified list. This is equivalent to list(as.length) but the resulting encoder can only encode the exact list that it was passed. Prefer this overload when possible because it lessens the possibility of attempting to encode a list of the wrong length.

  16. 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.

  17. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  19. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  20. def oids(ty: Typer): Either[List[(Type, Option[Int])], List[Int]]

    Oids of types, or mismatches.

  21. def opt: Encoder[Option[A]]
  22. def product[B](fb: Encoder[B]): Encoder[(A, B)]

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

  23. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  24. def toString(): String
    Definition Classes
    Encoder → AnyRef → Any
  25. def values: Encoder[A]

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

  26. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  29. def ~[B](fb: Encoder[B]): Encoder[~[A, B]]

    Shorthand for product.

Inherited from AnyRef

Inherited from Any

Ungrouped