View Source EctoTemp.Macros (ecto_temp v1.2.0)

Summary

Functions

Add a column to a table definition.

Runs through previously defined @ecto_temporary_tables to insert temporary tables. This should be called in a setup block, which needs to be defined after all deftemptable definitions.

Creates a temporary table that will be rolled back at the end of the current test transaction. If the table name is given as :things, then the actual temporary table will be created as things. As this may overlap with existing tables, it is recommended to use a temp prefix of suffix when defining temp tables.

Adds inserted_at and updated_at to a table definition.

Functions

Link to this macro

column(name, type, opts \\ [])

View Source (macro)
@spec column(name :: atom(), type :: atom(), opts :: keyword()) :: Macro.t()

Add a column to a table definition.

This must be called within a deftemptable block, or a CompileError will be raised.

Opts

nametypedefaultdescription
defaultterm()Provides a default value when none is provided.
nullbooleantrueDetermines whether null values are allowed in a column.
Link to this macro

create_temp_tables()

View Source (macro)
@spec create_temp_tables() :: Macro.t()

Runs through previously defined @ecto_temporary_tables to insert temporary tables. This should be called in a setup block, which needs to be defined after all deftemptable definitions.

Link to this macro

deftemptable(table_name, opts \\ [], list)

View Source (macro)

Creates a temporary table that will be rolled back at the end of the current test transaction. If the table name is given as :things, then the actual temporary table will be created as things. As this may overlap with existing tables, it is recommended to use a temp prefix of suffix when defining temp tables.

Examples

deftemptable :person_temp do
  column :thing_id, :integer, null: false
  deftimestamps()
end

deftemptable :thing_temp, primary_key: false do
  column :description, :string, null: false
  column :comment, :string
end

Opts

nametypedefaultdescription
primary_keybooleantrueWhen true, adds an :id field of type :bigserial
Link to this macro

deftimestamps()

View Source (macro)
@spec deftimestamps() :: Macro.t()

Adds inserted_at and updated_at to a table definition.

This must be called within a deftemptable block, or a CompileError will be raised.