Project

superstore

0.01
Low commit activity in last 3 years
No release in over a year
ActiveModel-based JSONB document store
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 6.1

Runtime

 Project Readme

Superstore

Ruby Code Climate Gem

Superstore is a PostgreSQL JSONB document store which uses ActiveModel to mimic much of the behavior in ActiveRecord.

Requirements

Superstore requires PostgreSQL 9.5 or above.

Installation

Add the following to the Gemfile:

gem 'superstore'

Superstore will share the existing ActiveRecord database connection.

Defining Models

class Widget < Superstore::Base
  attribute :name, type: :string
  attribute :price, type: :integer
  attribute :colors, type: :array

  validates :name, presence: :true

  before_create do
    self.description = "#{name} is the best product ever"
  end
end

The table name defaults to the case-sensitive, pluralized name of the model class. To specify a custom name, set the table_name attribute on the class:

class MyWidget < Superstore::Base
  table_name = 'my_widgets'
end

Creating and updating records

Superstore has equivalent methods to ActiveRecord:

widget = Widget.new
widget.valid?
widget = Widget.create(name: 'Acme', price: 100)
widget.update_attribute(:price, 1200)
widget.update(price: 1200, name: 'Acme Corporation')
widget.attributes = {price: 300}
widget.price_was
widget.save
widget.save!