View Source EctoTemp.Factory (ecto_temp v0.1.3)
Link to this section Summary
Functions
Inserts values into a temporary table.
Link to this section Functions
Link to this macro
insert(struct_or_table, table_or_params \\ nil, params \\ [])
View Source (macro)Inserts values into a temporary table.
params
Params:
- struct (optional) - a struct defined the schema used by the data migration.
- table_name
- attrs (optional) - a keyword list of attributes to insert
notes
Notes:
- If not given a struct, and the temporary table has a primary key, then we return the
id
of the inserted row. - If given a struct, and the temporary table has a primary key, then we do a
Repo.get
using theid
of the inserted row, and return the result as a struct. - If the temporary table has no primary key, then we return the list of values returned by postgres. This list is probably ordered by the order in which the columns are defined on the temp table???
examples
Examples
import EctoTemp.Factory
insert(:thing_with_no_primary_key) == []
insert(:thing_with_no_primary_key, some_thing: "hi") == ["hi"]
insert(:thing_with_primary_key) == 1
insert(:thing_with_primary_key, some_thing: "hi") == 2
%MyDataMigration.Cycle{id: 1} = insert(MyDataMigration.Cycle, :cycles, started_at: ~N[2020-02-03 00:00:00])