Categorygithub.com/rickb777/where
2.1.6
Repository: https://github.com/rickb777/where.git
Documentation: pkg.go.dev

# README

where

GoDoc Build Status Code Coverage Go Report Card Issues

  • Provides a fluent API for dynamically constructing SQL WHERE & HAVING clauses.
  • Also supports dynamic LIMIT, OFFSET and ORDER BY clauses.
  • Allows the identifiers to be quoted to suit different SQL dialects, or not at all.
  • dialect package supports different placeholder styles.
  • quote package supports quoting SQL identifiers in back-ticks, double quotes, square barckets, or nothing.

Install

Install with this command:

go get github.com/rickb777/where/v2

where

Package where provides composable expressions for WHERE and HAVING clauses in SQL. These can range from the very simplest no-op to complex nested trees of AND and OR conditions.

In the naive approach, strings can be concatenated to construct lists of expression that are AND-ed together. However, mixing AND with OR makes things much more difficult. So this package does the work for you.

Also in this package are query constraints to provide ORDER BY, LIMIT and OFFSET clauses, along with 'TOP' for MS-SQL. These are similar to WHERE clauses except literal values are used instead of parameter placeholders.

Further support for SQL dialects and formatting options is provided in the dialect sub-package.

Queries should be written using '?' query placeholders throughout, and then these can be translated to the form needed by the chosen dialect: one of dialect.Query, dialect.Dollar, dialect.AtP or dialect.Inline.

Also, support for quoted identifiers is provided in the quote sub-package.

  • quote.Quoter is the interface for a quoter.
  • implementations include quote.ANSI, quote.Backticks, quote.SquareBrackets, and quote.None.

# Packages

Package where provides composable expressions for WHERE and HAVING clauses in SQL.