A Go library to build and manage dynamic queries. No external dependencies. Slightly inspired by Drizzle ORM
The scope of sqld
is to provide an easy way to organize your dynamic queries in re-usable components, not to validate said queries.
I suggest to use other tools like SQLParser and a lot of e2e tests!
query := sqld.New(
sqld.Select(
sqld.Columns(
"name",
"pizzas",
),
),
sqld.From(sqld.Just("Table")),
sqld.Where(
sqld.And(
sqld.IfNotNil(filters.Name,
sqld.Eq("name", filters.Name),
),
sqld.IfNotEmpty(filters.Pizzas,
sqld.In("pizzas", filters.Pizzas),
),
),
),
sqld.OrderBy(sqld.Desc(filters.OrderBy)),
)
s, args, err := query()
- Operators: callbacks that have this signature, used to build various parts of the query
- Statements: major "blocks" of the query, like a whole WHERE statement with all its conditions
- Conditionals: functions that return different operators depending on the inputs (usually boolean checks). Check this file
You can provide your own operators: every function (anonymous or not) that has this signature can be used by the library.
Check here for the built-in errors.