Categorygithub.com/rickb777/where/v2
modulepackage
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 dialect handles various dialect-specific ways of generating SQL.
No description provided by the author
Package quote augments SQL strings by quoting identifiers according to four common variants: - back-ticks used by MySQL, - double-quotes used in ANSI SQL (PostgreSQL etc), - square brackets used by SQLServer, or - no quotes at all.

# Functions

And combines some expressions into a clause that requires they are all true.
Between returns a between condition on a column.
Eq returns an equality condition on a column.
Gt returns a greater than condition on a column.
GtEq returns a greater than or equal condition on a column.
Having constructs the SQL clause beginning "HAVING ...".
In returns an 'IN' condition on a column.
InlinePlaceholders replaces every '?' placeholder with the corresponding argument value.
InSlice returns an 'IN' condition on a column.
Like returns a pattern-matching condition on a column.
Limit sets the upper limit on the number of records to be returned.
Literal returns a literal condition on a column.
Lt returns a less than condition on a column.
LtEq returns a less than or equal than condition on a column.
NoOp creates an empty expression.
Not negates an expression.
NotEq returns a not equal condition on a column.
NotNull returns an 'IS NOT NULL' condition on a column.
Null returns an 'IS NULL' condition on a column.
Offset sets the offset into the result set; previous items will be discarded.
Or combines some expressions into a clause that requires that any is true.
OrderBy lists the column(s) by which the database will be asked to sort its results.
Predicate returns a literal predicate.
ReplacePlaceholders replaces all "?" placeholders with numbered placeholders, using the given dialect option.
Where constructs the SQL clause beginning "WHERE ...".

# Structs

Clause is a compound expression.
Condition is a simple condition such as an equality test.
No description provided by the author

# Interfaces

Expression is an element in a WHERE clause.