(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| # Add it to Gemfile | |
| gem 'httplog' |
| Typhoeus.get("http://google.com", verbose: true) |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| INSERT INTO creation_metadata (creation_id, category) | |
| SELECT creations.id, creations.type | |
| FROM creations | |
| LEFT JOIN creation_metadata | |
| ON creations.id = creation_metadata.creation_id | |
| WHERE creations.type IS NOT NULL | |
| AND creation_metadata.category IS NULL |
| CREATE OR REPLACE FUNCTION upsert(target_id INT, type_value TEXT) RETURNS VOID AS $$ | |
| BEGIN | |
| -- Try update first | |
| UPDATE creation_metadata SET category = type_value | |
| WHERE creation_id = target_id; | |
| -- Return if UPDATE command runs successfully | |
| IF FOUND THEN | |
| RETURN; | |
| END IF; | |
| -- Since there's no record in creation_metada |
| WITH creations_need_move AS ( | |
| SELECT id, type | |
| FROM creations | |
| WHERE type IS NOT NULL | |
| ), | |
| update_existing_metadata AS ( | |
| UPDATE creation_metadata (creation_id, category) | |
| SET category = source.type | |
| FROM creations_need_move source | |
| WHERE creation_id = source.id |
| INSERT INTO creation_metadata (creation_id, category) | |
| SELECT id, type | |
| FROM creations | |
| ON CONFLICT DO UPDATE SET category = EXCLUDED.type; |