-
-
Notifications
You must be signed in to change notification settings - Fork 67
feat: database-configuration & transaction management + application.conf #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Implements Phase 0 database configuration proposal with auto-configuration and automatic transaction management for Scala 3.7+. Core features: - Auto-configured DbClient from application.conf - @cask.transactional decorator with using syntax - Smart rollback on exceptions and HTTP 4xx/5xx responses - SimpleTable support via scalasql-namedtuples Implementation: - cask.database.DatabaseConfig: Auto-configuration from application.conf - cask.database.transactional: Transaction decorator with using clause - cask.database package: Type aliases and documentation Dependencies (Scala 3.7+ only): - ScalaSql 0.2.3 with scalasql-namedtuples - Typesafe Config for application.conf loading
- Added conditional ScalaSql dependency for Scala 3.7+ builds - Implemented @cask.database.transactional decorator for transaction management - Uses reflection to avoid compile-time dependency on ScalaSql for older Scala versions - Auto-commits on success, rolls back on exceptions or HTTP 4xx/5xx responses - Updated todoDb examples to use scalasql.simple API with SimpleTable pattern - Cross-compilation support for Scala 2.12, 2.13, 3.3.4, and 3.7.3
- Added ClassTag context bound to preserve type information at runtime - Validates type matches at runtime to catch misuse early - Documents type safety approach using Scala's reflection mechanism - Prevents type erasure issues while maintaining cross-compilation compatibility
feat: database configuration & transaction management Issue com-lihaoyi#181
feat: database-configuration & transaction management
- Functional config loader with Either-based error handling and ADT error types - Environment profile support (dev/test/prod) via CASK_ENV variable - Type-safe accessors for string/int/boolean/long/double with optional variants - Config example showing HOCON usage and environment overrides - Updated todoDb example to use config for database path and initial data - Comprehensive test coverage with 7 tests for all config features - Cross-compiles across Scala 2.12, 2.13, 3.3.4, 3.7.3
- Functional config loader with Either-based error handling and ADT error types - Environment profile support (dev/test/prod) via CASK_ENV variable - Type-safe accessors for string/int/boolean/long/double with optional variants - Config example showing HOCON usage and environment overrides - Updated todoDb example to use config for database path and initial data - Comprehensive test coverage with 7 tests for all config features - Cross-compiles across Scala 2.12, 2.13, 3.3.4, 3.7.3
… feature/application-config
…lication-config feat: application config
| * } | ||
| * }}} | ||
| */ | ||
| class transactional[T <: AnyRef : ClassTag](using dbClient: T) extends RawDecorator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop the class tag and just hardcode the compile-time dependency on ScalaSql. If anyone wants an alternative database library, they can define their own decorator to do so, no need to try and make this one generic
| /** Lazily loaded configuration */ | ||
| private lazy val loader: InternalConfig.Loader = | ||
| InternalConfig.Loader.loadOrThrow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the scope of this config? Is it process-scoped, thread-local, or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Configuration is process-scoped and loaded once lazily when first accessed. The config. is immutable after loading; changes to config files require app restart
Added clear documentation
| @@ -1,40 +1,31 @@ | |||
| package app | |||
| import scalasql.DbApi.Txn | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you are removing this import? Seems like it makes all the code in the file a lot more verbose needing to spell out scalasql.core.DbApi.Txn over and over
|
Let's split out the database integration and config-management integration into separate PRs |
|
This PR has been split into two separate PRs as requested:
Both PRs address the review feedback:
Closing this PR in favor of the focused PRs. |
database-configuration & transaction management
application configuration
With
com.typesafe:configand HOCONIssue #181 #183