Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the insert statements for the defined db #9

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[go]": {
"editor.defaultFormatter": "golang.go"
},
"[sql]": {
"editor.defaultFormatter": "inferrinizzard.prettier-sql-vscode"
}
}
200 changes: 145 additions & 55 deletions internal/db/sqlite/queries.sql
Original file line number Diff line number Diff line change
@@ -1,68 +1,158 @@
-- name: CreateResource :exec
INSERT INTO resources (id, title, content_md, image_url, resource_type, resource_list_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?);
INSERT INTO
resource (
uuid,
title,
content_md,
image_url,
resource_type,
created_at,
updated_at,
deleted_at
)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?);

-- name: CreateResourceList :exec
INSERT INTO resource_lists (title, created_at, updated_at) VALUES (?, ?, ?);
-- name: CreateEvent :exec
INSERT INTO
event (
uuid,
location,
start_at,
end_at,
is_all_day,
host,
visibility
)
VALUES
(?, ?, ?, ?, ?, ?, ?);

-- name: CreatePerson :exec
INSERT INTO
person (uuid, name, preferred_pronoun)
VALUES
(?, ?, ?);

-- name: CreateResourceReference :exec
INSERT INTO resource_references (resource_id, resource_list_id, created_at, updated_at) VALUES (?, ?, ?, ?);
-- name: CreateResourceGroupMapping :exec
INSERT INTO
resource_id_group_id_mapping (
resource_uuid,
group_uuid,
type,
created_at,
updated_at,
deleted_at
)
VALUES
(?, ?, ?, ?, ?, ?);

-- name: GetResourceList :many
SELECT rr.resource_id, rr.resource_list_id, rr.created_at, rr.updated_at
FROM resource_references rr
JOIN resources r ON rr.resource_id = r.id
JOIN resource_lists rl ON rr.resource_list_id = rl.id
WHERE rl.id = ?
ORDER BY rr.index_in_list ASC;
-- name: CreateGroupResourceMapping :exec
INSERT INTO
group_id_resource_list_mapping (
group_uuid,
resource_uuid,
index_in_list,
created_at,
updated_at,
deleted_at
)
VALUES
(?, ?, ?, ?, ?, ?);

-- name: AddResource :exec
INSERT INTO resource_references (resource_id, resource_list_id, index_in_list, created_at, updated_at) VALUES (?, ?, ?, ?, ?);
-- name: CreateAnnouncement :exec
INSERT INTO
announcement (
uuid,
event_groups_group_uuid,
approved_by_list_uuid,
visibility,
announce_at,
discord_channel_id,
discord_message_id
)
VALUES
(?, ?, ?, ?, ?, ?, ?);

-- name: DeleteResource :exec
DELETE FROM resources WHERE id = ?;
DELETE FROM resource
WHERE
id = ?;

-- name: CreateEvent :exec
INSERT INTO events (id, location, start_at, duration_ms, is_all_day, host, visibility) VALUES (?, ?, ?, ?, ?, ?, ?);
-- name: GetResource :exec
SELECT
uuid,
title,
content_md,
image_url,
resource_type,
created_at,
updated_at,
deleted_at
from
resource
where
uuid = ?;

-- name: GetEvent :one
-- name: GetEvent :exec
SELECT
r.id,
r.title,
r.content_md,
r.image_url,
r.resource_type,
r.resource_list_id,
r.created_at,
r.updated_at,
e.location,
e.start_at,
e.duration_ms,
e.is_all_day,
e.host,
e.visibility
FROM resources r
INNER JOIN events e ON r.id = e.id
WHERE r.id = ?;
uuid,
location,
start_at,
end_at,
is_all_day,
host,
visibility
from
event
where
uuid = ?;

-- name: CreateAnnouncement :exec
INSERT INTO announcements (id, event_list_id, approved_by_list_id, visibility, announce_at, discord_channel_id, discord_message_id) VALUES (?, ?, ?, ?, ?, ?, ?);
-- name: GetPerson :exec
SELECT
uuid,
name,
preferred_pronoun
from
person
where
uuid = ?;

-- name: GetResourceGroupMapping :exec
SELECT
resource_uuid,
group_uuid,
type,
created_at,
updated_at,
deleted_at
from
resource_id_group_id_mapping
where
resource_uuid = ?;

-- name: GetGroupResourceMapping :exec
SELECT
group_uuid,
resource_uuid,
index_in_list,
created_at,
updated_at,
deleted_at
from
group_id_resource_list_mapping
where
group_uuid = ?;

-- name: GetAnnouncement :one
-- name: GetAnnouncement :exec
SELECT
r.id,
r.title,
r.content_md,
r.image_url,
r.resource_type,
r.resource_list_id,
r.created_at,
r.updated_at,
a.event_list_id,
a.approved_by_list_id,
a.visibility,
a.announce_at,
a.discord_channel_id,
a.discord_message_id
FROM resources r
INNER JOIN announcements a ON r.id = a.id
WHERE r.id = ?;
uuid,
event_groups_group_uuid,
approved_by_list_uuid,
visibility,
announce_at,
discord_channel_id,
discord_message_id
from
announcements
where
uuid = ?;
115 changes: 58 additions & 57 deletions internal/db/sqlite/schema.sql
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
-- Language: sqlite

-- Create the 'resource_mapping' table.
CREATE TABLE IF NOT EXISTS resource_id_group_id_mapping (
resource_uuid TEXT REFERENCES resource(uuid),
group_uuid TEXT NOT NULL REFERENCES group_resource_list_mapping(uuid),
type TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP DEFAULT NULL,
);
CREATE TABLE
IF NOT EXISTS resource_id_group_id_mapping (
resource_uuid TEXT REFERENCES resource (uuid),
group_uuid TEXT NOT NULL REFERENCES group_resource_list_mapping (uuid),
type TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP DEFAULT NULL,
);

CREATE TABLE IF NOT EXISTS group_id_resource_list_mapping (
group_uuid TEXT,
resource_uuid TEXT NOT NULL REFERENCES resource(uuid),
index_in_list INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP DEFAULT NULL,
);
CREATE TABLE
IF NOT EXISTS group_id_resource_list_mapping (
group_uuid TEXT,
resource_uuid TEXT NOT NULL REFERENCES resource (uuid),
index_in_list INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP DEFAULT NULL,
);

-- Create the 'resource' table.
CREATE TABLE IF NOT EXISTS resource (
uuid TEXT PRIMARY KEY,
title TEXT NOT NULL,
content_md TEXT NOT NULL,
image_url TEXT,
resource_type TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP DEFAULT NULL,
);
CREATE TABLE
IF NOT EXISTS resource (
uuid TEXT PRIMARY KEY,
title TEXT NOT NULL,
content_md TEXT NOT NULL,
image_url TEXT,
resource_type TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP DEFAULT NULL,
);

-- Create the 'events' table which is a table of event resources.
CREATE TABLE IF NOT EXISTS event (
uuid TEXT PRIMARY KEY REFERENCES resource(uuid),
location TEXT NOT NULL,
start_at NUMBER NOT NULL, -- Start time in UTC milliseconds.
end_at NUMBER NOT NULL,
is_all_day BOOLEAN NOT NULL,
host TEXT NOT NULL, -- Accepts team ID or plain text.
visibility TEXT NOT NULL, -- Accepts 'public' or 'private'.
)

-- Create the 'person' table which is a table of person resources.
CREATE TABLE IF NOT EXISTS person (
uuid TEXT REFERENCES resource(uuid),
name TEXT,
preferred_pronoun TEXT
)

-- Create the 'announcement' table which is a table of announcement resources.
CREATE TABLE IF NOT EXISTS announcement (
uuid TEXT PRIMARY KEY REFERENCES resource(uuid),
event_groups_group_uuid TEXT REFERENCES resource_group_mapping(resource_uuid),
approved_by_list_uuid TEXT REFERENCES group_id_resource_list_mapping(uuid),
visibility TEXT NOT NULL, -- Accepts 'public' or 'private'.
announce_at INTEGER NOT NULL, -- UTC milliseconds.
discord_channel_id TEXT, -- Discord channel ID.
discord_message_id TEXT, -- Discord message ID. If present, the announcement has been posted.
UNIQUE (id)
)


CREATE TABLE
IF NOT EXISTS event (
uuid TEXT PRIMARY KEY REFERENCES resource (uuid),
location TEXT NOT NULL,
start_at NUMBER NOT NULL, -- Start time in UTC milliseconds.
end_at NUMBER NOT NULL,
is_all_day BOOLEAN NOT NULL,
host TEXT NOT NULL, -- Accepts team ID or plain text.
visibility TEXT NOT NULL, -- Accepts 'public' or 'private'.
)
-- Create the 'person' table which is a table of person resources.
CREATE TABLE
IF NOT EXISTS person (
uuid TEXT REFERENCES resource (uuid),
name TEXT,
preferred_pronoun TEXT
)
-- Create the 'announcement' table which is a table of announcement resources.
CREATE TABLE
IF NOT EXISTS announcement (
uuid TEXT PRIMARY KEY REFERENCES resource (uuid),
event_groups_group_uuid TEXT REFERENCES resource_group_mapping (resource_uuid),
approved_by_list_uuid TEXT REFERENCES group_id_resource_list_mapping (uuid),
visibility TEXT NOT NULL, -- Accepts 'public' or 'private'.
announce_at INTEGER NOT NULL, -- UTC milliseconds.
discord_channel_id TEXT, -- Discord channel ID.
discord_message_id TEXT, -- Discord message ID. If present, the announcement has been posted.
UNIQUE (id)
)
Loading