mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
A postgresql datalayer for the Ash Framework
acc947292d
It should be possible to use this function, and it did work as of ash v2.5.9. This test fails as of ash v2.5.10, which introduced adding relationships to underlying ecto schemas. The bug is related to a has_many relationship being present on the resource. The test fails with: 1) test call Ecto.Repo.insert! via Ash Repo (AshPostgres.EctoCompatibilityTest) test/ecto_compatibility_test.exs:6 ** (Ecto.InvalidChangesetError) could not perform insert because changeset is invalid. Errors %{posts: [{"is invalid", [type: {:array, :map}]}]} Applied changes %{name: "The Org"} Params nil Changeset #Ecto.Changeset< action: :insert, changes: %{name: "The Org"}, errors: [posts: {"is invalid", [type: {:array, :map}]}], data: #AshPostgres.Test.Organization<>, valid?: false > code: |> AshPostgres.TestRepo.insert!() stacktrace: (ecto 3.9.4) lib/ecto/repo/schema.ex:270: Ecto.Repo.Schema.insert!/4 test/ecto_compatibility_test.exs:9: (test) |
||
---|---|---|
.github | ||
.vscode | ||
config | ||
documentation | ||
lib | ||
logos | ||
priv | ||
test | ||
test_snapshot_path | ||
.check.exs | ||
.credo.exs | ||
.formatter.exs | ||
.gitignore | ||
CHANGELOG.md | ||
LICENSE | ||
mix.exs | ||
mix.lock | ||
README.md |
AshPostgres
AshPostgres supports all the capabilities of an Ash data layer. AshPostgres is the primary Ash data layer.
Custom Predicates:
AshPostgres.Predicates.Trigram
DSL
See the DSL documentation in AshPostgres.DataLayer
for DSL documentation
Usage
Add ash_postgres
to your mix.exs
file.
{:ash_postgres, "~> 1.0"}
To use this data layer, you need to chage your Ecto Repo's from use Ecto.Repo
,
to use AshPostgres.Repo
. because AshPostgres adds functionality to Ecto Repos.
Then, configure each of your Ash.Resource
resources by adding use Ash.Resource, data_layer: AshPostgres.DataLayer
like so:
defmodule MyApp.SomeResource do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
repo MyApp.Repo
table "table_name"
end
attributes do
# ... Attribute definitions
end
end
Generating Migrations
See the documentation for Mix.Tasks.AshPostgres.GenerateMigrations
for how to generate
migrations from your resources
Contributors
Ash is made possible by its excellent community!