Documentation ¶
Overview ¶
Package dialect handles various dialect-specific ways of generating SQL.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // SqliteQuoter uses ANSI double-quotes for Sqlite. // This can be modified, e.g. to None, before first use. SqliteQuoter = quote.ANSI // PostgresQuoter uses ANSI double-quotes for Postgres. // This can be modified, e.g. to None, before first use. PostgresQuoter = quote.ANSI // MySqlQuoter uses backticks for MySQL. // This can be modified, e.g. to None, before first use. MySqlQuoter = quote.Backticks // MSSqlQuoter uses square brackets for MS-SQL. // This can be modified, e.g. to None, before first use. MSSqlQuoter = quote.SquareBrackets )
These are defaults used by each dialect; they can be altered before first use.
var DefaultDialect = Sqlite
DefaultDialect is Sqlite, chosen as being probably the simplest. This can be altered before first use.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect int
Dialect represents a dialect of SQL. All the defined dialects are non-zero.
const ( // Sqlite identifies SQLite Sqlite Dialect // Mysql identifies MySQL (also works for MariaDB) Mysql // Postgres identifies PostgreSQL Postgres // SqlServer identifies SqlServer (MS-SQL) SqlServer )
func Pick ¶
Pick finds a dialect that matches by name, ignoring letter case. It matches:
- "sqlite", "sqlite3"
- "mysql"
- "postgres", "postgresql", "pgx"
- "sqlserver", "sql-server", "mssql"
It returns 0 if not found.
func (Dialect) Placeholder ¶
func (d Dialect) Placeholder() FormatOption
Placeholder returns Query, Dollar or AtP.
type FormatOption ¶
type FormatOption int
FormatOption provides controls for where-expression formatting.
const ( // Query indicates placeholders using queries '?'. For Sqlite & MySql. // Because where-expressions are constructed using queries, this option // specifies that no change is needed. Query FormatOption = iota // Dollar indicates placeholders using numbered $1, $2, ... format. For PostgreSQL. Dollar // AtP indicates placeholders using numbered @p1, @p2, ... format. For SQL-Server. AtP // Inline indicates that each placeholder is removed and its value is inlined. Inline )
These options affect how placeholders are renderered.
const ( // NoQuotes indicates identifiers will not be enclosed in quote marks. NoQuotes FormatOption = iota + 10 // ANSIQuotes indicates identifiers will be enclosed in double quote marks. For Postgres. ANSIQuotes // Backticks indicates identifiers will be enclosed in back-tick marks. For MySql. Backticks // SquareBrackets indicates identifiers will be enclosed in square brackets. For SQL-Server. SquareBrackets )
These options affect how column name identifiers are quoted, if required. Quoting identifiers is mandatory if the identifiers happen to collide with reserved names. Otherwise, it is optional.