I am using a CSV dataset in SQLite to seed. It seems that I can insert data but I can’t read it ! Something obvious must be missing but I just don’t see.
The table looks like this:
def create_table(conn, table) do
Exqlite.Sqlite3.execute(
conn,
"CREATE TABLE IF NOT EXISTS #{table} (
id integer primary key,
ident string,
elevation_ft string,
type string,
name string,...
I also have a schema and a Repo.
defmodule Airport do
use Ecto.Schema
import Ecto.Changeset
@headers headers
@columns Enum.map(@headers, &String.to_atom/1)
schema "csv" do
Enum.each(@columns, &field(&1, :string))
#timestamps()
end
def changeset(attrs \\ %{}) do
%Airport{}
|> cast(attrs, @columns)
|> validate_required(@columns -- [:iata_code])
end
end
I check that the fields are :ok
Airport.__schema__(:fields)
[:id, :ident, :type, :name, :elevation_ft...]
Now it seems that I can insert (?) a row:
l = %{
coordinates: "-74.93360137939453, 40.07080078125",
elevation_ft: "11",
gps_code: "00A",
...
}
|> Airport.changeset()
|> Repo.insert()
which returns:
[debug] QUERY OK db=0.9ms idle=1248.3ms
INSERT INTO "csv" (coordinates","elevation_ft","gps_code....
{:ok,
%Airport{
__meta__: #Ecto.Schema.Metadata<:loaded, "csv">,
id: 57424,
ident: "00A",....
but I can’t read it !??
Repo.get(Airport, 1)
** (ArgumentError) cannot load `11` as type :string for field :elevation_ft in %Airport{__meta__:
It seems that I can insert my whole file, but I can’t read it either:
Repo.aggregate(Airport, :count)
57342
Seems good, but:
Repo.all(Airport)
** (ArgumentError) cannot load `11` as type :string for field :elevation_ft in
%Airport{__meta__: #Ecto.Schema.Metadata<:loaded, "csv">, id: nil, ident: nil, type: nil, name: nil, elevation_ft: nil,
...