1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.OAuth.Token.Query do
7 Contains queries for OAuth Token.
10 import Ecto.Query, only: [from: 2]
12 alias Pleroma.Web.OAuth.Token
14 @type query :: Ecto.Queryable.t() | Token.t()
16 @spec get_by_refresh_token(query, String.t()) :: query
17 def get_by_refresh_token(query \\ Token, refresh_token) do
18 from(q in query, where: q.refresh_token == ^refresh_token)
21 @spec get_by_token(query, String.t()) :: query
22 def get_by_token(query \\ Token, token) do
23 from(q in query, where: q.token == ^token)
26 @spec get_by_app(query, String.t()) :: query
27 def get_by_app(query \\ Token, app_id) do
28 from(q in query, where: q.app_id == ^app_id)
31 @spec get_by_id(query, String.t()) :: query
32 def get_by_id(query \\ Token, id) do
33 from(q in query, where: q.id == ^id)
36 @spec get_by_user(query, String.t()) :: query
37 def get_by_user(query \\ Token, user_id) do
38 from(q in query, where: q.user_id == ^user_id)
41 @spec preload(query, any) :: query
42 def preload(query \\ Token, assoc_preload \\ [])
44 def preload(query, assoc_preload) when is_list(assoc_preload) do
45 from(q in query, preload: ^assoc_preload)
48 def preload(query, _assoc_preload), do: query