Documentation ¶
Index ¶
- Constants
- Variables
- func CreateMigration(name string) error
- func NewDB(dsn string, driverName string) *sql.DB
- type Column
- func (c *Column) Change()
- func (c *Column) Default(defaultValue any) *Column
- func (c *Column) Done() *Table
- func (c *Column) NotNull() *Column
- func (c *Column) Nullable() *Column
- func (c *Column) Primary() *Column
- func (c *Column) Type(dataType *DataType) *Column
- func (c *Column) Unique() *Column
- func (c *Column) Unsigned() *Column
- type DataSource
- type DataType
- func (dataType *DataType) AddSuffixes() *DataType
- func (dataType *DataType) AppendSufix(suffix string) *DataType
- func (dataType *DataType) SetColumnName(columnName string)
- func (dataType *DataType) SetDialect(dialect string)
- func (dataType *DataType) ToString() string
- func (dataType *DataType) WithEnumValues(enumValues []string) *DataType
- func (dataType *DataType) WithLength(length uint) *DataType
- func (dataType *DataType) WithPrecision(precision uint) *DataType
- func (dataType *DataType) WithScale(scale uint) *DataType
- type Migration
- type Migrator
- type Schema
- type Table
- func (t *Table) AddColumn(name string, dataType *DataType) *Column
- func (t *Table) AlterColumn(name string, dataType string) *Column
- func (t *Table) BigIncrements(name string) *Column
- func (t *Table) BigInt(name string) *Column
- func (t *Table) Binary(name string) *Column
- func (t *Table) Boolean(name string) *Column
- func (t *Table) Char(name string, length uint) *Column
- func (t *Table) Date(name string) *Column
- func (t *Table) DateTime(name string, precision uint) *Column
- func (t *Table) DateTimeTz(name string, precision uint) *Column
- func (t *Table) Decimal(name string, precision uint, scale uint) *Column
- func (t *Table) Double(name string, precision uint, scale uint) *Column
- func (t *Table) DropColumn(name string) *Column
- func (t *Table) DropForeignKey(name string)
- func (t *Table) DropIndex(indexName string)
- func (t *Table) DropPrimaryKey()
- func (t *Table) DropUniqueKey(name string)
- func (t *Table) Enum(name string, values ...string) *Column
- func (t *Table) Float(name string, precision uint, scale uint) *Column
- func (t *Table) Foreign(columns ...string) *foreignKey
- func (t *Table) ForeignID(column string) *foreignKey
- func (t *Table) HasConstraints() bool
- func (t *Table) Increments(name string) *Column
- func (t *Table) Index(columns ...string)
- func (t *Table) Int(name string) *Column
- func (t *Table) MediumInt(name string) *Column
- func (t *Table) PrimaryKey(columns ...string)
- func (t *Table) RenameColumn(oldName string, newName string) *Column
- func (t *Table) SmallInt(name string) *Column
- func (t *Table) String(name string, length uint) *Column
- func (t *Table) Text(name string) *Column
- func (t *Table) Time(name string, precision uint) *Column
- func (t *Table) Timestamp(name string, precision uint) *Column
- func (t *Table) TimestampTz(name string, precision uint) *Column
- func (t *Table) TinyInt(name string) *Column
- func (t *Table) UniqueKey(columns ...string)
- func (t *Table) UnsignedBigInt(name string) *Column
- func (t *Table) UnsignedInt(name string) *Column
- func (t *Table) UnsignedMediumInt(name string) *Column
- func (t *Table) UnsignedSmallInt(name string) *Column
- func (t *Table) UnsignedTinyInt(name string) *Column
Constants ¶
const ( DriverSQLite = "sqlite" DriverMySQL = "mysql" DriverPostgres = "postgres" ColTypeIncrements = "increments" ColTypeBigIncrements = "bigIncrements" ColTypeTinyInt = "tinyInt" ColTypeBool = "bool" ColTypeSmallInt = "smallInt" ColTypeMediumInt = "mediumInt" ColTypeInt = "int" ColTypeBigInt = "bigInt" ColTypeFloat = "float" ColTypeDouble = "double" ColTypeDecimal = "decimal" ColTypeDate = "date" ColTypeDateTime = "dateTime" ColTypeDateTimeTz = "dateTimeTz" ColTypeTime = "time" ColTypeTimestamp = "timestamp" ColTypeTimestampTz = "timestampTz" ColTypeChar = "char" ColTypeVarchar = "varchar" ColTypeText = "text" ColTypeTinyText = "tinyText" ColTypeMediumText = "mediumText" ColTypeLongText = "longText" ColTypeBinary = "binary" ColTypeVarBinary = "varBinary" ColTypeBlob = "blob" ColTypeTinyBlob = "tinyBlob" ColTypeMediumBlob = "mediumBlob" ColTypeLongBlob = "longBlob" ColTypeEnum = "enum" ColTypeSet = "set" )
Variables ¶
var (
ErrUnsupportedDialect = errors.New("unsupported driver")
)
Functions ¶
func CreateMigration ¶ added in v0.1.0
CreateMigration creates a migration file
Types ¶
type Column ¶ added in v0.1.0
type Column struct {
// contains filtered or unexported fields
}
Column type is the column definition
func (*Column) Change ¶ added in v0.1.0
func (c *Column) Change()
Change changes the operation of the column to alter
type DataSource ¶ added in v0.1.0
type DataSource struct { Driver string Host string Port string Username string Password string Name string Params string }
DataSource holds the necessary fields for a DSN (data source name)
func (*DataSource) String ¶ added in v0.1.0
func (ds *DataSource) String() (string, error)
String returns the string representation of the data source
type DataType ¶ added in v0.1.0
type DataType struct {
// contains filtered or unexported fields
}
DataType represents a column type
func NewDataType ¶ added in v0.1.0
NewDataType creates a new DataType
func (*DataType) AddSuffixes ¶ added in v0.1.0
AddSuffixes adds suffixes to the column type
func (*DataType) AppendSufix ¶ added in v0.1.0
AppendSufix appends a suffix to the column type
func (*DataType) SetColumnName ¶ added in v0.1.0
SetColumnName sets the column name of the column
func (*DataType) SetDialect ¶ added in v0.1.3
SetDialect sets the driver of the column
func (*DataType) ToString ¶ added in v0.1.0
ToString returns the string representation of the column type
func (*DataType) WithEnumValues ¶ added in v0.1.0
WithEnumValues sets the enum values of the column
func (*DataType) WithLength ¶ added in v0.1.0
WithLength sets the length of the column
func (*DataType) WithPrecision ¶ added in v0.1.0
WithPrecision sets the precision of the column
type Migration ¶
type Migration struct { Version string Up func(*sql.Tx) error Down func(*sql.Tx) error // contains filtered or unexported fields }
Migration represents a migration data type
type Migrator ¶
type Migrator struct { Versions []string Migrations map[string]*Migration // contains filtered or unexported fields }
Migrator is a struct that holds the migrations
func (*Migrator) AddMigration ¶
AddMigration adds a migration to the migrator
func (*Migrator) MigrationStatus ¶
Status checks which migrations have run and which have not
type Schema ¶ added in v0.1.0
type Schema struct {
// contains filtered or unexported fields
}
Schema type is the schema definition
func Alter ¶ added in v0.1.0
Alter provides callback to alter an existing table, and returns a schema
func NewSchema ¶ added in v0.1.0
func NewSchema() *Schema
NewSchema creates a new schema based on the driver provided in the environment variable DB_DRIVER
func (*Schema) HasCompositePrimaryKey ¶ added in v0.1.10
func (*Schema) HasForeignKeys ¶ added in v0.1.10
func (*Schema) HasNonPrimaryConstraints ¶ added in v0.1.10
func (*Schema) HasPrimaryKeyOnTable ¶ added in v0.1.10
func (*Schema) HasUniqueConstraints ¶ added in v0.1.10
type Table ¶ added in v0.1.0
type Table struct {
// contains filtered or unexported fields
}
Table type is the table definition
func (*Table) AlterColumn ¶ added in v0.1.0
AlterColumn alters a column in the table
func (*Table) BigIncrements ¶ added in v0.1.0
BigIncrements adds an auto-incrementing column to the table with big integers
func (*Table) DateTimeTz ¶ added in v0.1.0
DateTimeTz adds a date time with timezone column to the table
func (*Table) DropColumn ¶ added in v0.1.0
DropColumn drops a column from the table
func (*Table) DropForeignKey ¶ added in v0.1.0
DropForeignKey drops a foreign key from the table
func (*Table) DropPrimaryKey ¶ added in v0.1.0
func (t *Table) DropPrimaryKey()
DropPrimaryKey drops the primary key from the table
func (*Table) DropUniqueKey ¶ added in v0.1.1
DropUniqueKey drops a unique constraint from the table
func (*Table) ForeignID ¶ added in v0.1.3
ForeignID accepts an id column that references the primary column of another table
func (*Table) HasConstraints ¶ added in v0.1.0
HasConstraints returns true if the table has constraints
func (*Table) Increments ¶ added in v0.1.0
Increments adds an auto-incrementing column to the table
func (*Table) PrimaryKey ¶ added in v0.1.0
PrimaryKey adds a primary key to the table
func (*Table) RenameColumn ¶ added in v0.1.0
RenameColumn renames a column in the table
func (*Table) TimestampTz ¶ added in v0.1.0
TimestampTz adds a timestamp with timezone column to the table
func (*Table) UnsignedBigInt ¶ added in v0.1.0
UnsignedBigTInt adds an unsigned tiny integer column to the table
func (*Table) UnsignedInt ¶ added in v0.1.0
UnsignedInt adds an unsigned integer column to the table
func (*Table) UnsignedMediumInt ¶ added in v0.1.0
UnsignedMediumInt adds an unsigned medium integer column to the table
func (*Table) UnsignedSmallInt ¶ added in v0.1.0
UnsignedSmallInt adds an unsigned small integer column to the table
func (*Table) UnsignedTinyInt ¶ added in v0.1.0
UnsignedTinyInt adds an unsigned tiny integer column to the table