This file provides guidance to coding agents working with code in this repository.
Slick is a functional relational mapping (FRM) library for Scala that provides type-safe, composable database access.
It's a multi-module sbt project; build.sbt defines the modules.
# Clean and compile all modules. The sbt 2 runner joins all arguments into one command line,
# so separate multiple commands with ';' inside a single quoted argument.
sbt "clean; compile"
# Compile under each supported Scala version. `++2.13.x` switches every project to the 2.13 version listed in
# `crossScalaVersions`
sbt ++2.12.x compile
sbt ++2.13.x compile
sbt ++3.x compile
# Generate API documentation
sbt docRead DEVELOPING.md before running tests. It covers the setting needed to load the build in a linked
git worktree, how to select testkit tests (testOnly patterns and the arguments after --), how to set system
properties in the forked test JVMs, and how to enable the service databases.
# Build capabilities documentation table
sbt testkit/buildCapabilitiesTable
# Run compatibility report
sbt site/buildCompatReport
# Check current version
sbt "show version"- AST Layer (
slick.ast): Immutable query representation with a comprehensive type system - Compiler Layer (
slick.compiler): Multi-phase query compilation pipeline - Lifted Embedding (
slick.lifted): Type-safe DSL for database queries - Profile System: Database-specific implementations (H2Profile, PostgresProfile, etc.)
- Backend/JDBC (
slick.jdbc): SQL generation and database execution
- QueryCompiler: Immutable, configurable compilation pipeline with 20+ phases
- Profile: Database abstraction layer with capability-based feature detection
- DBIOAction: Monadic database operations with async support and effect tracking
- Table/Query: Core abstractions for database schema and queries
- Rep[T]: Lifted representation of database values with type safety
- Shape System: Type-level mapping between Scala types and database representations
Slick supports multiple databases through profile-based architecture:
- Production databases: PostgreSQL, MySQL, SQL Server, Oracle, DB2
- Embedded databases: H2, Derby, HSQLDB, SQLite
- In-memory testing: Heap-based database for unit tests
- Profile hierarchy: BasicProfile → RelationalProfile → SqlProfile → JdbcProfile → Specific profiles
slick/src/main/scala/slick/
├── ast/ # Abstract syntax tree and comprehensive type system
├── compiler/ # Multi-phase query compilation pipeline (20+ phases)
├── lifted/ # Type-safe query DSL with Rep[T] and Query[E,U,C]
├── jdbc/ # JDBC backend and database-specific profiles
├── basic/ # Basic profile abstraction and backend
├── relational/ # Relational database abstractions
├── sql/ # SQL-specific functionality and capabilities
├── memory/ # In-memory heap database support
├── dbio/ # Database I/O action system with effect tracking
└── util/ # Utilities including tuple support and helpers
slick-testkit/src/
├── main/scala/ # Testkit framework, utilities, and test definitions
├── test/scala/ # Profile-specific unit tests and benchmarks
├── codegen/ # Code generation tests
└── doctest/ # Documentation example tests
Tests use Typesafe Config for database configuration:
- testkit-reference.conf: Defines test database configurations and test classes
- Multi-database support: PostgreSQL, MySQL, Oracle, DB2, SQL Server, H2, Derby, HSQLDB, SQLite
- Test grouping: Database-specific test groups with controlled concurrency
- Environment-specific configs: GitHub Actions configurations in
test-dbs/ - Key test databases: H2 (default for fast testing), PostgreSQL, MySQL (for production database testing)
- TestDB abstraction: Database-specific test configurations with capability detection
- ResultSetAction: Use for custom metadata queries with proper connection context
- Database cleanup: Override
dropUserArtifactsfor database-specific cleanup logic - CI configuration: Use
test-dbs/testkit.github-actions.conffor CI-specific database settings - Test concurrency: Database tests are grouped and run with controlled parallelism
- Cross-compilation: Supports Scala 2.12, 2.13, and 3.x with version-specific optimizations
- Custom tasks:
testAllruns comprehensive test suite across all modules - Dependencies: Managed in
project/Dependencies.scalawith version centralization - Test concurrency: Configured with test group tags to limit concurrent database tests
- Forked tests: Database tests run in forked JVMs for isolation
The project uses a custom versioning system:
- Custom Versioning:
project/Versioning.scalacontrols version format (e.g.,3.7.0-pre.32.abc123.dirty) - SBT Integration: Custom plugin overrides sbt-ci-release to use the custom versioning scheme
- Version Policy: Uses sbt-version-policy for compatibility checking across versions
- Pattern Matching: Internal dependency version changes are filtered using regex patterns in
versionPolicy.sbt
Slick uses a custom CompatReportPlugin that integrates with sbt-version-policy and MiMa for binary compatibility
checking:
- Binary Compatibility: Uses MiMa to detect breaking changes in public APIs
- Source Compatibility: Tracks changes that break source compatibility
- Dependency Tracking: Monitors internal module dependencies for version consistency
- GitHub Integration: Automatically posts compatibility reports on PRs via GitHub Actions
- Internal Dependencies: Filtered using
versionPolicyIgnoredInternalDependencyVersionsto avoid noise - MiMa Filters: Exclusions defined in
slick/src/main/mima-filters/for legitimate breaking changes - Compatibility Reports: Generated via
sbt site/buildCompatReportand posted to PRs automatically
# Generate compatibility report manually
sbt site/buildCompatReport
# Check version policy compliance
sbt versionPolicyCheck
# Test with specific previous version
sbt 'set every CompatReportPlugin.previousRelease := Some("3.6.1-pre.123.abc"); site/buildCompatReport'
# Show current version policy settings
sbt "show versionPolicyIgnored"
sbt "show versionPolicyIgnoredInternalDependencyVersions"- Profile-specific compilers: Each database profile has customized compilation
- Phase modification: Phases can be added, removed, or replaced
- Debug support: Compilation logging and AST dumping capabilities
- Type system integration: Comprehensive type annotations throughout compilation
- Immutable nodes: All AST nodes are immutable with structural sharing
- Type system: Comprehensive type annotations with
TypedType[T]throughout the AST - Node transformation: Pattern matching and tree rewriting for optimizations
- Symbol management: Unique symbol generation and resolution
- Capability-based: Each profile declares supported database features
- SQL generation: Profile-specific SQL builders and formatters
- Type mapping: Database-specific type conversions and encodings
- Feature detection: Runtime capability checking for database features
- Follow Scala best practices and existing codebase patterns
- Leverage the type system for compile-time safety
- Write comprehensive tests for new features
- Use immutable data structures throughout
- New features should work across supported databases
- Use capability system to handle database-specific features
- Test against multiple database profiles
- Handle database-specific SQL generation in profiles
- Type inference issues: Check
slick.ast.Typesystem andTypedTypeimplicits - Implicit resolution: Review
ShapeandTypedTypeimplicits inslick.lifted - Compiler phases: Debug with
QueryCompilerlogging and AST dump - Scala 3 compatibility: Check version-specific source directories
- SQL generation: Log the executed SQL with
-Dlog.jdbc.statement=debug(see "Setting system properties for tests" in DEVELOPING.md) - Database-specific features: Verify profile capabilities
- "Relation already exists" errors: Usually indicates database cleanup issues between tests. Check
dropUserArtifactsimplementations in test database configurations
- Cross-Database DDL Compatibility: When generating code from one database profile for use with another, be aware of capability differences (e.g., H2's features vs Derby's limitations)
- Type inference changes: Scala 3 has different type inference behavior
- Match types: Use Scala 3's match types for type-level programming
- Anonymous class handling: Be aware of changes in anonymous class generation
- Coverage instrumentation: Some Scala 3 versions have issues with coverage tools
slick-testkit/src/main/scala/com/typesafe/slick/testkit/util/TestDB.scala: Test database managementslick-testkit/src/main/scala/com/typesafe/slick/testkit/util/StandardTestDBs.scala: Standard test configurationstest-dbs/testkit.github-actions.conf: CI-specific database configurationsdocker-compose.yml: Local database setup for testing
project/Versioning.scala: Custom versioning logic with sbt-ci-release integrationproject/CompatReportPlugin.scala: Custom compatibility checking pluginversionPolicy.sbt: Version policy configuration and internal dependency filteringproject/Dependencies.scala: Centralized dependency management with version coordination
slick/src/main/scala-3/slick/lifted/ShapedValue.scala: Scala 3-specific implementationsslick/src/main/scala/slick/lifted/Rep.scala: Core representation types
- JDBC driver upgrades: Always test against multiple database versions when updating drivers
- Metadata API changes: DatabaseMetaData behavior can change between driver versions, especially catalog parameter handling
- Test isolation: Database cleanup between tests relies on proper metadata queries
- Cross-compilation: Test thoroughly across Scala 2.12, 2.13, and 3.x
- Type inference: Be aware of Scala 3's different type inference behavior
- Anonymous classes: Changes in anonymous class generation can affect type casting
- Use H2 for fast local testing: Default database for rapid development cycles
- Test with real databases: Use PostgreSQL/MySQL for production-like testing
- Database cleanup: Ensure proper cleanup between tests to avoid "relation exists" errors
- Test grouping: Respect database-specific test groups for concurrency control
- Custom versioning precedence: The
Versioningplugin requiresCiReleasePluginto ensure proper load order - Version format: Follows pattern
X.Y.Z-pre.N.SHA[.dirty]for development builds - Compatibility filtering: Internal dependency changes are filtered using regex patterns to avoid CI noise
- MiMa integration: Binary compatibility is checked using MiMa with custom exclusion filters