-- NOTE: This file is auto generated by ./sql-generator

-- SessionRepository.get
select
  "id",
  "expiresAt",
  "pinExpiresAt"
from
  "sessions"
where
  "id" = $1

-- SessionRepository.getByToken
select
  "sessions"."id",
  "sessions"."updatedAt",
  "sessions"."pinExpiresAt",
  (
    select
      to_json(obj)
    from
      (
        select
          "users"."id",
          "users"."name",
          "users"."email",
          "users"."isAdmin",
          "users"."quotaUsageInBytes",
          "users"."quotaSizeInBytes"
        from
          "users"
        where
          "users"."id" = "sessions"."userId"
          and "users"."deletedAt" is null
      ) as obj
  ) as "user"
from
  "sessions"
where
  "sessions"."token" = $1
  and (
    "sessions"."expiresAt" is null
    or "sessions"."expiresAt" > $2
  )

-- SessionRepository.getByUserId
select
  "sessions".*
from
  "sessions"
  inner join "users" on "users"."id" = "sessions"."userId"
  and "users"."deletedAt" is null
where
  "sessions"."userId" = $1
  and (
    "sessions"."expiresAt" is null
    or "sessions"."expiresAt" > $2
  )
order by
  "sessions"."updatedAt" desc,
  "sessions"."createdAt" desc

-- SessionRepository.delete
delete from "sessions"
where
  "id" = $1::uuid

-- SessionRepository.lockAll
update "sessions"
set
  "pinExpiresAt" = $1
where
  "userId" = $2
