eff3ct0 / criteria4s   0.8.1

MIT License GitHub

Criteria4s is a simple DSL to define criteria and predicate expressions for any data stores by using Scala type class mechanisms in a type-safe

Scala versions: 2.13

CI Release License: MIT

Criteria4s

Type-safe, data-store-agnostic filter expressions for Scala 3.

Write a predicate once and evaluate it against SQL, MongoDB, Elasticsearch, or any custom backend — with full compiler enforcement and zero runtime dispatch.

Documentation

Quick Start

// build.sbt
libraryDependencies += "com.eff3ct" %% "criteria4s-core"       % "<version>"
libraryDependencies += "com.eff3ct" %% "criteria4s-postgresql"  % "<version>" // or any dialect

Define a filter once:

import com.eff3ct.criteria4s.core.*
import com.eff3ct.criteria4s.extensions.*

def activeAdults[T <: CriteriaTag: GEQ: EQ: AND](using Show[Column, T]): Criteria[T] =
  F.col[T]("age").geq(F.lit(18)) and (F.col[T]("active") === F.lit(true))

Evaluate against any backend:

import com.eff3ct.criteria4s.dialect.sql.{given, *}
import com.eff3ct.criteria4s.dialect.mongodb.{given, *}

activeAdults[SQL].value
// (age >= 18) AND (active = true)

activeAdults[MongoDB].value
// {$and: [{"age": {$gte: 18}}, {"active": {$eq: true}}]}

Dialects

Module Backend
criteria4s-sql SQL (base)
criteria4s-postgresql PostgreSQL
criteria4s-mysql MySQL
criteria4s-sparksql Spark SQL
criteria4s-duckdb DuckDB
criteria4s-clickhouse ClickHouse
criteria4s-mongodb MongoDB
criteria4s-elasticsearch Elasticsearch

Client Integrations

Module Client
criteria4s-sql-jdbc JDBC (all SQL dialects)
criteria4s-mongodb-driver MongoDB Java Driver
criteria4s-elasticsearch-client Elasticsearch Java Client
criteria4s-clickhouse-client ClickHouse Native Client (v2)

For the full API reference, guides, and integration examples see the documentation site.

License

MIT — Copyright © 2024-2026 Rafael Fernandez