change gin web framework to ron
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
create table if not exists tv_show (
|
||||
id serial unique primary key,
|
||||
"name" varchar not null,
|
||||
tt_imdb varchar not null,
|
||||
popularity int not null default 0,
|
||||
|
||||
created_at timestamp not null default (now()),
|
||||
updated_at timestamp not null default (now())
|
||||
);
|
||||
|
||||
create index if not exists idx_tv_show_name on "tv_show" ("name");
|
||||
create index if not exists idx_tv_show_tt_imdb on "tv_show" ("tt_imdb");
|
||||
create index if not exists idx_tv_show_updated_at on "tv_show" ("updated_at");
|
||||
|
||||
create table if not exists episodes (
|
||||
id serial unique primary key,
|
||||
tv_show_id integer not null,
|
||||
|
||||
season integer not null,
|
||||
episode integer not null,
|
||||
released date,
|
||||
"name" varchar not null,
|
||||
plot text not null default '',
|
||||
avg_rating real not null default 0,
|
||||
vote_count int not null default 0,
|
||||
|
||||
foreign key (tv_show_id) references tv_show (id)
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
-- name: CreateTVShow :one
|
||||
insert into "tv_show" (name, tt_imdb)
|
||||
values ($1, $2)
|
||||
returning *;
|
||||
|
||||
-- name: CreateEpisodes :one
|
||||
insert into "episodes" (tv_show_id, season, episode, released, name, plot, avg_rating, vote_count)
|
||||
values ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
returning *;
|
||||
|
||||
-- name: CheckTVShowExists :one
|
||||
select * from "tv_show"
|
||||
where tt_imdb = $1;
|
||||
|
||||
-- name: GetEpisodes :many
|
||||
select * from "episodes"
|
||||
where tv_show_id = $1
|
||||
order by season, episode asc;
|
||||
|
||||
-- name: IncreasePopularity :exec
|
||||
update "tv_show" set popularity = popularity + 1
|
||||
where tt_imdb = $1;
|
||||
|
||||
-- name: TvShowAverageRating :one
|
||||
select avg(avg_rating) from "episodes"
|
||||
where tv_show_id = $1;
|
||||
|
||||
-- name: TvShowMedianRating :one
|
||||
select percentile_cont(0.5) within group (order by avg_rating) from "episodes"
|
||||
where tv_show_id = $1;
|
||||
|
||||
-- name: SeasonAverageRating :one
|
||||
select avg(avg_rating) from "episodes"
|
||||
where tv_show_id = $1 and season = $2;
|
||||
|
||||
-- name: SeasonMedianRating :one
|
||||
select percentile_cont(0.5) within group (order by avg_rating) from "episodes"
|
||||
where tv_show_id = $1 and season = $2;
|
||||
Reference in New Issue
Block a user