How can I build a front end for querying a Redshift database (hopefully with Rails)

后端 未结 3 1475
梦谈多话
梦谈多话 2021-02-03 10:59

So I have a Redshift database with enough tables that it feels worth my time to build a front end to make querying it a little bit easier than just typing in SQL commands.

3条回答
  •  耶瑟儿~
    2021-02-03 11:42

    This tutorial helps you setup a rails app with a redshift adapter:

    https://www.credible.com/code/setting-up-a-data-warehouse-with-aws-redshift-and-ruby/

    In a nutshell:

    Clone the sample app:

    git clone git@github.com:tuesy/redshift-ruby-tutorial.git
    cd redshift-ruby-tutorial
    

    Setup ENV Variables via ~/.bashrc (or dotenv):

    export REDSHIFT_HOST=redshift-ruby-tutorial.ccmj2nxbsay7.us-east-1.redshift.amazonaws.com
    export REDSHIFT_PORT=5439
    export REDSHIFT_USER=deploy
    export REDSHIFT_PASSWORD=
    export REDSHIFT_DATABASE=analytics
    export REDSHIFT_BUCKET=redshift-ruby-tutorial
    

    Use the gem activerecord4-redshift-adapter, in Gemfile:

    'activerecord4-redshift-adapter', '~> 0.2.0' # For Rails 4.2
    'activerecord4-redshift-adapter', '~> 0.1.1' # For Rails 4.1
    

    Then you can query into redshift like you would with a normal AR model:

    bundle exec rails c
    RedshiftUser.count
    

    (Disclosure: I havn't yet given this method a try, but I may soon)

提交回复
热议问题