sql

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute interface {
	Name() string
	Value() any
}

Attribute represents an attribute definition.

type Column

type Column struct {
	Name          string
	Type          spec.Type
	Unique        bool
	Nullable      bool
	Sensitive     bool
	Comment       string
	Default       sql.NullString
	Charset       string
	Collation     string
	Precision     int
	Scale         int
	Primary       bool
	AutoIncrement bool
	OnUpdate      bool
	Attrs         []Attribute

	Table *Table
}

Column represents a column definition.

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

func Open

func Open(dialect, dsn string) (*Driver, error)

func OpenDB

func OpenDB(dialect string, db *sql.DB) *Driver

func (*Driver) Close

func (d *Driver) Close() error

func (*Driver) Dialect

func (d *Driver) Dialect() string

func (*Driver) Exec

func (d *Driver) Exec(ctx context.Context, query string, args ...any) (any, error)

func (*Driver) Query

func (d *Driver) Query(ctx context.Context, query string, args ...any) (any, error)

Query implements the cre.Query method.

func (*Driver) QueryRow

func (d *Driver) QueryRow(ctx context.Context, query string, args ...any) (any, error)

QueryRow implements the cre.QueryRow method.

type Expression

type Expression interface{}

type ForeignKey

type ForeignKey struct {
	Name       string
	Table      *Table
	Columns    []*Column
	RefTable   *Table
	RefColumns []*Column
	Inverse    bool
	OnUpdate   ReferenceOption
	OnDelete   ReferenceOption
	Attrs      []Attribute
}

type Index

type Index struct {
	Name         string
	Unique       bool
	Type         string
	Comment      string
	IndexColumns []*IndexColumn
	Primary      bool
}

type IndexColumn

type IndexColumn struct {
	SeqNo  int
	Column string
	Sub    int
	Expr   Expression
}

type Inspector

type Inspector interface {
	Inspect(ctx context.Context, name string) (*Schema, error)
}

type ReferenceOption

type ReferenceOption string

ReferenceOption represents constraint actions.

const (
	NoAction   ReferenceOption = "NO ACTION"
	Restrict   ReferenceOption = "RESTRICT"
	Cascade    ReferenceOption = "CASCADE"
	SetNull    ReferenceOption = "SET NULL"
	SetDefault ReferenceOption = "SET DEFAULT"
)

https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html#foreign-key-referential-actions the referential action specified by ON UPDATE and ON DELETE subclauses of the FOREIGN KEY clause

type Schema

type Schema struct {
	Name   string
	Tables []*Table
	Attrs  []Attribute
}

Schema represents an schema definition.

func (*Schema) Convert

func (s *Schema) Convert() (*spec.Schema, error)

func (*Schema) Table

func (s *Schema) Table(name string) *Table

type Table

type Table struct {
	Name          string
	Charset       string
	Collation     string
	AutoIncrement int
	Comment       string
	Options       string
	Columns       []*Column
	Indexes       []*Index
	ForeignKeys   []*ForeignKey
	Attrs         []Attribute

	Schema *Schema
}

Table represents a table definition.

func (*Table) Column

func (t *Table) Column(name string) *Column

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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