schema

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 13 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 struct {
	Name string
	Type string
	Null bool
}

type BelongsTo

type BelongsTo struct {
	Name        string
	ModelName   string
	ForeignKey  string
	ForeignType string
	PrimaryKey  string
	Type        string
	Index       bool
	Null        bool
	Dependent   string
	Optional    bool
	Required    bool
	Default     bool
}

func NewBelongsTo added in v0.1.7

func NewBelongsTo(name string) *BelongsTo

type Column

type Column struct {
	// column name in snake case
	Name string
	Type string
	// array type
	Array bool
	// nullable, allow_null by default
	Null bool
	// sql auto_increment
	AutoIncrement bool
	Default       interface{} // TODO: support default
}

type Config

type Config struct {
	Adapter     string
	Environment string
	URL         types.StringOrEnv
	Database    string
	Host        string
	Port        string
	User        string
	Password    string
	Encoding    string
	Pool        int
	Timeout     int
	Socket      string
	Options     map[string]string
	RawOptions  string
}

type Database

type Database struct {
	Name       string
	Adapter    string
	TimeZone   string
	Generators []*Generator
	Configs    []*Config
	Models     []*Model
	// contains filtered or unexported fields
}

func (*Database) CreateMySQLSchema added in v0.1.7

func (d *Database) CreateMySQLSchema(dbName string) *schema.Schema

convert a mysql queryx database schema to an atlas sql schema

func (*Database) CreatePostgreSQLSchema added in v0.1.7

func (d *Database) CreatePostgreSQLSchema(dbName string) *schema.Schema

convert a postgresql queryx database schema to an atlas sql schema

func (*Database) CreateSQLiteSchema

func (d *Database) CreateSQLiteSchema(dbName string) *schema.Schema

func (*Database) LoadConfig

func (d *Database) LoadConfig(environment string) *Config

func (*Database) NewConfig

func (d *Database) NewConfig(environment string) *Config

func (*Database) NewModel

func (d *Database) NewModel(name string) *Model

initialize new model with defaults

func (*Database) Tables

func (d *Database) Tables() []string

type Enum

type Enum struct {
	Name string
}

type Generator

type Generator struct {
	Name string
	Test bool
}

type HasMany

type HasMany struct {
	Name       string
	ModelName  string
	Through    string
	ForeignKey string
	Source     string
	BelongsTo  *BelongsTo
}

type HasOne

type HasOne struct {
	Name       string
	ModelName  string
	Through    string
	ForeignKey string
	BelongsTo  *BelongsTo
}

type Index

type Index struct {
	TableName   string
	ColumnNames []string
	Unique      bool
}

type Model

type Model struct {
	Database *Database
	// model name in camel case
	Name       string
	TableName  string
	TimeZone   string
	Timestamps bool
	Columns    []*Column
	Attributes []*Attribute
	BelongsTo  []*BelongsTo
	HasMany    []*HasMany
	HasOne     []*HasOne
	Index      []*Index
	// whether to automatically add a default primary key column named "id", default true
	DefaultPrimaryKey bool
	PrimaryKey        *PrimaryKey
}

func (*Model) AddBelongsTo

func (m *Model) AddBelongsTo(belongsTo *BelongsTo)

func (*Model) AddColumn added in v0.1.7

func (m *Model) AddColumn(column *Column)

func (*Model) AddDefaultPrimaryKey

func (m *Model) AddDefaultPrimaryKey()

set default primary key with id column for a model

func (*Model) AddHasMany

func (m *Model) AddHasMany(hasMany *HasMany)

func (*Model) AddHasOne

func (m *Model) AddHasOne(hasOne *HasOne)

func (*Model) AddIndex

func (m *Model) AddIndex(index *Index)

func (*Model) AddTimestamps

func (m *Model) AddTimestamps()

func (*Model) SetPrimaryKey

func (m *Model) SetPrimaryKey(columnNames []string)

custom primary key for a model

func (*Model) String

func (m *Model) String() string

String implements the stringer interface.

type PrimaryKey

type PrimaryKey struct {
	TableName   string
	Columns     []*Column
	ColumnNames []string
}

type Schema

type Schema struct {
	Databases []*Database
}

func NewSchema

func NewSchema() *Schema

func Parse

func Parse(body hcl.Body) (*Schema, error)

func (*Schema) NewDatabase

func (s *Schema) NewDatabase(name string) *Database

type Type

type Type struct {
	Name string
}

Jump to

Keyboard shortcuts

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