postgresql-types-algebra: Type classes for PostgreSQL type mappings

[ codecs, library, mit, postgresql ] [ Propose Tags ] [ Report a vulnerability ]

Core type classes and algebra extracted from the postgresql-types library.

Defines the fundamental abstractions for mapping Haskell types to PostgreSQL types, including binary and textual encoding/decoding, type metadata, and error handling.

This package provides the type class algebra without concrete type implementations, making it suitable as a lightweight dependency for libraries that want to define their own PostgreSQL type mappings or work with the postgresql-types ecosystem.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1, 0.1
Dependencies attoparsec (>=0.14 && <0.19), base (>=4.11 && <5), bytestring (>=0.10 && <0.13), ptr-peeker (>=0.1 && <0.2), ptr-poker (>=0.1.2.16 && <0.2), tagged (>=0.8.9 && <0.9), text (>=1.2 && <3), text-builder (>=1.0.0.4 && <1.1) [details]
License MIT
Copyright (c) 2025, Nikita Volkov
Author Nikita Volkov <nikita.y.volkov@mail.ru>
Maintainer Nikita Volkov <nikita.y.volkov@mail.ru>
Uploaded by NikitaVolkov at 2026-01-22T15:48:06Z
Category PostgreSQL, Codecs
Home page https://github.com/nikita-volkov/postgresql-types-algebra
Bug tracker https://github.com/nikita-volkov/postgresql-types-algebra/issues
Source repo head: git clone https://github.com/nikita-volkov/postgresql-types-algebra
Distributions
Reverse Dependencies 3 direct, 0 indirect [details]
Downloads 6 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-01-22 [all 1 reports]

Readme for postgresql-types-algebra-0.1

[back to package description]

postgresql-types-algebra

Hackage Continuous Haddock

Core type classes and algebra for PostgreSQL type mappings, extracted from "postgresql-types".

Overview

This package provides the fundamental abstractions for mapping Haskell types to PostgreSQL types:

  • Type classes defining the algebra for PostgreSQL type mappings
  • Error types for decoding failures
  • Metadata support for type names, OIDs, and parameters
  • No concrete implementations - just the algebra

Type Classes

IsScalar

The core type class for types that map to PostgreSQL values:

class IsScalar a where
  -- Type metadata
  typeName :: Tagged a Text
  baseOid :: Tagged a (Maybe Word32)
  arrayOid :: Tagged a (Maybe Word32)
  typeParams :: Tagged a [Text]
  typeSignature :: Tagged a Text
  
  -- Binary format
  binaryEncoder :: a -> Write.Write
  binaryDecoder :: PtrPeeker.Variable (Either DecodingError a)
  
  -- Textual format
  textualEncoder :: a -> TextBuilder.TextBuilder
  textualDecoder :: Attoparsec.Parser a

This class enables:

  • Binary encoding/decoding using PostgreSQL's native binary format
  • Textual encoding/decoding using PostgreSQL's text representation
  • Type metadata including OIDs and type signatures for parameterized types
  • Round-trip fidelity through all encoding combinations

Use Cases

For Library Authors

Use this package to:

  • Define custom PostgreSQL type mappings compatible with the "postgresql-types" ecosystem
  • Create adapter libraries for different PostgreSQL client libraries
  • Build generic tools that work with any IsScalar instance

For Application Developers

This package is typically used indirectly through: