decrel

Declarative data relation library for Scala

Declarative

Define relationships between data types once and reuse them across your application. Let decrel handle the implementation details.

Efficient by Default

Automatically batch multiple queries and run independent operations in parallel. No more N+1 query problems.

Ecosystem Integration

Works with both ZIO and cats-effect. Use with ZQuery, Fetch, or extend to your own effect system.

Type-Safe

Leverage Scala's type system for compile-time guarantees about your data access patterns.

Composition-First

Build complex data access patterns by composing simple relations with intuitive operators.

Testable

The same relations used for data fetching can generate test data with ScalaCheck or ZIO Test.

decrel - Declarative Data Relations in Scala

decrel allows you to model relationships between your domain entities and efficiently fetch interconnected data with automatic batching and parallelism.

// Define your domain model relations
object Post {
  object author extends Relation.Single[Post, Author]
  object comments extends Relation.Many[Post, List, Comment]
}

// Create a complex query
val postWithDetails = Post.author & Post.comments

// Execute the query efficiently
for {
  post <- getPost(postId)
  (author, comments) <- postWithDetails.toZIO(post)
  // Use author and comments...
} yield ()

Why decrel?

  • Solve N+1 Query Problems: Automatically batch and parallelize data fetches
  • Reuse Access Patterns: Define relations once, use them anywhere
  • Improve Maintainability: Keep your domain model and data access cleanly separated
  • Scale Efficiently: As your application grows, your data access remains optimized

Community