waterlink / active_record.cr

Active Record pattern implementation for Crystal.
MIT License
191 stars 16 forks source link

Adapter configuration #30

Open sdogruyol opened 8 years ago

sdogruyol commented 8 years ago

We need to have a way to configure the underlying adapter. This is needed for

WDYT @waterlink

alex-fedorov commented 8 years ago

Yeah of course! I expect this list to be waaay longer in the future :)

I would love to have similar configuration to the ruby's AR - through config/database.yml or something.

Though it would be nice to leave an option for 12factor. I.e.: there should be still a possibility to configure everything through environment variables, that are in certain format.

For example, given this config/database.yml file:

override_prefix: MYAPP

adapters:
  postgres:
    username: john
    password: welcome
    hostname: 127.0.0.1
    port: 5432
    timeout: 5000     # ms
    pool: 10

You can for example override hostname with: export MYAPP_ADAPTERS_POSTGRES_HOSTNAME=db.production01.internal.myapp.com and so on.

alex-fedorov commented 8 years ago

Implementation for this should probably sit within active_record.cr codebase. And it should expose some simple integration API for querying, along the lines:

ActiveRecord::Config.adapters.postgres.encoding? || "utf8"
alex-fedorov commented 8 years ago

maybe config file name can be more specific: config/active_record.yml

alex-fedorov commented 8 years ago

Maybe it would be nice to junk in different environments:

override_prefix: MYAPP

environments:
  development:
    adapters:
      postgres:
        # ...
alex-fedorov commented 8 years ago

Or maybe just have different names for files, like Elixir does:

sdogruyol commented 8 years ago

I prefer the AR style