sqlschema

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NONE for None
	NONE = 0

	// Serialize Types
	ARRAY = 1
	JSON  = 2
	YAML  = 3

	// Index Types
	INDEX       = 1
	UNIQUE      = 2
	PRIMARY_KEY = 3
)

Variables

View Source
var (
	ErrUnknownColumn = errors.New("unknown column")
)

Functions

func Insert added in v0.1.0

func Insert(ctx context.Context, db *sql.DB, table string, v any) error

func ScanRrow added in v0.1.0

func ScanRrow(row *sql.Rows, v any) error

func Update added in v0.1.0

func Update(ctx context.Context, db *sql.DB, table string, columns []string, v any) error

Types

type Field

type Field struct {
	Name          string
	Type          string
	Nullable      bool
	AutoIncrement bool
	DefaultValue  string
	Comment       string
}

func (*Field) Equal

func (fd *Field) Equal(other *Field) bool

type Index

type Index struct {
	Name    string
	Columns []string
	Primary bool
	Unique  bool
}

func (*Index) Equal

func (idx *Index) Equal(other *Index) bool

type Schema

type Schema struct {
	Name    string
	Fields  []*Field
	Indices []*Index
	Engine  string
	Collate string
	Comment string
}

func GetSchema added in v0.1.0

func GetSchema(v any) *Schema

func ReadFromDB

func ReadFromDB(db *sql.DB, ctx context.Context, name string) (*Schema, error)

func (*Schema) Create

func (sc *Schema) Create(db *sql.DB, ctx context.Context) error

func (*Schema) Field

func (sc *Schema) Field(name string) *Field

func (*Schema) Index

func (sc *Schema) Index(name string) *Index

func (*Schema) Update

func (sc *Schema) Update(db *sql.DB, ctx context.Context) error

Jump to

Keyboard shortcuts

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