ankane / blazer

Business intelligence made simple
MIT License
4.5k stars 471 forks source link

Allow DB host with characters #457

Closed AliOsm closed 9 months ago

AliOsm commented 9 months ago

Thanks for this great gem, I'm really happy with it :)

I faced a problem recently in a new project that is deployed on a single server with docker using Kamal.

The URI parser is raising an exception when I pass the DB host as the container name like "myapp-postgres".

Is it possible to change the parser or provide a configuration based integration with postgres like Rails? As Rails is accepting the docker name with no issues.

ankane commented 9 months ago

Hi @AliOsm, myapp-postgres should be fine for the hostname, so think it's probably another issue.

AliOsm commented 9 months ago

@ankane Actually there is a problem, when I set:

BLAZER_DATABASE_URL=postgres://mypp:myapp@myapp-postgres:5432/myapp_production

And run a query, I get the following error:

URI::InvalidURIError (the scheme postgres does not accept registry part: myapp:myapp@myapp-postgres:5432 (or bad hostname?))

Which leads to:

lib/blazer/adapters/sql_adapter.rb:14:in `block in initialize'
lib/blazer/adapters/sql_adapter.rb:10:in `initialize'
lib/blazer/adapters/sql_adapter.rb:10:in `new'
lib/blazer/adapters/sql_adapter.rb:10:in `initialize'
lib/blazer/data_source.rb:215:in `new'
lib/blazer/data_source.rb:215:in `adapter_instance'
lib/blazer/data_source.rb:224:in `parameter_binding'
lib/blazer/data_source.rb:173:in `bind_params'
lib/blazer/statement.rb:65:in `bind'
lib/blazer/run_statement.rb:7:in `perform'
app/controllers/blazer/queries_controller.rb:150:in `run'
AliOsm commented 9 months ago

The same configs are working fine with Rails.

ankane commented 9 months ago

Hostnames can't contain underscores. You'll see the same error with Rails if you pass the same URL as the DATABASE_URL.

AliOsm commented 9 months ago

You are right, it works now! Thanks for your helpful response :)