View Source Skema (Skema v0.1.0)

Params provide some helpers method to work with parameters

Summary

Functions

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

Cast and validate params with given schema.

Transform params with given schema.

Validate params with given schema.

Functions

@spec cast(data :: map(), schema :: map()) :: %Skema.Result{
  errors: term(),
  params: term(),
  schema: term(),
  valid?: term(),
  valid_data: term()
}
Link to this function

cast_and_validate(data, schema)

View Source
@spec cast_and_validate(data :: map(), schema :: map()) ::
  {:ok, map()} | {:error, errors :: map()}

Cast and validate params with given schema. See Skema.SchemaHelper 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} <- Skema.cast(params, index_schema) do
    # do query data
  else
    {:error, errors} -> IO.puts(errors)
  end
end
Link to this function

cast_and_validate!(data, schema)

View Source
Link to this function

cast_apply(data, schema)

View Source
@spec cast_apply(data :: map(), schema :: map()) :: %Skema.Result{
  errors: term(),
  params: term(),
  schema: term(),
  valid?: term(),
  valid_data: term()
}

Cast and validate params with given schema.

Link to this function

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

View Source
Link to this function

transform_apply(data, schema)

View Source

Transform params with given schema.

Link to this function

validate_apply(data, schema)

View Source

Validate params with given schema.