Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlident

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package sqlident quotes SQL identifiers (table, column and index names) for the SQL tanGO generates, so a model or field named after a reserved word ("user", "order", "group") works on every dialect.

It is the one quoting helper shared by db.Store and the migration DDL. It takes a Style rather than a db.Dialect because db itself imports it; each package maps its dialect to a Style in one place.

The two styles differ on purpose. PostgreSQL only accepts the standard double quote. SQLite accepts double quotes too, but falls back to reading a double-quoted name that matches no column as a string literal, so a missing column would silently select its own name instead of failing; SQLite's backtick quoting has no such fallback.

Quoting never changes an identifier's identity for the names tanGO generates: they are lower-case (see db.ColumnName), which is what PostgreSQL folds an unquoted name to, and SQLite matches names case-insensitively whether quoted or not.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Quote

func Quote(style Style, name string) string

Quote returns name as a quoted identifier in style.

func QuoteAll

func QuoteAll(style Style, names []string) string

QuoteAll quotes each name in style and joins them with ", ".

Types

type Style

type Style int

Style selects a dialect's identifier quote character.

const (
	// Backtick quotes as `name`, escaping ` as “. Used for SQLite.
	Backtick Style = iota
	// DoubleQuote quotes as "name", escaping " as "". Used for PostgreSQL.
	DoubleQuote
)

Jump to

Keyboard shortcuts

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