Connecting to a PostgreSQL Server with Spring Boot and jOOQ
What is jOOQ ? jOOQ is a Java library that lets you to generate Java code from the database and lets you write type-safe SQL queries. jOOQ transforms tables in a database into Java classes, which we can use to retrieve or update data. Using jOOQ Library Inititalize Database Tables Execute the SQL statements in src/resources/initial_table.sql file on a Postgres server to create users, categories, transacations tables. initial_table.sql content 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 DROP TABLE IF EXISTS users CASCADE; DROP TABLE IF EXISTS categories CASCADE; DROP TABLE IF EXISTS transactions CASCADE; CREATE TABLE IF NOT EXISTS users ( id BIGINT NOT NULL PRIMARY KEY, username TEXT, email TEXT, updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); CREATE TABLE IF NOT EXISTS categories ( id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY(START WITH 200000000) , user_id BIGINT REFERENCES users(id), name TEXT, active BOOLEAN NOT NULL DEFAULT TRUE, type TEXT, updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); CREATE TABLE IF NOT EXISTS transactions ( id BIGINT NOT NULL PRIMARY KEY, user_id BIGINT REFERENCES users(id), category_id BIGINT REFERENCES categories(id), amount BIGINT, transaction_date DATE NOT NULL DEFAULT CURRENT_DATE, note TEXT, updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); Add jOOQ Dependency To use jOOQ in Spring Boot, we declare a dependency to spring-boot-starter-jooq:...