sql3util

package
v0.30.5 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 9 Imported by: 0

README

SQLite utility functions

This package implements assorted SQLite utilities useful to extension writers.

It also wraps a parser for the CREATE and ALTER TABLE commands, created by Marco Bambini.

Documentation

Overview

Package sql3util implements SQLite utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NamedArg

func NamedArg(arg string) (key, val string)

NamedArg splits an named arg into a key and value, around an equals sign. Spaces are trimmed around both key and value.

func ParseBool

func ParseBool(s string) (b, ok bool)

ParseBool parses a boolean.

https://sqlite.org/pragma.html#syntax

func ParseFloat added in v0.30.4

func ParseFloat(s string) (f float64, ok bool)

ParseFloat parses a decimal floating point number.

func ParseTimeShift added in v0.30.4

func ParseTimeShift(s string) (years, months, days int, duration time.Duration, ok bool)

ParseTimeShift parses a time shift modifier, also the output of timediff.

https://sqlite.org/lang_datefunc.html

func Unquote

func Unquote(val string) string

Unquote unquotes a string.

https://sqlite.org/lang_keywords.html

func ValidPageSize

func ValidPageSize(s int) bool

ValidPageSize returns true if s is a valid page size.

https://sqlite.org/fileformat.html#pages

Types

type Affinity added in v0.30.5

type Affinity byte

Affinity is the type affinity of a column.

https://sqlite.org/datatype3.html#type_affinity

const (
	TEXT Affinity = iota
	NUMERIC
	INTEGER
	REAL
	BLOB
)

func GetAffinity added in v0.30.5

func GetAffinity(declType string) Affinity

GetAffinity determines the affinity of a column by the declared type of the column.

https://sqlite.org/datatype3.html#determination_of_column_affinity

type Column

type Column struct {
	Name                  string
	Type                  string
	Length                string
	ConstraintName        string
	Comment               string
	IsPrimaryKey          bool
	IsAutoIncrement       bool
	IsNotNull             bool
	IsUnique              bool
	PKOrder               OrderClause
	PKConflictClause      ConflictClause
	NotNullConflictClause ConflictClause
	UniqueConflictClause  ConflictClause
	CheckExpr             string
	DefaultExpr           string
	CollateName           string
	ForeignKeyClause      *ForeignKey
	GeneratedExpr         string
	GeneratedType         GenType
}

Column holds metadata about a column.

type ConflictClause

type ConflictClause uint32
const (
	CONFLICT_NONE ConflictClause = iota
	CONFLICT_ROLLBACK
	CONFLICT_ABORT
	CONFLICT_FAIL
	CONFLICT_IGNORE
	CONFLICT_REPLACE
)

type ConstraintType added in v0.30.5

type ConstraintType uint32
const (
	TABLECONSTRAINT_PRIMARYKEY ConstraintType = iota
	TABLECONSTRAINT_UNIQUE
	TABLECONSTRAINT_CHECK
	TABLECONSTRAINT_FOREIGNKEY
)

type FKAction

type FKAction uint32
const (
	FKACTION_NONE FKAction = iota
	FKACTION_SETNULL
	FKACTION_SETDEFAULT
	FKACTION_CASCADE
	FKACTION_RESTRICT
	FKACTION_NOACTION
)

type FKDefType

type FKDefType uint32
const (
	DEFTYPE_NONE FKDefType = iota
	DEFTYPE_DEFERRABLE
	DEFTYPE_DEFERRABLE_INITIALLY_DEFERRED
	DEFTYPE_DEFERRABLE_INITIALLY_IMMEDIATE
	DEFTYPE_NOTDEFERRABLE
	DEFTYPE_NOTDEFERRABLE_INITIALLY_DEFERRED
	DEFTYPE_NOTDEFERRABLE_INITIALLY_IMMEDIATE
)

type ForeignKey

type ForeignKey struct {
	Table       string
	ColumnNames []string
	OnDelete    FKAction
	OnUpdate    FKAction
	Match       string
	Deferrable  FKDefType
}

ForeignKey holds metadata about a foreign key constraint.

type GenType added in v0.30.5

type GenType uint32
const (
	GENTYPE_NONE GenType = iota
	GENTYPE_STORED
	GENTYPE_VIRTUA
)

type IdxColumn added in v0.30.5

type IdxColumn struct {
	Name        string
	CollateName string
	Order       OrderClause
}

IdxColumn holds metadata about an indexed column.

type OrderClause

type OrderClause uint32
const (
	ORDER_NONE OrderClause = iota
	ORDER_ASC
	ORDER_DESC
)

type StatementType

type StatementType uint32
const (
	CREATE_UNKNOWN StatementType = iota
	CREATE_TABLE
	ALTER_RENAME_TABLE
	ALTER_RENAME_COLUMN
	ALTER_ADD_COLUMN
	ALTER_DROP_COLUMN
)

type Table

type Table struct {
	Name           string
	Schema         string
	Comment        string
	IsTemporary    bool
	IsIfNotExists  bool
	IsWithoutRowID bool
	IsStrict       bool
	Columns        []Column
	Constraints    []TableConstraint
	Type           StatementType
	CurrentName    string
	NewName        string
}

Table holds metadata about a table.

func ParseTable

func ParseTable(sql string) (_ *Table, err error)

ParseTable parses a CREATE or ALTER TABLE command.

type TableConstraint added in v0.30.5

type TableConstraint struct {
	Type ConstraintType
	Name string
	// Type is TABLECONSTRAINT_PRIMARYKEY or TABLECONSTRAINT_UNIQUE
	IndexedColumns  []IdxColumn
	ConflictClause  ConflictClause
	IsAutoIncrement bool
	// Type is TABLECONSTRAINT_CHECK
	CheckExpr string
	// Type is TABLECONSTRAINT_FOREIGNKEY
	ForeignKeyNames  []string
	ForeignKeyClause *ForeignKey
}

TableConstraint holds metadata about a table key constraint.

Jump to

Keyboard shortcuts

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