Documentation
¶
Overview ¶
MIT License
Copyright (c) 2025 OcomSoft ¶
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 ¶
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 ¶
IsValidDatabase checks if a database type is valid
func IsValidFieldType ¶
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 ¶
IsNullable returns the nullable value, defaulting to true if not set
func (*Field) SetNullable ¶
SetNullable sets the nullable field
type ForeignKey ¶
ForeignKey represents a foreign key relationship
type Index ¶
type Index struct {
Name string `yaml:"name"`
Fields []string `yaml:"fields"`
Unique bool `yaml:"unique,omitempty"`
}
Index represents a database index definition
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 ¶
GetTableByName finds a table by name in the schema
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 ¶
GetFieldByName finds a field by name in the table
func (*Table) GetPrimaryKeyField ¶
GetPrimaryKeyField returns the primary key field if it exists
func (*Table) HasPrimaryKey ¶
HasPrimaryKey checks if the table has a primary key field