Skip to content

Commit

Permalink
spider: publisher and publisher_feed, add updated_at
Browse files Browse the repository at this point in the history
This will be used in:
#18
#39
  • Loading branch information
odscjames committed Jun 25, 2020
1 parent 5dc304d commit 808d85a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE publisher ADD updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL default (now() at time zone 'utc');
ALTER TABLE publisher_feed ADD updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL default (now() at time zone 'utc');
10 changes: 8 additions & 2 deletions src/lib/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ async function write_publisher(data) {
publisher_id = res_add_publisher.rows[0].id;
} else {
publisher_id = res_find_publisher.rows[0].id;
const res_add_publisher = await client.query(
'UPDATE publisher SET name=$1, url=$2, data=$3 WHERE id=$4',
await client.query(
'UPDATE publisher SET name=$1, url=$2, data=$3, updated_at=(now() at time zone \'utc\') WHERE id=$4',
[data.name, data.url, data.data, publisher_id]
);
}
Expand All @@ -110,6 +110,12 @@ async function write_publisher(data) {
const res_find_feed = await client.query('SELECT * FROM publisher_feed WHERE url = $1', [data.data_urls[idx].url]);
if (res_find_feed.rowCount == 0) {
const res_add_feed = await client.query('INSERT INTO publisher_feed (publisher_id, name, url) VALUES ($1, $2, $3) RETURNING id', [publisher_id, data.data_urls[idx].name, data.data_urls[idx].url]);
} else {
const publisher_feed_id = res_find_feed.rows[0].id;
await client.query(
'UPDATE publisher_feed SET name=$1, updated_at=(now() at time zone \'utc\') WHERE id=$2',
[data.data_urls[idx].name, publisher_feed_id]
);
}
}

Expand Down

0 comments on commit 808d85a

Please sign in to comment.