plushie/data

Data query pipeline for filtering, searching, sorting, and paginating in-memory record collections.

Apply a chain of query options to transform a list:

data.query(users, [
  data.Filter(fn(u) { u.active }),
  data.Search(fields: [fn(u) { u.name }], query: "alice"),
  data.SortBy(direction: data.Asc, compare: fn(a, b) {
    string.compare(a.name, b.name)
  }),
  data.Page(1),
  data.PageSize(10),
])

Types

Query options applied in order: filter -> search -> sort -> paginate.

pub type QueryOpt(a) {
  Filter(fn(a) -> Bool)
  Search(fields: List(fn(a) -> String), query: String)
  Sort(direction: SortDirection, key: fn(a) -> String)
  SortBy(
    direction: SortDirection,
    compare: fn(a, a) -> order.Order,
  )
  Page(Int)
  PageSize(Int)
  Group(fn(a) -> String)
}

Constructors

  • Filter(fn(a) -> Bool)

    Keep only records matching the predicate.

  • Search(fields: List(fn(a) -> String), query: String)

    Case-insensitive substring search across extracted string fields.

  • Sort(direction: SortDirection, key: fn(a) -> String)

    Sort by a string key extractor (lexicographic comparison).

  • SortBy(
      direction: SortDirection,
      compare: fn(a, a) -> order.Order,
    )

    Sort with a custom comparison function (for numeric or complex sorts).

  • Page(Int)

    Page number (1-based, default 1).

  • PageSize(Int)

    Items per page (default 25).

  • Group(fn(a) -> String)

    Group paginated results by a key extractor.

Query result with pagination metadata.

pub type QueryResult(a) {
  QueryResult(
    entries: List(a),
    total: Int,
    page: Int,
    page_size: Int,
    groups: dict.Dict(String, List(a)),
  )
}

Constructors

  • QueryResult(
      entries: List(a),
      total: Int,
      page: Int,
      page_size: Int,
      groups: dict.Dict(String, List(a)),
    )

Sort direction.

pub type SortDirection {
  Asc
  Desc
}

Constructors

  • Asc
  • Desc

Values

pub fn query(
  records: List(a),
  opts: List(QueryOpt(a)),
) -> QueryResult(a)

Run a query pipeline on a list of records.

Search Document