Skip to content

Support dynamic where clauses #2060

Open
@go-aegian

Description

@go-aegian

apart from the predefined where clause, it needs somehow to be able to support passing a string containing a filter clause that it's parameters are already resolved prior to the Query function, I proposed a possible solution to be able to declare in the sql definition something like this

-- name: ListOrders :many
  select * from order where status = $1 and (@filter::text);

Generated

const listOrders = "select * from order where status = $1 and (@filter::text);"

 type ListOrdersParams struct {
       Status string
       Filter string
}
func (q *Queries) ListOrders(ctx context.Context, arg ListOrdersParams) ([]*ListOrdersRow, error) {
        filter:=arg.Filter
        if filter=="" {
           filter = "1=1"
        }
        listOrdersWithFilter = strings.Replace(listOrders, "@filter::text", filter, -1)

	rows, err := q.db.Query(ctx, listOrdersWithFilter, arg.Status)

...

What database engines need to be changed?

PostgreSQL, MySQL

What programming language backends need to be changed?

Go, Python, Kotlin

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions