quote

package
v2.0.1-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2023 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

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.

For prefixed identifiers containing a dot ('.'), the quote marks are applied separately to the prefix(es) and the identifier itself.

Quoting is only applied where a column name is clear (as in the 'where' package). There isn't a general syntax analyser that somehow fixes up arbitrary SQL.

Index

Constants

This section is empty.

Variables

View Source
var (
	// None leaves identifiers unchanged.
	None = none

	// ANSI wraps identifiers in double-quote marks. For PostgreSQL etc.
	ANSI = quoter{/* contains filtered or unexported fields */}

	// Backticks wraps identifies in back-ticks. For MySql etc.
	Backticks = quoter{/* contains filtered or unexported fields */}

	// SquareBrackets wraps identifies in '[' and ']'. For MS SQL/SQL-Server.
	SquareBrackets = quoter{/* contains filtered or unexported fields */}
)
View Source
var (
	// DefaultQuoter does not change identifiers and is used by default.
	// Change this to affect the default setting for every SQL construction function.
	DefaultQuoter = none
)

Functions

This section is empty.

Types

type Quoter

type Quoter interface {
	// Quote renders an identifier within quote marks. If the identifier consists of both a
	// prefix and a name, each part is quoted separately. Any i/o errors are silently dropped.
	Quote(identifier string) string

	// QuoteW renders an identifier within quote marks. If the identifier consists of one or more
	// prefixes and a name, each part is quoted separately. This may give better performance
	// than Quote.
	QuoteW(w io.StringWriter, identifier string)
}

Quoter wraps identifiers in quote marks. Compound identifiers, i.e. those with an alias prefix such as "excluded"."created_at", are handled according to SQL grammar.

func Pick

func Pick(name string) Quoter

Pick picks a quoter based on the names "ansi", "backtick" (aliases "backticks") or "none", ignoring case. Other options are also permitted: "sqlite", "sqlite3", "postgres", "mysql", "mssql", "ms-sql", "sql-server". The default is none.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL