Tarams (Tarams v1.9.0)

Copy Markdown View Source

Params provide some helpers method to work with parameters

Summary

Functions

cast(data, schema)

@spec cast(data :: map(), schema :: map()) :: {:ok, map()} | {:error, errors :: map()}

Cast and validate params with given schema. See Tarams.Schema for instruction on how to define a schema And then use it like this

def index(conn, params) do
  index_schema = %{
    status: [type: :string, required: true],
    type: [type: :string, in: ["type1", "type2", "type3"]],
    keyword: [type: :string, length: [min: 3, max: 100]],
  }

  with {:ok, data} <- Tarams.cast(params, index_schema) do
    # do query data
  else
    {:error, errors} -> IO.puts(errors)
  end
end

cast!(data, schema)

cast_array(type, value, acc \\ [])

clean_nil(data)

See Tarams.Utils.clean_nil/1.

plug_scrub(conn, keys \\ [])

See Tarams.Utils.plug_scrub/2.

scrub_param(data)

See Tarams.Utils.scrub_param/1.