View Source Bind.Parse (bind v0.1.0)

Summary

Functions

Parses a constraint and returns a dynamic query fragment.

Parses the sort parameter to determine the sort direction and field.

Parses a where parameter to extract the field name and constraint.

Functions

Link to this function

constraint(field, constraint, value)

View Source

Parses a constraint and returns a dynamic query fragment.

Parameters

  • field: The field to apply the constraint to.
  • constraint: The type of constraint (e.g., "eq", "gte").
  • value: The value to compare the field against.

Examples

> Bind.Parse.constraint(:name, "eq", "Alice")
dynamic([r], r.name == ^"Alice")

> Bind.Parse.constraint(:age, "gte", 30)
dynamic([r], r.age > ^30)

Parses the sort parameter to determine the sort direction and field.

Parameters

  • param: The sort parameter as a string.

Examples

> Bind.Parse.sort_field("-age")
[desc: :age]

> Bind.Parse.sort_field("name")
[asc: :name]

Parses a where parameter to extract the field name and constraint.

Parameters

  • param: The where parameter as a string.

Examples

> Bind.Parse.where_field("name[eq]")
[:name, "eq"]

> Bind.Parse.where_field("age[gte]")
[:age, "gte"]