sql3util

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 7 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 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 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
}

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 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
	Columns    []string
	OnDelete   FKAction
	OnUpdate   FKAction
	Match      string
	Deferrable FKDefType
}

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

Jump to

Keyboard shortcuts

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