No commit activity in last 3 years
No release in over 3 years
Sequel extension that facilitates using crosstab function in postgres
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.14
~> 0.10
~> 10.0
~> 3.0

Runtime

>= 0.17.0
>= 4.0.0
 Project Readme

Sequel::Tablefunc Build Status Gem Version Coverage Status

This is sequel extension makes using crosstab function more convenient

Installation

Add this line to your application's Gemfile:

gem 'sequel-tablefunc'

And then execute:

$ bundle

Usage

Assuming you have table which already have 2 categories. This table can be represented as a pivot table

  User.select_group(:type_id, :status_id)
      .select_append(:count.sql_function('*'.lit))
      .order(:type_id)
      .crosstab(User.select(:status_id).distinct.order(:status_id))
      .all
row_name status1 status2
type1 5 10
type2 1 2

It is easy, isn't it?

  User.select_group(:date_trunc.sql_function('year', :created_at), :status_id)
      .select_append(:count.sql_function('*'.lit))
      .order(:date_trunc.sql_function('year', :created_at))
      .crosstab(User.select(:status_id)
      .distinct
      .order(:status_id))
      .all
row_name status1 status2
2012-01-01 00:00:00 6 nil
2013-01-01 00:00:00 nil 12

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/sequel-tablefunc.