0.01
No release in over 3 years
Low commit activity in last 3 years
A Rails database driver for ClickHouse
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.1.2
>= 0

Runtime

 Project Readme

Clickhouse rails

Build Status codecov

Install

  1. Add to Gemfile
gem 'clickhouse-rails'
  1. Run bundle
$ bundle install
  1. Init config files and folders
$ rails g clickhouse:install
  1. Change clickhouse.yml at config/clickhouse.yml path

Usage

  1. Create migrations
$ rails g clickhouse:migration add_tmp_table
      create  db/clickhouse/migrate/002_add_tmp_table.rb
  1. Edit file like this:
# db/clickhouse/migrate/002_add_tmp_table.rb
class AddTmpTable < Clickhouse::Rails::Migrations::Base
  def self.up
    create_table :tmp do |t|
      t.date   :date
      t.uint16 :id

      t.engine "MergeTree(date, (date), 8192)"
    end
  end
end
  1. Run migrations
$ rake clickhouse:db:migrate

You can create class of clickhouse table:

# app/models/custom_table.rb
class CustomTable
  include Clickhouse::Table
end

And insert rows like this:

CustomTable.insert_rows([{a:1, b:2}])
CustomTable.insert_row({a:1, b:2})

Alter table migration

  alter_table "analytics_table" do
    fetch_column :new_ids, :uint8 # Adds column new_ids or skip it
  end

TODO:

  1. Rollback migrations
  2. Alter table

Additional clickhouse links