glitr/query

This module exports types and functions related to the query of Routes

Types

A wrapper for an encoder and a decoder to convert from request/response query to and from a Gleam type

pub type QueryConverter(query_type) {
  QueryConverter(
    encoder: fn(query_type) -> List(#(String, String)),
    decoder: fn(List(#(String, String))) ->
      Result(query_type, Nil),
  )
}

Constructors

  • QueryConverter(
      encoder: fn(query_type) -> List(#(String, String)),
      decoder: fn(List(#(String, String))) -> Result(query_type, Nil),
    )

The type of query that can be expected from a Route

pub type QueryType {
  EmptyQuery
  ComplexQuery
}

Constructors

  • EmptyQuery
  • ComplexQuery

The query type of a Route

pub opaque type RouteQuery(query_type)

Functions

pub fn complex_query(
  converter: QueryConverter(a),
) -> RouteQuery(a)

Create a more complex RouteQuery from a custom converter

pub fn decode(
  query: RouteQuery(a),
  value: List(#(String, String)),
) -> Result(a, Nil)

Decode a value using the RouteQuery’s decoder from a query

pub fn empty_query() -> RouteQuery(Nil)

Create a RouteQuery that convert from/to an empty query

pub fn encode(
  query: RouteQuery(a),
  value: a,
) -> List(#(String, String))

Encode a value using the RouteQuery’s encoder into a query

pub fn get_type(query: RouteQuery(a)) -> QueryType

Return the QueryType of a RouteQuery

Search Document