tellesleandro
tellesleandro
AEAsh Elixir
Created by tellesleandro on 9/29/2023 in #support
How to use Ash.Transform?
Sorry, I know this forum is archived but I think here I can get help faster than on Elixir Forum. I'm posting here the same question I've just posted there. I need to shift the time_zone of some (DateTime) attributes from a resource. Ideally, I'd like to do it right after records are loaded from db. Is it possible? How?
4 replies
AEAsh Elixir
Created by tellesleandro on 9/27/2023 in #support
Ash.Query getting started docs
I need some help to figure out how to translate Ecto queries into Ash ones. I've already read the docs, but I'm still stucked on simple "SELECT COUNT(*) FROM table" and "SELECT MIN(field) FROM table". Where do I find such explanation? Thanks in advance.
34 replies
AEAsh Elixir
Created by tellesleandro on 9/26/2023 in #support
belongs_to does not add _id attributes do resource
The resource with attributes and relationships
attributes do
uuid_primary_key :id
create_timestamp :inserted_at
update_timestamp :updated_at
attribute :max_estadias_simultaneas, :integer do
allow_nil? false
default 1
end
attribute :valido_ate, :utc_datetime_usec
attribute :chaves, {:array, :string} do
allow_nil? false
default []
end
end

relationships do
belongs_to :plano, Garagem.Operacional.Plano
belongs_to :pessoa, Garagem.Operacional.Pessoa
end
attributes do
uuid_primary_key :id
create_timestamp :inserted_at
update_timestamp :updated_at
attribute :max_estadias_simultaneas, :integer do
allow_nil? false
default 1
end
attribute :valido_ate, :utc_datetime_usec
attribute :chaves, {:array, :string} do
allow_nil? false
default []
end
end

relationships do
belongs_to :plano, Garagem.Operacional.Plano
belongs_to :pessoa, Garagem.Operacional.Pessoa
end
does not have the attributes plano_id and pessoa_id. If I try to insert a record, the insert command does not have the foreign keys:
INSERT INTO "planos_contratos" ("chaves","id","inserted_at","max_estadias_simultaneas","updated_at","valido_ate") VALUES ($1,$2,$3,$4,$5,$6) [[], "a0424503-341b-476d-8522-926f600457c7", ~U[2023-09-26 04:33:13.460031Z], 1, ~U[2023-09-26 04:33:13.460031Z], ~U[2023-09-26 04:33:13.084948Z]]
INSERT INTO "planos_contratos" ("chaves","id","inserted_at","max_estadias_simultaneas","updated_at","valido_ate") VALUES ($1,$2,$3,$4,$5,$6) [[], "a0424503-341b-476d-8522-926f600457c7", ~U[2023-09-26 04:33:13.460031Z], 1, ~U[2023-09-26 04:33:13.460031Z], ~U[2023-09-26 04:33:13.084948Z]]
21 replies
AEAsh Elixir
Created by tellesleandro on 9/25/2023 in #support
Complex types (postgres)
Is it possible to create (and use) complex types like this
CREATE DOMAIN dow AS integer
CHECK(
value BETWEEN 1 and 7
);

CREATE TYPE week_range as (
start_dow dow,
start_time time,
end_dow dow,
end_time time,
limit_in_seconds integer
);
CREATE DOMAIN dow AS integer
CHECK(
value BETWEEN 1 and 7
);

CREATE TYPE week_range as (
start_dow dow,
start_time time,
end_dow dow,
end_time time,
limit_in_seconds integer
);
?
22 replies
AEAsh Elixir
Created by tellesleandro on 9/25/2023 in #support
Postgres' range types
What's the best approach for adding tstzrange type column to a resource?
8 replies
AEAsh Elixir
Created by tellesleandro on 9/22/2023 in #support
Exception in transformer AshAuthentication.Strategy.Custom.Transformer
Hi there. I got an exception in transformer AshAuthentication.Strategy.Custom.Transformer when following the Authentication guide . Instead of User I set the resource name to Usuario.
== Compilation error in file lib/garagem/seguranca/resources/usuario.ex ==
** (RuntimeError) Exception in transformer AshAuthentication.Strategy.Custom.Transformer on Garagem.Seguranca.Usuario:

expected a map, got: nil
(elixir 1.15.4) lib/map.ex:486: Map.take/2
(ash_authentication 3.11.14) lib/ash_authentication/strategies/password/transformer.ex:78: anonymous fn/2 in AshAuthentication.Strategy.Password.Transformer.transform/2
...
== Compilation error in file lib/garagem/seguranca/resources/usuario.ex ==
** (RuntimeError) Exception in transformer AshAuthentication.Strategy.Custom.Transformer on Garagem.Seguranca.Usuario:

expected a map, got: nil
(elixir 1.15.4) lib/map.ex:486: Map.take/2
(ash_authentication 3.11.14) lib/ash_authentication/strategies/password/transformer.ex:78: anonymous fn/2 in AshAuthentication.Strategy.Password.Transformer.transform/2
...
mix.exs
...
{:ash, "~> 2.14"},
{:ash_postgres, "~> 1.3"},
{:ash_phoenix, "~> 1.2"},
{:ash_authentication, "~> 3.11"},
{:ash_authentication_phoenix, "~> 1.8"}
...
...
{:ash, "~> 2.14"},
{:ash_postgres, "~> 1.3"},
{:ash_phoenix, "~> 1.2"},
{:ash_authentication, "~> 3.11"},
{:ash_authentication_phoenix, "~> 1.8"}
...
Resource file
defmodule Garagem.Seguranca.Usuario do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication]

attributes do
uuid_primary_key :id
attribute :email, :ci_string, allow_nil?: false
attribute :hashed_password, :string, allow_nil?: false, sensitive?: true
end

authentication do
api Garagem.Seguranca

strategies do
password :password do
identity_field :email
sign_in_tokens_enabled? true
end
end

tokens do
enabled? true
token_resource Garagem.Seguranca.Token

signing_secret Garagem.Seguranca.Secrets
end
end

postgres do
table "usuarios"
repo Garagem.Repo
end

identities do
identity :unique_email, [:email]
end
end
defmodule Garagem.Seguranca.Usuario do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication]

attributes do
uuid_primary_key :id
attribute :email, :ci_string, allow_nil?: false
attribute :hashed_password, :string, allow_nil?: false, sensitive?: true
end

authentication do
api Garagem.Seguranca

strategies do
password :password do
identity_field :email
sign_in_tokens_enabled? true
end
end

tokens do
enabled? true
token_resource Garagem.Seguranca.Token

signing_secret Garagem.Seguranca.Secrets
end
end

postgres do
table "usuarios"
repo Garagem.Repo
end

identities do
identity :unique_email, [:email]
end
end
The resettable property of the struct strategy is nil at ash_authentication/strategies/password/transformer.ex:77. I tried to set the property to a function, as shown in the docs (https://hexdocs.pm/ash_authentication/AshAuthentication.Sender.html), but I still get the error. I hope someone can help me. Thanks
38 replies