Francis
Francis
AEAsh Elixir
Created by Francis on 8/2/2023 in #support
AshCsv - duplication on `upsert?: true`
I might be doing something wrong but when using AshCsv with upsert?: true on a create action, I get duplicates in the CSV file. For context, here's the ressource
elixir

defmodule WorkoutManager.Exercises.Equipment do
@moduledoc false

alias WorkoutManager.Exercises

use Ash.Resource,
data_layer: AshCsv.DataLayer

csv do
file "priv/exercises/equipment.csv"
create? true
header? true
columns [:name]
end

attributes do
attribute :name, :ci_string do
allow_nil? false
primary_key? true
constraints casing: :lower
end
end

actions do
defaults [:read, :destroy]

create :upsert do
accept [:name]
upsert? true
end
end

code_interface do
define_for Exercises

define :read_all, action: :read
define :upsert, args: [:name]
define :destroy
end
end
elixir

defmodule WorkoutManager.Exercises.Equipment do
@moduledoc false

alias WorkoutManager.Exercises

use Ash.Resource,
data_layer: AshCsv.DataLayer

csv do
file "priv/exercises/equipment.csv"
create? true
header? true
columns [:name]
end

attributes do
attribute :name, :ci_string do
allow_nil? false
primary_key? true
constraints casing: :lower
end
end

actions do
defaults [:read, :destroy]

create :upsert do
accept [:name]
upsert? true
end
end

code_interface do
define_for Exercises

define :read_all, action: :read
define :upsert, args: [:name]
define :destroy
end
end
This happens when I call WorkoutManager.Exercises.Equipment.upsert!("rings") multiple times. The behaviour I was expecting was that if rings was already in the file, it wouldn't duplicate it but it inserts a duplicate.
8 replies
AEAsh Elixir
Created by Francis on 5/13/2023 in #support
SQLite support
Not sure if this is the right place to post this but I still wanted to open the discussion. From what I understand, a ash_sqlite lib is in the plans although it's not known yet when it will be available. If you're looking for help on this one, I'd love to help out for the implementation. In the meantime, what is the suggested approach to use SQLite without too much hassle? Thanks 🙂
16 replies