ash_postgres/lib/ash_postgres.ex

107 lines
3.6 KiB
Elixir
Raw Normal View History

2019-12-05 03:58:20 +13:00
defmodule AshPostgres do
2019-12-06 07:45:42 +13:00
@moduledoc """
A postgres extension library for `Ash`.
2019-12-06 07:45:42 +13:00
`AshPostgres.DataLayer` provides a DataLayer, and a DSL extension to configure that data layer.
2019-12-06 07:45:42 +13:00
2020-12-27 19:20:12 +13:00
The dsl extension exposes the `postgres` section. See: `AshPostgres.DataLayer` for more.
2019-12-06 07:45:42 +13:00
"""
2020-05-03 07:06:52 +12:00
alias Ash.Dsl.Extension
2019-12-06 07:45:42 +13:00
2020-09-20 10:08:09 +12:00
@doc "The configured repo for a resource"
2019-11-27 11:33:52 +13:00
def repo(resource) do
2020-06-28 07:11:28 +12:00
Extension.get_opt(resource, [:postgres], :repo, nil, true)
2020-01-18 06:24:07 +13:00
end
2020-05-03 07:06:52 +12:00
2020-09-20 10:08:09 +12:00
@doc "The configured table for a resource"
def table(resource) do
2020-06-28 07:11:28 +12:00
Extension.get_opt(resource, [:postgres], :table, nil, true)
2020-05-03 07:06:52 +12:00
end
@doc "The configured references for a resource"
def references(resource) do
Extension.get_entities(resource, [:postgres, :references])
end
@doc "A keyword list of customized migration types"
def migration_types(resource) do
Extension.get_opt(resource, [:postgres], :migration_types, nil, true)
end
@doc "The configured check_constraints for a resource"
def check_constraints(resource) do
Extension.get_entities(resource, [:postgres, :check_constraints])
end
2021-09-21 08:38:36 +12:00
@doc "The configured custom_indexes for a resource"
def custom_indexes(resource) do
Extension.get_entities(resource, [:postgres, :custom_indexes])
end
@doc "The configured polymorphic_reference_on_delete for a resource"
def polymorphic_on_delete(resource) do
Extension.get_opt(resource, [:postgres, :references], :polymorphic_on_delete, nil, true)
end
@doc "The configured polymorphic_reference_on_update for a resource"
def polymorphic_on_update(resource) do
Extension.get_opt(resource, [:postgres, :references], :polymorphic_on_update, nil, true)
end
@doc "The configured polymorphic_reference_name for a resource"
def polymorphic_name(resource) do
Extension.get_opt(resource, [:postgres, :references], :polymorphic_on_delete, nil, true)
end
@doc "The configured polymorphic? for a resource"
def polymorphic?(resource) do
Extension.get_opt(resource, [:postgres], :polymorphic?, nil, true)
end
@doc "The configured unique_index_names"
def unique_index_names(resource) do
Extension.get_opt(resource, [:postgres], :unique_index_names, [], true)
end
@doc "The configured identity_index_names"
def identity_index_names(resource) do
Extension.get_opt(resource, [:postgres], :identity_index_names, [], true)
end
@doc "The configured foreign_key_names"
def foreign_key_names(resource) do
Extension.get_opt(resource, [:postgres], :foreign_key_names, [], true)
end
@doc "Whether or not the resource should be included when generating migrations"
def migrate?(resource) do
Extension.get_opt(resource, [:postgres], :migrate?, nil, true)
end
2020-09-20 10:08:09 +12:00
@doc "A stringified version of the base_filter, to be used in a where clause when generating unique indexes"
def base_filter_sql(resource) do
Extension.get_opt(resource, [:postgres], :base_filter_sql, nil)
end
@doc "Skip generating unique indexes when generating migrations"
def skip_unique_indexes?(resource) do
Extension.get_opt(resource, [:postgres], :skip_unique_indexes?, [])
end
2020-10-29 15:26:45 +13:00
@doc "The template for a managed tenant"
def manage_tenant_template(resource) do
Extension.get_opt(resource, [:postgres, :manage_tenant], :template, nil)
end
@doc "Whether or not to create a tenant for a given resource"
def manage_tenant_create?(resource) do
Extension.get_opt(resource, [:postgres, :manage_tenant], :create?, false)
end
@doc "Whether or not to update a tenant for a given resource"
def manage_tenant_update?(resource) do
Extension.get_opt(resource, [:postgres, :manage_tenant], :update?, false)
end
2019-10-31 04:13:22 +13:00
end