Documentation
¶
Index ¶
- func Create(c Context, name string, bp func(table *Blueprint)) error
- func Drop(c Context, name string) error
- func DropIfExists(c Context, name string) error
- func HasColumn(c Context, table, column string) (bool, error)
- func HasColumns(c Context, table string, columns []string) (bool, error)
- func HasIndex(c Context, table string, columns []string) (bool, error)
- func HasTable(c Context, name string) (bool, error)
- func NewDryRunContext(ctx context.Context, opts ...core.DryRunContextOptions) *core.DryRunContext
- func NewGrammar(dialectValue string) (blueprint.Grammar, error)
- func Rename(c Context, from, to string) error
- func Table(c Context, name string, bp func(table *Blueprint)) error
- func WithDialect(dialect string) core.ContextOptions
- func WithDryRunDialect(dialect string) core.DryRunContextOptions
- func WithFilename(filename string) core.ContextOptions
- type Blueprint
- type Builder
- type Column
- type ColumnDefinition
- type Context
- type Expression
- type ForeignKeyDefinition
- type Index
- type IndexDefinition
- type Row
- type Rows
- type TableInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
Create creates a new table with the given name and blueprint.
Example:
schema.Create(ctx, "users", func(table *schema.Blueprint) {
table.String("name")
table.Integer("age")
})
func DropIfExists ¶
DropIfExists drops the table with the given name if it exists.
Example:
schema.DropIfExists(ctx, "users")
func HasColumn ¶
HasColumn checks if a column with the given name exists in the specified table.
Example:
exists, err := schema.HasColumn(ctx, "users", "email")
func HasColumns ¶
HasColumns checks if all specified columns exist in the given table.
Example:
exists, err := schema.HasColumns(ctx, "users", []string{"email", "name"})
func HasIndex ¶
HasIndex checks if an index exists on the specified table for the given columns.
Example:
exists, err := schema.HasIndex(ctx, "users", []string{"email"})
func HasTable ¶
HasTable checks if a table with the given name exists.
Example:
exists, err := schema.HasTable(ctx, "users")
func NewDryRunContext ¶ added in v0.4.0
func NewDryRunContext(ctx context.Context, opts ...core.DryRunContextOptions) *core.DryRunContext
NewDryRunContext creates a new DryRunContext with the given base context and options.
func NewGrammar ¶ added in v0.4.1
NewGrammar creates a new Grammar instance for the specified dialect.
func Rename ¶
Rename renames a table from the given name to the new name.
Example:
schema.Rename(ctx, "users", "app_users")
func Table ¶
Table modifies the table with the given name using the provided blueprint.
Example:
schema.Table(ctx, "users", func(table *schema.Blueprint) {
table.String("email").Unique()
})
func WithDialect ¶ added in v0.4.1
func WithDialect(dialect string) core.ContextOptions
WithDialect returns a ContextOption that sets the dialect for the context.
func WithDryRunDialect ¶ added in v0.4.1
func WithDryRunDialect(dialect string) core.DryRunContextOptions
WithDryRunDialect returns a DryRunContextOption that sets the dialect for the dry run context.
func WithFilename ¶
func WithFilename(filename string) core.ContextOptions
WithFilename returns a ContextOption that sets the filename for the context.
Types ¶
type Builder ¶
func NewBuilder ¶
NewBuilder creates a new Builder instance for the specified dialect.
type ColumnDefinition ¶
type ColumnDefinition = blueprint.ColumnDefinition
type Context ¶
func NewContext ¶
NewContext creates a new Context with the given base context, transaction, and options.
type Expression ¶
type Expression = blueprint.Expression
type ForeignKeyDefinition ¶
type ForeignKeyDefinition = blueprint.ForeignKeyDefinition
type IndexDefinition ¶
type IndexDefinition = blueprint.IndexDefinition