View Source EctoTemp.Factory (ecto_temp v1.2.0)

Summary

Functions

Inserts values into a temporary table.

Generates a UUID that may be inserted directly into a :uuid field. Use this in preference of Ecto.UUID.generate/0 or Ecto.UUID.bingenerate/0, as those will not dump their string values to the binary format expected by postgres.

Functions

Link to this macro

insert(struct_or_table, table_or_params \\ nil, params \\ [])

View Source (macro)

Inserts values into a temporary table.

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:

  • 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 the id 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

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])
@spec uuid() :: binary()

Generates a UUID that may be inserted directly into a :uuid field. Use this in preference of Ecto.UUID.generate/0 or Ecto.UUID.bingenerate/0, as those will not dump their string values to the binary format expected by postgres.