Project

shoden

0.0
No release in over 3 years
Low commit activity in last 3 years
Slim postgres models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.2
~> 0.16

Runtime

~> 1.1
 Project Readme

Shôden - Build Status

Elephant god

Shôden is a persistance library on top of Postgres. Uses JSONB as an storage abstraction so no need for migrations.

Installation

gem install shoden

Connect

Shoden connects by default using a DATABASE_URL env variable. But you can change the connection string by calling Shoden.url=

Setup

Shoden needs a setup method to create the proper tables. You should do that after connecting

Shoden.setup

Models

class Fruit < Shoden::Model
  attribute :type
end
Fruit.create type: "Banana"

To find by an id:

Fruit[1]

Relations

class User < Shoden::Model
  attribute :email

  collection :posts, :Post
end

class Post < Shoden::Model
  attribute :title
  attribute :content

  reference :owner, :User
end

Attributes

Shoden attributes offer you a way to type cast the values, or to perform changes in the data itself.

class Shout < Shoden::Model
  attribute :what, ->(x) { x.uppcase }
end

Indexing

class User < Shoden::Model
  attribute :email
  attribute :country

  index  :country
  unique :email
end

Querying

You can query models or relations using the filter method.

User.filter(email: "elcuervo@elcuervo.net")
User.first
User.last
User.count

You can go through the entire set using: User.all which will give you a Enumerator::Lazy