types

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var ValidFieldTypes = map[string]bool{
	"varchar":      true,
	"text":         true,
	"integer":      true,
	"bigint":       true,
	"float":        true,
	"decimal":      true,
	"boolean":      true,
	"date":         true,
	"timestamp":    true,
	"time":         true,
	"uuid":         true,
	"json":         true,
	"jsonb":        true,
	"serial":       true,
	"foreign_key":  true,
	"many_to_many": true,
}

ValidFieldTypes represents valid YAML field types

Functions

func IsValidDatabase

func IsValidDatabase(db string) bool

IsValidDatabase checks if a database type is valid

func IsValidFieldType

func IsValidFieldType(fieldType string) bool

IsValidFieldType checks if a field type is valid

Types

type Database

type Database struct {
	Name             string `yaml:"name"`
	Version          string `yaml:"version"`
	MigrationVersion string `yaml:"migration_version,omitempty"`
}

Database represents the database metadata

type DatabaseType

type DatabaseType string

DatabaseType represents supported database types

const (
	DatabasePostgreSQL DatabaseType = "postgresql"
	DatabaseMySQL      DatabaseType = "mysql"
	DatabaseSQLServer  DatabaseType = "sqlserver"
	DatabaseSQLite     DatabaseType = "sqlite"
	DatabaseRedshift   DatabaseType = "redshift"
	DatabaseClickHouse DatabaseType = "clickhouse"
	DatabaseTiDB       DatabaseType = "tidb"
	DatabaseVertica    DatabaseType = "vertica"
	DatabaseYDB        DatabaseType = "ydb"
	DatabaseTurso      DatabaseType = "turso"
	DatabaseStarRocks  DatabaseType = "starrocks"
	DatabaseAuroraDSQL DatabaseType = "auroradsql"
)

func ParseDatabaseType

func ParseDatabaseType(db string) (DatabaseType, error)

ParseDatabaseType parses a string into a DatabaseType

type Defaults

type Defaults struct {
	PostgreSQL map[string]string `yaml:"postgresql"`
	SQLServer  map[string]string `yaml:"sqlserver"`
	MySQL      map[string]string `yaml:"mysql"`
	SQLite     map[string]string `yaml:"sqlite"`
	Redshift   map[string]string `yaml:"redshift"`
	ClickHouse map[string]string `yaml:"clickhouse"`
	TiDB       map[string]string `yaml:"tidb"`
	Vertica    map[string]string `yaml:"vertica"`
	YDB        map[string]string `yaml:"ydb"`
	Turso      map[string]string `yaml:"turso"`
	StarRocks  map[string]string `yaml:"starrocks"`
	AuroraDSQL map[string]string `yaml:"auroradsql"`
}

Defaults represents default value mappings per database type

type Field

type Field struct {
	Name       string      `yaml:"name"`
	Type       string      `yaml:"type"`
	PrimaryKey bool        `yaml:"primary_key,omitempty"`
	Nullable   *bool       `yaml:"nullable,omitempty"`
	Default    string      `yaml:"default,omitempty"`
	Length     int         `yaml:"length,omitempty"`
	Precision  int         `yaml:"precision,omitempty"`
	Scale      int         `yaml:"scale,omitempty"`
	AutoCreate bool        `yaml:"auto_create,omitempty"`
	AutoUpdate bool        `yaml:"auto_update,omitempty"`
	ForeignKey *ForeignKey `yaml:"foreign_key,omitempty"`
	ManyToMany *ManyToMany `yaml:"many_to_many,omitempty"`
}

Field represents a database field/column definition

func (*Field) IsNullable

func (f *Field) IsNullable() bool

IsNullable returns the nullable value, defaulting to true if not set

func (*Field) SetNullable

func (f *Field) SetNullable(nullable bool)

SetNullable sets the nullable field

func (*Field) Validate

func (f *Field) Validate() error

Validate validates the field structure

type ForeignKey

type ForeignKey struct {
	Table    string `yaml:"table"`
	OnDelete string `yaml:"on_delete"`
}

ForeignKey represents a foreign key relationship

type Include

type Include struct {
	Module string `yaml:"module"`
	Path   string `yaml:"path"`
}

Include represents an external schema to include

func (*Include) Validate

func (i *Include) Validate() error

Validate validates the include structure

type Index

type Index struct {
	Name   string   `yaml:"name"`
	Fields []string `yaml:"fields"`
	Unique bool     `yaml:"unique,omitempty"`
}

Index represents a database index definition

func (*Index) Validate

func (i *Index) Validate(table Table) error

Validate validates the index structure

type ManyToMany

type ManyToMany struct {
	Table string `yaml:"table"`
}

ManyToMany represents a many-to-many relationship

type Schema

type Schema struct {
	Database Database  `yaml:"database"`
	Include  []Include `yaml:"include,omitempty"`
	Defaults Defaults  `yaml:"defaults"`
	Tables   []Table   `yaml:"tables"`
}

Schema represents a YAML schema file structure

func (*Schema) GetTableByName

func (s *Schema) GetTableByName(name string) *Table

GetTableByName finds a table by name in the schema

func (*Schema) Validate

func (s *Schema) Validate() error

Validate validates the schema structure

type Table

type Table struct {
	Name    string  `yaml:"name"`
	Fields  []Field `yaml:"fields"`
	Indexes []Index `yaml:"indexes,omitempty"`
}

Table represents a database table definition

func (*Table) GetFieldByName

func (t *Table) GetFieldByName(name string) *Field

GetFieldByName finds a field by name in the table

func (*Table) GetPrimaryKeyField

func (t *Table) GetPrimaryKeyField() *Field

GetPrimaryKeyField returns the primary key field if it exists

func (*Table) HasPrimaryKey

func (t *Table) HasPrimaryKey() bool

HasPrimaryKey checks if the table has a primary key field

Jump to

Keyboard shortcuts

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