feat(examples): add PostgreSQL example with user relationship

Adds an example demonstrating user, comment, and follower relationship
including:
- User management with profiles
- Comments (not really useful, just for showcasing)
- Follower/follozing relationships
- Ineractive CLI interface with CRUD operations
- Database migrations for the example schema
This commit is contained in:
2025-06-05 23:56:15 +02:00
parent 9e56952dc6
commit 190c4d7b1d
23 changed files with 1199 additions and 85 deletions

View File

@@ -0,0 +1,4 @@
DROP TABLE IF EXISTS Followers;
DROP TABLE IF EXISTS Comments;
DROP TABLE IF EXISTS Profiles;
DROP TABLE IF EXISTS Users;

View File

@@ -0,0 +1,30 @@
-- Add migration script here
CREATE TABLE Users (
id SERIAL PRIMARY KEY,
username VARCHAR(100) UNIQUE NOT NULL
);
CREATE TABLE Profiles (
id SERIAL PRIMARY KEY,
user_id INT UNIQUE NOT NULL,
bio TEXT,
display_name VARCHAR(100),
FOREIGN KEY (user_id) REFERENCES Users(id)
);
CREATE TABLE Comments (
id SERIAL PRIMARY KEY,
author_id INT NOT NULL,
content TEXT NOT NULL,
FOREIGN KEY (author_id) REFERENCES Users(id)
);
CREATE TABLE Followers (
id SERIAL PRIMARY KEY,
followed INT NOT NULL,
follower INT NOT NULL,
FOREIGN KEY (followed) REFERENCES Users(id) ON DELETE CASCADE,
FOREIGN KEY (follower) REFERENCES Users(id) ON DELETE CASCADE,
CHECK (followed != follower),
UNIQUE (followed, follower)
);