-
Notifications
You must be signed in to change notification settings - Fork 3
/
create-and-fill-table.txt
55 lines (31 loc) · 1.37 KB
/
create-and-fill-table.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Setup a PostgreSQL Database server in a container
sudo docker run --name postgres-server -p 6543:5432 -e POSTGRES_PASSWORD=supersecretpassword -d postgres
Port 6543 => 5432
psql -h localhost -U postgres -d postgres -p 6543
// RAW setup for a table to store some data
CREATE SEQUENCE Posts_id_seq;
CREATE TABLE public.posts
(
id integer NOT NULL DEFAULT nextval('Posts_id_seq'::regclass),
title text COLLATE pg_catalog."default",
body text COLLATE pg_catalog."default",
CONSTRAINT "Posts_pkey" PRIMARY KEY (id)
)
WITH
(
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.posts OWNER to postgres;
// Let's create two inital posts
INSERT INTO posts(title, body)
VALUES('the first title only','and this is the body of the first post.');
INSERT INTO posts(title, body)
VALUES('yet another title','and some more copy text for another body.');
// Uselful curl commands to check out the API
Create ()
curl -X POST 127.0.0.1:8000/posts -H "Content-Type: application/json" -d '{"title": "A new post headline for a new post", "body": "but also a new body text here will appear"}'
Update ()
curl -X PUT 127.0.0.1:8000/posts/3 -H "Content-Type: application/json" -d '{"title": "and this is the new title for post number 1","body": "and the brand new edited body text of post number 1"}'
Delete
curl -X DELETE 127.0.0.1:8000/posts/4 -H "Accept: application/json"