(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 id, type | |
FROM creations | |
ON CONFLICT DO UPDATE SET category = EXCLUDED.type; |
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 |
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 |
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 |
(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.
Typhoeus.get("http://google.com", verbose: true) |
# Add it to Gemfile | |
gem 'httplog' |
# Install the gem | |
$ bundle install |
# Configure HttpLog to capture the detail we want to know. | |
HttpLog.configure do |config| | |
# Enable or disable all logging | |
config.enabled = true | |
# You can assign a different logger | |
config.logger = Logger.new($stdout) |
irb(main):023:0> uri = URI('http://www.google.com') | |
=> #<URI::HTTP http://www.google.com> | |
irb(main):059:0> Net::HTTP.get(uri) | |
D, [2018-08-13T22:33:30.030400 #19738] DEBUG -- : [httplog] Connecting: www.google.com:80 | |
D, [2018-08-13T22:33:30.055285 #19738] DEBUG -- : [httplog] Sending: GET http://www.google.com:80/ | |
D, [2018-08-13T22:33:30.055377 #19738] DEBUG -- : [httplog] Header: accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3 | |
D, [2018-08-13T22:33:30.055412 #19738] DEBUG -- : [httplog] Header: accept: */* | |
D, [2018-08-13T22:33:30.055579 #19738] DEBUG -- : [httplog] Header: user-agent: Ruby | |
D, [2018-08-13T22:33:30.055605 #19738] DEBUG -- : [httplog] Header: host: www.google.com | |
D, [2018-08-13T22:33:30.055646 #19738] DEBUG -- : [httplog] Data: |