dbutils
import dbutils "ganigeorgiev.com/pocketbase/pocketbase/tools/dbutils"
Source: tools/dbutils.
Functions
AliasOrIdentifier
func AliasOrIdentifier(columnOrTableIdentifier string) string
AliasOrIdentifier returns the alias from a column or table identifier. Returns the identifier unmodified if no alias was found.
HasSingleColumnUniqueIndex
func HasSingleColumnUniqueIndex(column string, indexes []string) bool
Deprecated: Use `_, ok := FindSingleColumnUniqueIndex(indexes, column)` instead.
HasColumnUniqueIndex loosely checks whether the specified column has a single column unique index (WHERE statements are ignored).
JSONArrayLength
func JSONArrayLength(column string) string
JSONArrayLength returns JSON_ARRAY_LENGTH SQLite string expression with some normalizations for non-json columns.
It works with both json and non-json column values.
Returns 0 for empty string or NULL column values.
JSONEach
func JSONEach(column string) string
JSONEach returns JSON_EACH SQLite string expression with some normalizations for non-json columns.
JSONExtract
func JSONExtract(column string, path string) string
JSONExtract returns a JSON_EXTRACT SQLite string expression with some normalizations for non-json columns.
Types
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.
FindSingleColumnUniqueIndex
func FindSingleColumnUniqueIndex(indexes []string, column string) (Index, bool)
FindSingleColumnUniqueIndex returns the first matching single column unique index.
ParseIndex
func ParseIndex(createIndexExpr string) Index
ParseIndex parses the provided "CREATE INDEX" SQL string into Index struct.
Index.Build
func (idx Index) Build() string
Build returns a "CREATE INDEX" SQL string from the current index parts.
Returns empty string if idx.IsValid() is false.
Index.IsValid
func (idx Index) IsValid() bool
IsValid checks if the current Index contains the minimum required fields to be considered valid.
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.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.