https://github.com/solnic/rom-workshop
https://github.com/solnic/rom-workshop
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/solnic/rom-workshop
- Owner: solnic
- Created: 2019-05-11T14:50:32.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-17T18:32:36.000Z (about 6 years ago)
- Last Synced: 2025-04-24T07:16:11.032Z (about 1 month ago)
- Language: Ruby
- Size: 27.3 KB
- Stars: 5
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Persistence with rom-rb
## Exercises
### Setup
- [ ] `bundle install`
### Getting started, writing data
- [ ] Write a migration for an "articles" table
- `id` primary key, `title` text, and `published` boolean columns
- [ ] Create a relation (with inferred schema)
- [ ] Create a repo for the relation
- [ ] Create some records
- enable `create` command on repo
- [ ] Use `#by_pk` to read records back
- [ ] Update some records
- enable `update` comand on repo using `by_pk` restriction### Building queries
- [ ] Add methods to repository to query and return multiple records
- [ ] listing of published articles
- [ ] Move lower-level query methods into relation
- `#published` method in relation
- update repository to use this method
- create some articles where published is both true and false, ensure they're returned as appropriate
- [ ] Add methods to repository to return single records
- [ ] Create shared `articles` method in repository to ensure all query methods return only published articles
- [ ] Return results as custom structs via a custom struct namespace### Reading aggregates
- [ ] Write a migration for an associated "authors" table
- `id` primary key and `name` text column
- add `author_id` foreign key to "articles" table
- [ ] Add a relation for the table and declare associations
- declare `belongs_to :author` association in "articles" relation
- [ ] Create a repository for authors, with "create" command enabled
- [ ] Create author records
- [ ] Create article records with `author_id` attribute filled
- [ ] In "articles" repository, return aggregate objects including the articles' authors### Changesets
- [ ] Implement `publish(author, article)` in the articles repository that will use `:create` changeset to create a new article, mark it as published and associate with the author
- [ ] Implement `unpublish(article)` in the articles repository that will use `:update` changeset to mark the article as not published## Further exploration...
### Building queries
- [ ] Return custom structs using `map_to`
- [ ] Investigate using dry-struct to build custom struct classes with strict attribute types### Testing
- [ ] Write tests for your repository methods
- Use rom-factory to create records
- Write tests to assert that repository methods return appropriate records