Currently, a new project which defaults to Pg still depends on all DB shards and they are downloaded when one runs 'shards', including the ones not needed/used:
redis
mysql
sqlite3
This should be sorted out and according to @marksiemers' advice, maybe these should be on app level rather than framework level.
This will require having conditional require statements in some places, not sure what else.
Example: https://github.com/amberframework/amber/blob/master/src/amber/cli/commands/database.cr#L4
This will require having conditional require statements in some places, not sure what else
Yeah, a conditional require would work here, we should use macros though
{% if database == "pg" %}
require "pg"
{% elsif database == "mysql" %}
require "mysql"
{% elsif database == "sqlite" %}
require "sqlite3"
{% end %}
Was this resolved?
@faustinoaq @marksiemers require is a before macro operation. You can't conditionally do requires with macros.
I don't think this should be closed. The macro solution may not work, but something could.
The require statements are done in the CLI, which does make it a challenge - maybe some kind of dependency injection could work, or somehow offloading the operations and dependencies to the app itself.
It may be a for a far future version, but we shouldn't drop it.
馃憤馃徎 I closed it thinking this was addressed in he above PR
require is a before macro operation. You can't conditionally do requires with macros.
@elorest I tested some code, and I think we can try something like this:
VAR = "no" # Try changing this to "yes"
{% if VAR == "yes" %}
require "tempfile"
pp Tempfile.new("foo").path
{% elsif VAR == "no" %}
require "colorize"
pp "foo".colorize(:green)
{% end %}
Or maybe we can use some kind of ECR template to generate db-related files, WDYT?
Based on some playing in carc.in a macro will change what is required: https://carc.in/#/r/3khf
@marksiemers and @faustinoaq can you guys take a shot at addressing this in a PR? I think this can be an easy win :)
@eliasjpr - if the code with the require statements were in the app itself, this would be an easy win, but they are in the CLI. Since that is built independent of any application - that makes this more difficult.
Moving the dependency to each individual app, but having the CLI still work may require re-architecting this whole section of the CLI - not just putting in a couple macro statements.
One way on how we can clean this dependency is by moving the CLI out of the project this way we don't need the DB shards to exist on the Amber repo.
We are going to close this for now and revisit at a later time given that this might required to split the CLI to its own project.
Most helpful comment
Yeah, a conditional
requirewould work here, we should use macros though