Move pk to int autogen and uuid as handle

This commit is contained in:
Zoe Roux
2024-10-19 18:06:31 +02:00
parent 200087f2f6
commit a2df0ae305
4 changed files with 23 additions and 16 deletions
+11 -9
View File
@@ -5,7 +5,7 @@ select
sqlc.embed(u)
from
users as u
inner join sessions as s on u.id = s.user_id
inner join sessions as s on u.pk = s.user_pk
where
s.token = $1
limit 1;
@@ -20,24 +20,26 @@ where
-- name: GetUserSessions :many
select
*
s.*
from
sessions
sessions as s
inner join users as u on u.pk = s.user_pk
where
user_id = $1
u.pk = $1
order by
last_used;
-- name: CreateSession :one
insert into sessions(token, user_id, device)
insert into sessions(token, user_pk, device)
values ($1, $2, $3)
returning
*;
-- name: DeleteSession :one
delete from sessions
where id = $1
and user_id = $2
delete from sessions as s using users as u
where s.user_pk = u.pk
and s.id = $1
and u.id = sqlc.arg(user_id)
returning
*;
s.*;
+5 -2
View File
@@ -21,10 +21,13 @@ limit $1;
-- name: GetUser :many
select
sqlc.embed(u),
sqlc.embed(h)
h.provider,
h.id,
h.username,
h.profile_url
from
users as u
left join oidc_handle as h on u.id = h.user_id
left join oidc_handle as h on u.pk = h.user_pk
where
u.id = $1;