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

-- SessionRepository.search
select
  *
from
  "sessions"
where
  "sessions"."updatedAt" <= $1

-- SessionRepository.getByToken
select
  "sessions"."id",
  "sessions"."updatedAt",
  (
    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

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

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