Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8018090

Browse files
README added
1 parent 5f87a56 commit 8018090

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

‎README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!-- TOC -->
2+
3+
- [Docker](#docker)
4+
- [Run the Postgres Container](#run-the-postgres-container)
5+
- [Setting up the Database](#setting-up-the-database)
6+
- [Create a Database](#create-a-database)
7+
- [Add a Table](#add-a-table)
8+
- [Add Data](#add-data)
9+
10+
<!-- /TOC -->
11+
12+
13+
## Docker
14+
15+
### Run the Postgres Container
16+
17+
```bash
18+
docker run -d --rm \
19+
--name postgres \
20+
-e POSTGRES_PASSWORD=secretpassword \
21+
-p 5432:5432 \
22+
postgres:14
23+
```
24+
25+
Connect to the Postgres CLI:
26+
27+
28+
```bash
29+
docker exec -ti -u postgres postgres psql
30+
31+
psql (14.0 (Debian 14.0-1.pgdg110+1))
32+
Type "help" for help.
33+
34+
postgres=#
35+
```
36+
37+
## Setting up the Database
38+
39+
### Create a Database
40+
41+
```sql
42+
CREATE DATABASE books;
43+
```
44+
45+
Switch to using the new books table instead of the default postgres:
46+
47+
48+
```sql
49+
\connect books;
50+
You are now connected to database "books" as user "postgres".
51+
```
52+
53+
54+
### Add a Table
55+
56+
```sql
57+
CREATE TABLE the_expanse (
58+
book_id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
59+
title VARCHAR ( 25 ) UNIQUE NOT NULL,
60+
isbn VARCHAR ( 25 ) UNIQUE NOT NULL,
61+
year INT,
62+
pages INT,
63+
created_on TIMESTAMP NOT NULL
64+
);
65+
```
66+
67+
### Add Data
68+
69+
```sql
70+
INSERT INTO the_expanse
71+
(title, isbn, year, pages, created_on)
72+
VALUES
73+
('Leviathan Wakes', '978-0-316-12908-4', 2011, 592, NOW() - interval '1256 days'),
74+
('Calibans War', '978-1-841-49990-1', 2012, 595, NOW() - interval '993 days'),
75+
('Abaddons Gate', '978-0-316-12907-7', 2013, 539, NOW() - interval '765 days'),
76+
('Cibola Burn', '978-0-316-21762-0', 2014, 583, NOW() - interval '543 days'),
77+
('Nemesis Games', '978-0-316-21758-3', 2015, 544, NOW() - interval '267 days'),
78+
('Babylons Ashes', '978-0-316-33474-7', 2016, 608, NOW() - interval '189 days'),
79+
('Persepolis Rising', '978-0-316-33283-5', 2017, 560, NOW() - interval '122 days'),
80+
('Tiamats Wrath', '978-0-316-33286-6', 2019, 544, NOW() - interval '98 days'),
81+
('Leviathan Falls', '978-0-356-51039-2', 2021, 528, NOW() - interval '21 days');
82+
```
83+
84+
85+
## Node.js Client
86+
87+
### Start the Client
88+
89+
```bash
90+
npm install
91+
node server_express.js
92+
running on http://localhost:8888
93+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /