schema

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(c Context, name string, bp func(table *Blueprint)) error

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 Drop

func Drop(c Context, name string) error

Drop drops the table with the given name.

Example:

schema.Drop(ctx, "users")

func DropIfExists

func DropIfExists(c Context, name string) error

DropIfExists drops the table with the given name if it exists.

Example:

schema.DropIfExists(ctx, "users")

func HasColumn

func HasColumn(c Context, table, column string) (bool, error)

HasColumn checks if a column with the given name exists in the specified table.

Example:

exists, err := schema.HasColumn(ctx, "users", "email")

func HasColumns

func HasColumns(c Context, table string, columns []string) (bool, error)

HasColumns checks if all specified columns exist in the given table.

Example:

exists, err := schema.HasColumns(ctx, "users", []string{"email", "name"})

func HasIndex

func HasIndex(c Context, table string, columns []string) (bool, error)

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

func HasTable(c Context, name string) (bool, error)

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

func NewGrammar(dialectValue string) (blueprint.Grammar, error)

NewGrammar creates a new Grammar instance for the specified dialect.

func Rename

func Rename(c Context, from, to string) error

Rename renames a table from the given name to the new name.

Example:

schema.Rename(ctx, "users", "app_users")

func Table

func Table(c Context, name string, bp func(table *Blueprint)) error

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 Blueprint

type Blueprint = blueprint.Blueprint

func NewBlueprintForTesting added in v0.4.1

func NewBlueprintForTesting(name string, g blueprint.Grammar) *Blueprint

NewBlueprintForTesting creates a new Blueprint instance for testing purposes with the given name and grammar.

type Builder

type Builder = builders.Builder

func NewBuilder

func NewBuilder(dialectValue string) (Builder, error)

NewBuilder creates a new Builder instance for the specified dialect.

type Column

type Column = core.Column

func GetColumns

func GetColumns(c Context, table string) ([]*Column, error)

GetColumns retrieves the columns of the specified table.

Example:

columns, err := schema.GetColumns(ctx, "users")

type ColumnDefinition

type ColumnDefinition = blueprint.ColumnDefinition

type Context

type Context = core.Context

func NewContext

func NewContext(ctx context.Context, tx *sql.Tx, opts ...core.ContextOptions) Context

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 Index

type Index = core.Index

func GetIndexes

func GetIndexes(c Context, table string) ([]*Index, error)

GetIndexes retrieves the indexes of the specified table.

Example:

indexes, err := schema.GetIndexes(ctx, "users")

type IndexDefinition

type IndexDefinition = blueprint.IndexDefinition

type Row added in v0.4.1

type Row = core.Row

type Rows added in v0.4.1

type Rows = core.Rows

type TableInfo

type TableInfo = core.TableInfo

func GetTables

func GetTables(c Context) ([]*TableInfo, error)

GetTables retrieves the list of tables in the database.

Example:

tables, err := schema.GetTables(ctx)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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