code
Clone this repository
https://tangled.org/gdiazlo.tngl.sh/repodb
git@tangled.org:gdiazlo.tngl.sh/repodb
For self-hosted knots, clone URLs may differ based on your setup.
Connect the Query DSL module to Repo for direct query execution:
- all_query: Execute SELECT, return list of decoded results
- one_query: Execute SELECT, return first row or Not_found error
- one_query_opt: Execute SELECT, return first row as option
- insert_query: Execute INSERT query
- update_query: Execute UPDATE query
- delete_query: Execute DELETE query
- insert/update/delete_query_returning: Variants with RETURNING
Add 10 integration tests covering:
- Basic all_query usage
- WHERE clause filtering with Expr.raw
- one_query with and without results
- one_query_opt behavior
- ORDER BY and LIMIT
- INSERT/UPDATE/DELETE via Query
- Complex query with multiple conditions
Tests: 168 unit + 89 SQLite integration
- Add Ecto-like preloading to solve N+1 queries:
- preload_has_many, preload_has_one, preload_belongs_to
- preload_many_to_many for junction tables
- preload_chunked for streaming large datasets
- Rewrite Multi module for composable database transactions:
- Named steps with typed results
- Dependent operations (access previous results)
- Automatic transaction wrapping with rollback on failure
- insert/update/delete with _fn and _returning variants
- Add comprehensive error tests:
- SQLite: 17 error scenarios
- PostgreSQL: 13 error scenarios
- Covers constraint violations, syntax errors, connection failures
- Add driver abstraction layer (lib/driver.ml)
- Split into 3 opam packages: repodb, repodb-sqlite, repodb-postgresql
Tests: 168 unit + 79 SQLite integration + 82 PostgreSQL integration
Allocation optimizations:
- Switch changeset.changes from assoc list to StringMap (O(log n) lookups)
- Add Buffer-based SQL generation (to_sql_buf) in expr.ml
- Replace List.rev + List.map with List.rev_map in query.ml
- Add named operator functions (eq, lt, add, etc.) to avoid shadowing stdlib
Streaming API (lib/stream.ml):
- fold/iter for memory-efficient result processing
- with_cursor for PostgreSQL cursor-based streaming
- Sync helpers: fold_list, iter_list, to_seq, filter_map, take, drop, chunks
- Configurable batch_size and max_rows
167 tests passing (11 new stream tests)
- Rename all lib/mlecto_*.ml to simple names (types.ml, schema.ml, etc.)
- Add assoc.ml for associations (has_many, belongs_to, has_one, many_to_many)
- Add embedded.ml for embedded schemas with pluggable JSON
- Refactor changeset.ml for pipe-friendly API (t argument last)
- Enhanced repo.ml with transactions and SQL builders
- Comprehensive test suite with 156 passing tests
Core modules:
- Type: GADT type witnesses with Caqti integration
- Schema: Table/column DSL with constraints and SQL generation
- Expr: Full expression GADT (operators, aggregates, functions)
- Query: SELECT/INSERT/UPDATE/DELETE with JOINs, upserts
- Changeset: Type-safe validations and constraints
- Repo: SQL builders, transaction state machine with savepoints
- Migration: DSL + runner with version tracking, plan/rollback
- Multi: Operation chaining with named results, atomic execution
- Error: Comprehensive error types
All modules compile, tests pass.