Giter VIP home page Giter VIP logo

superstore's Introduction

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!

superstore's People

Contributors

matthuhiggins avatar nzkoz avatar grantr avatar malept avatar ryanking avatar jamesgolick avatar kadwanev avatar dcromer avatar forresty avatar betesh-at-data-axle avatar quainjn avatar josh avatar ebarendt avatar monde avatar johnkeith avatar tomafro avatar aschlick avatar alexmooney avatar jmhodges avatar j1wilmot avatar kunruh9 avatar matthinea avatar doolin avatar bullfight avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.