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

-- PluginRepository.getForLoad
select
  "plugin"."id",
  "plugin"."name",
  "plugin"."version",
  "plugin"."wasmBytes",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "plugin_method"."name",
          "plugin_method"."hostFunctions"
        from
          "plugin_method"
        where
          "plugin_method"."pluginId" = "plugin"."id"
      ) as agg
  ) as "methods"
from
  "plugin"
where
  "enabled" = $1

-- PluginRepository.search
select
  "plugin"."id",
  "plugin"."name",
  "plugin"."title",
  "plugin"."description",
  "plugin"."author",
  "plugin"."version",
  "plugin"."createdAt",
  "plugin"."updatedAt",
  "plugin"."templates",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "plugin_method"."name",
          "plugin_method"."title",
          "plugin_method"."description",
          "plugin_method"."types",
          "plugin_method"."schema",
          "plugin_method"."hostFunctions",
          "plugin_method"."allowedHosts",
          "plugin_method"."uiHints",
          "plugin"."name" as "pluginName"
        from
          "plugin_method"
        where
          "plugin_method"."pluginId" = "plugin"."id"
      ) as agg
  ) as "methods"
from
  "plugin"
order by
  "plugin"."name"

-- PluginRepository.getByHash
select
  "plugin"."id",
  "plugin"."name",
  "plugin"."title",
  "plugin"."description",
  "plugin"."author",
  "plugin"."version",
  "plugin"."createdAt",
  "plugin"."updatedAt",
  "plugin"."templates",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "plugin_method"."name",
          "plugin_method"."title",
          "plugin_method"."description",
          "plugin_method"."types",
          "plugin_method"."schema",
          "plugin_method"."hostFunctions",
          "plugin_method"."allowedHosts",
          "plugin_method"."uiHints",
          "plugin"."name" as "pluginName"
        from
          "plugin_method"
        where
          "plugin_method"."pluginId" = "plugin"."id"
      ) as agg
  ) as "methods"
from
  "plugin"
where
  "plugin"."sha256hash" = $1

-- PluginRepository.getByName
select
  "plugin"."id",
  "plugin"."name",
  "plugin"."title",
  "plugin"."description",
  "plugin"."author",
  "plugin"."version",
  "plugin"."createdAt",
  "plugin"."updatedAt",
  "plugin"."templates",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "plugin_method"."name",
          "plugin_method"."title",
          "plugin_method"."description",
          "plugin_method"."types",
          "plugin_method"."schema",
          "plugin_method"."hostFunctions",
          "plugin_method"."allowedHosts",
          "plugin_method"."uiHints",
          "plugin"."name" as "pluginName"
        from
          "plugin_method"
        where
          "plugin_method"."pluginId" = "plugin"."id"
      ) as agg
  ) as "methods"
from
  "plugin"
where
  "plugin"."name" = $1

-- PluginRepository.get
select
  "plugin"."id",
  "plugin"."name",
  "plugin"."title",
  "plugin"."description",
  "plugin"."author",
  "plugin"."version",
  "plugin"."createdAt",
  "plugin"."updatedAt",
  "plugin"."templates",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "plugin_method"."name",
          "plugin_method"."title",
          "plugin_method"."description",
          "plugin_method"."types",
          "plugin_method"."schema",
          "plugin_method"."hostFunctions",
          "plugin_method"."allowedHosts",
          "plugin_method"."uiHints",
          "plugin"."name" as "pluginName"
        from
          "plugin_method"
        where
          "plugin_method"."pluginId" = "plugin"."id"
      ) as agg
  ) as "methods"
from
  "plugin"
where
  "plugin"."id" = $1

-- PluginRepository.getForValidation
select
  "plugin_method"."id",
  "plugin_method"."name",
  "plugin"."name" as "pluginName",
  "plugin_method"."types"
from
  "plugin_method"
  inner join "plugin" on "plugin_method"."pluginId" = "plugin"."id"

-- PluginRepository.searchMethods
select
  "plugin"."name" as "pluginName",
  "plugin_method"."pluginId",
  "plugin_method"."id",
  "plugin_method"."name",
  "plugin_method"."title",
  "plugin_method"."description",
  "plugin_method"."types",
  "plugin_method"."schema",
  "plugin_method"."hostFunctions",
  "plugin_method"."allowedHosts",
  "plugin_method"."uiHints"
from
  "plugin_method"
  inner join "plugin" on "plugin"."id" = "plugin_method"."pluginId"
order by
  "plugin_method"."name"
