db

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTransactionWithOptions

func RunTransactionWithOptions(ctx context.Context, db *sql.DB, txOpts *sql.TxOptions, txWork TransactionScopedWork) error

RunTransactionWithOptions executes a block of code within a database transaction.

Types

type AlterTableSqlBuilder

type AlterTableSqlBuilder struct {
	Dialect DialectType
	Name    string
	Changes []string
}

func (*AlterTableSqlBuilder) AddColumn

func (b *AlterTableSqlBuilder) AddColumn(col *Column) *AlterTableSqlBuilder

func (*AlterTableSqlBuilder) AddUniqueConstraint

func (b *AlterTableSqlBuilder) AddUniqueConstraint(name string, columns ...string) *AlterTableSqlBuilder

func (*AlterTableSqlBuilder) ChangeColumn

func (b *AlterTableSqlBuilder) ChangeColumn(name string, col *Column) *AlterTableSqlBuilder

func (*AlterTableSqlBuilder) ToSQL

func (b *AlterTableSqlBuilder) ToSQL() (string, error)

type Column

type Column struct {
	Dialect    DialectType
	Name       string
	Nullable   bool
	Default    OptionalString
	Type       ColumnType
	Size       OptionalInt
	PrimaryKey bool
}

func (*Column) SetDefault

func (c *Column) SetDefault(value string) *Column

func (*Column) SetDefaultCurrentTimestamp

func (c *Column) SetDefaultCurrentTimestamp() *Column

func (*Column) SetName

func (c *Column) SetName(name string) *Column

func (*Column) SetNullable

func (c *Column) SetNullable(nullable bool) *Column

func (*Column) SetPrimaryKey

func (c *Column) SetPrimaryKey(pk bool) *Column

func (*Column) SetSize

func (c *Column) SetSize(size int) *Column

func (*Column) SetType

func (c *Column) SetType(t ColumnType) *Column

func (*Column) String

func (c *Column) String() (string, error)

type ColumnType

type ColumnType int
const (
	ColumnTypeBool     ColumnType = iota
	ColumnTypeSmallInt ColumnType = iota
	ColumnTypeInteger  ColumnType = iota
	ColumnTypeChar     ColumnType = iota
	ColumnTypeVarChar  ColumnType = iota
	ColumnTypeText     ColumnType = iota
	ColumnTypeDateTime ColumnType = iota
)

func (ColumnType) Format

func (d ColumnType) Format(dialect DialectType, size OptionalInt) (string, error)

type CreateIndexSqlBuilder

type CreateIndexSqlBuilder struct {
	Dialect DialectType
	Name    string
	Table   string
	Unique  bool
	Columns []string
}

func (*CreateIndexSqlBuilder) ToSQL

func (b *CreateIndexSqlBuilder) ToSQL() (string, error)

type CreateTableSqlBuilder

type CreateTableSqlBuilder struct {
	Dialect     DialectType
	Name        string
	IfNotExists bool
	ColumnOrder []string
	Columns     map[string]*Column
	Constraints []string
}

func (*CreateTableSqlBuilder) Column

func (*CreateTableSqlBuilder) SetIfNotExists

func (b *CreateTableSqlBuilder) SetIfNotExists(ine bool) *CreateTableSqlBuilder

func (*CreateTableSqlBuilder) ToSQL

func (b *CreateTableSqlBuilder) ToSQL() (string, error)

func (*CreateTableSqlBuilder) UniqueConstraint

func (b *CreateTableSqlBuilder) UniqueConstraint(columns ...string) *CreateTableSqlBuilder

type DialectType

type DialectType int
const (
	DialectSQLite DialectType = iota
	DialectMySQL  DialectType = iota
)

func (DialectType) AlterTable

func (d DialectType) AlterTable(name string) *AlterTableSqlBuilder

func (DialectType) Column

func (d DialectType) Column(name string, t ColumnType, size OptionalInt) *Column

func (DialectType) CreateIndex

func (d DialectType) CreateIndex(name, table string, columns ...string) *CreateIndexSqlBuilder

func (DialectType) CreateUniqueIndex

func (d DialectType) CreateUniqueIndex(name, table string, columns ...string) *CreateIndexSqlBuilder

func (DialectType) DropIndex

func (d DialectType) DropIndex(name, table string) *DropIndexSqlBuilder

func (DialectType) Table

func (d DialectType) Table(name string) *CreateTableSqlBuilder

type DropIndexSqlBuilder

type DropIndexSqlBuilder struct {
	Dialect DialectType
	Name    string
	Table   string
}

func (*DropIndexSqlBuilder) ToSQL

func (b *DropIndexSqlBuilder) ToSQL() (string, error)

type OptionalInt

type OptionalInt struct {
	Set   bool
	Value int
}
var UnsetSize OptionalInt = OptionalInt{Set: false, Value: 0}

type OptionalString

type OptionalString struct {
	Set   bool
	Value string
}
var UnsetDefault OptionalString = OptionalString{Set: false, Value: ""}

type RawSqlBuilder

type RawSqlBuilder struct {
	Query string
}

func (*RawSqlBuilder) ToSQL

func (b *RawSqlBuilder) ToSQL() (string, error)

type SQLBuilder

type SQLBuilder interface {
	ToSQL() (string, error)
}

type TransactionScopedWork

type TransactionScopedWork func(ctx context.Context, db *sql.Tx) error

TransactionScopedWork describes code executed within a database transaction.

Jump to

Keyboard shortcuts

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