INFO 153B/253B: Backend Web Architecture
Kay Ashaolu
long url http://news.google.com
short url http://bit.ly/awekl
hit count 482240
long url http://facebook.com/user/profile
short url http://bit.ly/czasw
hit count 11023
long url http://msnbc.com/news/article/
short url http://bit.ly/olkjpl
hit count 1232
http://news.google.com, http://bit.ly/awekl, 482240
http://facebook.com/user/profile, http://bit.ly/czasw, 11023
http://msnbc.com/news/article, http://bit.ly/olkjpl, 1232
# Create a volume managed by docker. By default it is stored in a
# subdirectory where docker is stored on your local computer
docker volume create demo-postgres-vol
# Create a container from the image postgres
docker run --name demo-postgres \
-e POSTGRES_USERNAME=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=demo_db \
-v demo-postgres-vol:/var/lib/postgresql/data \
-dit postgres
# See the running logs of your database container
docker logs -f demo-postgres
docker exec -it demo-postgres /bin/bash
psql -U postgres demo_db
CREATE TABLE links (
long_url VARCHAR(1000) NOT NULL,
short_url VARCHAR(20) NOT NULL,
hit_count BIGINT DEFAULT 0,
created DATE
);
INSERT INTO links (long_url, short_url, hit_count, created) VALUES ('http://www.google.com', 'qwelmw', 2, '2016-04-05'),
('http://www.twitter.com', 'adfer', 45, '2016-08-05');
SELECT * FROM links;
long_url |
short_url | hit_count | created |
---|---|---|---|
http://www.google.com |
qwelmw | 2 | 2016-4-5 |
http://www.facebook.com |
adfer | 45 | 2016-8-5 |
SELECT * FROM links WHERE hit_count < 20;
long_url |
short_url | hit_count | created |
---|---|---|---|
http://www.google.com |
qwelmw | 2 | 2016-4-5 |
SELECT * FROM links WHERE hit_count < 20;
long_url | short_url | hit_count | created |
---|---|---|---|
http://www.google.com | qwelmw | 2 | 2016-4-5 |
http://www.twitter.com | eovle | 9 | 2016-10-28 |
INSERT INTO links VALUES
('http://www.twitter.com', 'eovle', 9, '2016-10-28');
SELECT long_url, short_url, hit_count FROM links;
long_url | short_url | hit_count |
---|---|---|
http://www.google.com | qwelmw | 0 |
http://www.facebook.com | adfer | 0 |
http://www.twitter.com | eovle | 9 |
UPDATE links SET hit_count = '0' WHERE created < '2016-10-22';