Documentation
¶
Index ¶
- Constants
- func AliasOrIdentifier(columnOrTableIdentifier string) string
- func HasSingleColumnUniqueIndex(column string, indexes []string) booldeprecated
- func JSONArrayLength(column string) string
- func JSONEach(column string) string
- func JSONExtract(column string, path string) string
- func NormalizeIdentifierQuotes(expr string) string
- type Index
- type IndexColumn
Constants ¶
const DropPostgresFunctionsSQL = DropPostgresStrftimeFunctionsSQL + DropPostgresJSONFunctionsSQL
DropPostgresFunctionsSQL drops all popgres helper SQL functions.
const DropPostgresJSONFunctionsSQL = `` /* 337-byte string literal not displayed */
const DropPostgresStrftimeFunctionsSQL = `` /* 530-byte string literal not displayed */
const PostgresFunctionsSQL = PostgresJSONFunctionsSQL + PostgresStrftimeFunctionsSQL
PostgresFunctionsSQL creates all popgres helper SQL functions.
const PostgresJSONFunctionsSQL = `` /* 2392-byte string literal not displayed */
PostgresJSONFunctionsSQL creates the json helper functions used by the tools/dbutils json expressions (in the main and in the logs schema).
const PostgresStrftimeFunctionsSQL = `` /* 7425-byte string literal not displayed */
PostgresStrftimeFunctionsSQL creates the popgres_strftime SQL functions used by the strftime() filter function (an emulation of the SQLite strftime with its time values, modifiers and format substitutions).
The functions run with the UTC time zone (the same as SQLite) and return NULL for invalid time values, modifiers or format substitutions.
Variables ¶
This section is empty.
Functions ¶
func AliasOrIdentifier ¶
AliasOrIdentifier returns the alias from a column or table identifier. Returns the identifier unmodified if no alias was found.
func HasSingleColumnUniqueIndex
deprecated
func JSONArrayLength ¶
JSONArrayLength returns a SQL expression with the number of elements of a json array column.
It works with both json and non-json column values.
Returns 0 for empty string or NULL column values.
func JSONEach ¶
JSONEach returns a set returning SQL expression with a single "value" text column for each element of a json array column.
Non-array and non-json column values are treated as a single element array.
It is intended to be used as a FROM/JOIN item, eg.:
"LEFT JOIN " + JSONEach("tbl.col") + " je ON TRUE"
func JSONExtract ¶
JSONExtract returns a SQL expression that extracts the jsonb value at the specified path of a json column (or the whole normalized jsonb value when path is empty).
The path uses the PocketBase notation (eg. "a.b[0].c").
NULL is returned for missing paths and for the json null value (the same as the SQLite JSON_EXTRACT).
func NormalizeIdentifierQuotes ¶
NormalizeIdentifierQuotes replaces the backtick quoted identifiers in the provided SQL expression with double quoted ones.
Single quoted string literals (and the double quoted identifiers) are left untouched.
Types ¶
type Index ¶
type Index struct {
SchemaName string `json:"schemaName"`
IndexName string `json:"indexName"`
TableName string `json:"tableName"`
Where string `json:"where"`
Columns []IndexColumn `json:"columns"`
Unique bool `json:"unique"`
Optional bool `json:"optional"`
}
Index represents a single parsed SQL CREATE INDEX expression.
func FindSingleColumnUniqueIndex ¶
FindSingleColumnUniqueIndex returns the first matching single column unique index.
func ParseIndex ¶
ParseIndex parses the provided "CREATE INDEX" SQL string into Index struct.
func (Index) Build ¶
Build returns a "CREATE INDEX" SQL string from the current index parts.
It is the PocketBase (SQLite) format used for the stored collection index definitions; use Index.BuildPostgres for the SQL that is executed.
Returns empty string if idx.IsValid() is false.
func (Index) BuildPostgres ¶
BuildPostgres returns a PostgreSQL "CREATE INDEX" SQL string from the current index parts (the SQL that is executed, while Index.Build returns the stored definition format).
The identifiers are double quoted and the backtick quoted identifiers inside the column expressions and the WHERE clause (the PocketBase/SQLite index format) are converted to double quoted ones.
The SQLite collations are translated as follows:
- NOCASE is replaced with a lower(col) expression;
- BINARY is omitted since it is the Postgres default behavior;
- any other collation name is used as it is (eg. "C").
Returns empty string if idx.IsValid() is false.
type IndexColumn ¶
type IndexColumn struct {
Name string `json:"name"` // identifier or expression
Collate string `json:"collate"`
Sort string `json:"sort"`
}
IndexColumn represents a single parsed SQL index column.