Shôden is a persistance library on top of Postgres. Uses JSONB as an storage abstraction so no need for migrations.
Installation
gem install shodenConnect
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.setupModels
class Fruit < Shoden::Model
attribute :type
endFruit.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
endAttributes
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 }
endIndexing
class User < Shoden::Model
attribute :email
attribute :country
index :country
unique :email
endQuerying
You can query models or relations using the filter method.
User.filter(email: "elcuervo@elcuervo.net")
User.first
User.last
User.countYou can go through the entire set using: User.all which will give you a
Enumerator::Lazy