This repository has been archived by the owner on Dec 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sql): created and set up sqlc actions for basic jokes data
- Loading branch information
Showing
11 changed files
with
188 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,4 @@ api | |
|
||
# Sqlit | ||
*.sqlite | ||
sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
-- create admins | ||
create table admins | ||
( | ||
id integer primary key autoincrement, | ||
name text unique not null | ||
); | ||
|
||
-- create default categories | ||
create table joke_categories | ||
( | ||
id integer primary key autoincrement, | ||
name text unique not null | ||
); | ||
|
||
insert into joke_categories(name) | ||
values ('Any'); | ||
insert into joke_categories(name) | ||
values ('Programming'); | ||
insert into joke_categories(name) | ||
values ('Misc'); | ||
insert into joke_categories(name) | ||
values ('Dark'); | ||
insert into joke_categories(name) | ||
values ('YoMama'); | ||
|
||
-- create default types | ||
|
||
create table joke_types | ||
( | ||
id integer primary key autoincrement, | ||
name text unique not null | ||
); | ||
|
||
create trigger joke_types_lower_case_name | ||
after insert | ||
on joke_types | ||
begin | ||
update joke_types set name = lower(new.name) where id = new.id; | ||
end; | ||
|
||
insert into joke_types(name) | ||
values ('single'); | ||
insert into joke_types(name) | ||
values ('twopart'); | ||
|
||
-- create jokes | ||
|
||
create table jokes | ||
( | ||
id integer primary key autoincrement, | ||
question text, | ||
answer text not null, | ||
type_id integer not null references joke_types default 1, | ||
category_id integer not null references joke_categories default 1, | ||
userID text, | ||
guildID text | ||
); | ||
|
||
create index jokes_index on jokes (id, guildID); | ||
|
||
create table jokes_audit | ||
( | ||
id integer primary key autoincrement, | ||
status text default 'CREATED', | ||
joke_id integer not null, | ||
question text, | ||
answer text not null, | ||
type_id integer not null references joke_types, | ||
category_id integer not null references joke_categories, | ||
userID text, | ||
guildID text | ||
); | ||
|
||
create trigger joke_add_event_trigger | ||
after insert | ||
on jokes | ||
begin | ||
insert | ||
into jokes_audit(joke_id, question, answer, type_id, category_id, userID, guildID) | ||
values (new.id, new.question, new.answer, new.type_id, new.category_id, new.userID, new.guildID); | ||
end; | ||
|
||
create trigger joke_update_event_trigger | ||
after update | ||
on jokes | ||
begin | ||
insert | ||
into jokes_audit(status, joke_id, question, answer, type_id, category_id, userID, guildID) | ||
values ('UPDATED', new.id, new.question, new.answer, new.type_id, | ||
new.category_id, | ||
new.userID, new.guildID); | ||
end; | ||
|
||
create trigger joke_delete_event_trigger | ||
before delete | ||
on jokes | ||
begin | ||
insert | ||
into jokes_audit(status, joke_id, question, answer, type_id, category_id, userID, guildID) | ||
values ('DELETE', old.id, old.question, old.answer, old.type_id, | ||
old.category_id, | ||
old.userID, old.guildID); | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-- name: GetJokeById :one | ||
select * | ||
from jokes | ||
where id == ? | ||
limit 1; | ||
|
||
-- name: GetTypes :many | ||
select * | ||
from joke_types; | ||
|
||
-- name: GetCategories :many | ||
select * | ||
from joke_categories c; | ||
|
||
-- name: AddJoke :exec | ||
insert | ||
into jokes(question, answer, type_id, category_id, userID, guildID) | ||
values (?, ?, ?, ?, ?, ?); | ||
|
||
-- name: RemoveJoke :exec | ||
delete | ||
from jokes | ||
where id = ?; | ||
|
||
-- name: UpdateJoke :exec | ||
update jokes | ||
set question = ?, | ||
answer = ?, | ||
type_id = ?, | ||
category_id = ?, | ||
userID = ?, | ||
guildID = ? | ||
where id = ?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.