1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Activity.Queries do
7 Contains queries for Activity.
10 import Ecto.Query, only: [from: 2]
12 @type query :: Ecto.Queryable.t() | Activity.t()
14 alias Pleroma.Activity
16 @spec by_actor(query, String.t()) :: query
17 def by_actor(query \\ Activity, actor) do
20 where: fragment("(?)->>'actor' = ?", activity.data, ^actor)
24 @spec by_object_id(query, String.t()) :: query
25 def by_object_id(query \\ Activity, object_id) do
26 from(activity in query,
29 "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
37 @spec by_type(query, String.t()) :: query
38 def by_type(query \\ Activity, activity_type) do
41 where: fragment("(?)->>'type' = ?", activity.data, ^activity_type)
45 @spec limit(query, pos_integer()) :: query
46 def limit(query \\ Activity, limit) do
47 from(activity in query, limit: ^limit)