Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elcuervo/shoden
The elephant god
https://github.com/elcuervo/shoden
Last synced: 30 days ago
JSON representation
The elephant god
- Host: GitHub
- URL: https://github.com/elcuervo/shoden
- Owner: elcuervo
- License: mit
- Created: 2014-10-24T19:12:06.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-05-27T15:03:42.000Z (over 3 years ago)
- Last Synced: 2024-04-29T12:20:22.587Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 39.1 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Shôden - [![Build Status](https://travis-ci.org/elcuervo/shoden.svg)](https://travis-ci.org/elcuervo/shoden)
![Elephant god](https://images.unsplash.com/photo-1523190301657-195ef118bb36?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80)
Shôden is a persistance library on top of Postgres.
Uses JSONB as an storage abstraction so no need for migrations.## Installation
```bash
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```ruby
Shoden.setup
```## Models
```ruby
class Fruit < Shoden::Model
attribute :type
end
``````ruby
Fruit.create type: "Banana"
```To find by an id:
```ruby
Fruit[1]
```## Relations
```ruby
class User < Shoden::Model
attribute :emailcollection :posts, :Post
endclass Post < Shoden::Model
attribute :title
attribute :contentreference :owner, :User
end
```## Attributes
Shoden attributes offer you a way to type cast the values, or to perform changes
in the data itself.```ruby
class Shout < Shoden::Model
attribute :what, ->(x) { x.uppcase }
end
```## Indexing
```ruby
class User < Shoden::Model
attribute :email
attribute :countryindex :country
unique :email
end
```## Querying
You can query models or relations using the `filter` method.
```ruby
User.filter(email: "[email protected]")
User.first
User.last
User.count
```You can go through the entire set using: `User.all` which will give you a
`Enumerator::Lazy`