dbutils

package
v0.0.0-...-10fa78b Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasSingleColumnUniqueIndex deprecated

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).

func 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.

func JSONEach

func JSONEach(column string) string

JSONEach returns JSON_EACH SQLite string expression with some normalizations for non-json columns.

func JSONEachByPlaceholder

func JSONEachByPlaceholder(placeholder string) string

JSONEachByPlaceholder expands a given user input json array to multiple rows. Use JSONEach if you want to expand a column value instead. The [placeholder] is the parameter placeholder in SQL prepared statements. We assume the parameter value is a marshalled JSON array.

func JSONExtract

func JSONExtract(column string, path string) string

JSONExtract returns a JSON_EXTRACT SQLite string expression with some normalizations for non-json columns.

func JsonArrayExistsStr

func JsonArrayExistsStr(column string, strValue string) dbx.Expression

JsonArrayExistsStr is used to determine whether a JSON string array contains a string element. Right now it only used to determine whether a JSON string ID array contains a specific ID. Operation "?" definition: Does the string exist as a top-level key within the JSON value? The type of the key is only supported to be string. If we want to support other types, we may need to use `@>` operator instead.

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

func FindSingleColumnUniqueIndex(indexes []string, column string) (Index, bool)

FindSingleColumnUniqueIndex returns the first matching single column unique index.

func ParseIndex

func ParseIndex(createIndexExpr string) Index

ParseIndex parses the provided "CREATE INDEX" SQL string into Index struct.

func (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.

func (Index) IsValid

func (idx Index) IsValid() bool

IsValid checks if the current Index contains the minimum required fields to be considered valid.

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.

Jump to

Keyboard shortcuts

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