Skip to content

Commit e8d7e37

Browse files
committed
initial commit
0 parents  commit e8d7e37

35 files changed

+1530
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# java-cli-bloop-sbt-postgres-data-type-user-defined
2+
3+
## Description
4+
Creates a small database table
5+
called `dog`. This table, `dog`, has been normalized to 3NF.
6+
Two new tables have been added, `breedLookup` and `colorLookup`.
7+
8+
Creates a new table `dog_expanded` that joins
9+
`dog`, `breedLookup` and `colorLookup`. Added clustered indexes on
10+
`dog`.breedId and `dog`.colorId.
11+
12+
Turned `dog_expanded` into a view with an implicit index on `dog_expanded`.id.
13+
14+
Defined a type `type_int_int` that acts as a return type.
15+
Using table function with the aggregate function
16+
COUNT, create a new view `breed_count`.
17+
18+
All output normally
19+
seen in a terminal will be in `java-srv/log` which will dump to the screen. The project may seem to hang but the logs from the container must be written to the project this can take up to 3 min.
20+
21+
Compiled and ran from build server `bloop`.
22+
23+
# Build note
24+
Dependencies must be compatable with jdk8 or less.
25+
26+
## Tech stack
27+
- bloop
28+
- java
29+
- bloop-sbt
30+
- log4j
31+
- postgres driver
32+
33+
## Docker stack
34+
- hseeberger/scala-bloop-sbt:11.0.2-oraclelinux7_1.3.5_2.12.10
35+
- postgres
36+
37+
## To run
38+
`sudo ./install.sh -u`
39+
Creates java-srv/log
40+
41+
## To stop
42+
`sudo ./install.sh -d`
43+
Removes java-srv/log
44+
45+
## For help
46+
`sudo ./install.sh -h`
47+
48+
## Credit
49+
- [Pretty sql print](https://github.com/htorun/dbtableprinter)
50+
- [User defined type](https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-user-defined-data-types/)

db/data_dump.tar.gz

45 Bytes
Binary file not shown.

db/sql/00-create-table.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE SEQUENCE dog_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1;
2+
3+
CREATE TABLE "public"."dog" (
4+
"id" integer DEFAULT nextval('dog_id_seq') NOT NULL,
5+
"breedId" integer NOT NULL,
6+
"colorId" integer NOT NULL
7+
) WITH (oids = false);

db/sql/01-table-insert.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
INSERT INTO "animal"."public"."dog" ("breedId", "colorId")
2+
VALUES
3+
(1, 1),
4+
(1, 2),
5+
(1, 3),
6+
(2, 2),
7+
(3, 2),
8+
(3, 3),
9+
(4, 3),
10+
(4, 4);

db/sql/02-create-table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE SEQUENCE breedLookup_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1;
2+
3+
CREATE TABLE "public"."breedLookup" (
4+
"id" integer DEFAULT nextval('breedLookup_id_seq') NOT NULL,
5+
"breed" text NOT NULL
6+
) WITH (oids = false);

db/sql/03-table-insert.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSERT INTO "animal"."public"."breedLookup" (breed)
2+
VALUES
3+
('Am Bulldog'),
4+
('Blue Tick'),
5+
('Labrador'),
6+
('Gr Shepard');

db/sql/04-create-table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE SEQUENCE colorLookup_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1;
2+
3+
CREATE TABLE "public"."colorLookup" (
4+
"id" integer DEFAULT nextval('colorLookup_id_seq') NOT NULL,
5+
"color" text NOT NULL
6+
) WITH (oids = false);

db/sql/05-table-insert.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSERT INTO "animal"."public"."colorLookup" (color)
2+
VALUES
3+
('White'),
4+
('Grey'),
5+
('Black'),
6+
('Brown');

db/sql/06-create-table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE "public"."dog_expanded" AS (
2+
SELECT a.id, b.breed, c.color
3+
FROM dog AS a
4+
JOIN "breedLookup" AS b ON b.id = a."breedId"
5+
JOIN "colorLookup" AS c ON c.id = a."colorId"
6+
);

db/sql/07-create-index.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE INDEX "IDX_breed" on dog("breedId");
2+
CREATE INDEX "IDX_color" on dog("colorId");

0 commit comments

Comments
 (0)