definition

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts a string to snake_case.

func ValidateName

func ValidateName(name string) error

ValidateName checks if a name is valid (alphanumeric + underscore).

Types

type Field

type Field struct {
	Name        string     `json:"name"`
	Column      string     `json:"column"`
	Type        FieldType  `json:"type"`
	Description string     `json:"description,omitempty"`
	Primary     bool       `json:"primary,omitempty"`
	Unique      bool       `json:"unique,omitempty"`
	Required    bool       `json:"required,omitempty"`
	Nullable    bool       `json:"nullable,omitempty"`
	Default     any        `json:"default,omitempty"`
	Length      int        `json:"length,omitempty"`
	Precision   int        `json:"precision,omitempty"`
	Scale       int        `json:"scale,omitempty"`
	AutoGen     bool       `json:"autoGen,omitempty"` // Auto-generated (e.g., timestamps)
	References  *Reference `json:"references,omitempty"`
}

Field represents a table column.

type FieldType

type FieldType string

FieldType represents supported field types.

const (
	FieldTypeString    FieldType = "string"
	FieldTypeText      FieldType = "text"
	FieldTypeInteger   FieldType = "integer"
	FieldTypeBigInt    FieldType = "bigint"
	FieldTypeFloat     FieldType = "float"
	FieldTypeDecimal   FieldType = "decimal"
	FieldTypeBoolean   FieldType = "boolean"
	FieldTypeTimestamp FieldType = "timestamp"
	FieldTypeDate      FieldType = "date"
	FieldTypeTime      FieldType = "time"
	FieldTypeUUID      FieldType = "uuid"
	FieldTypeJSON      FieldType = "json"
	FieldTypeJSONB     FieldType = "jsonb"
	FieldTypeBinary    FieldType = "binary"
	FieldTypeEnum      FieldType = "enum"
)

type Index

type Index struct {
	Name    string   `json:"name"`
	Columns []string `json:"columns"`
	Unique  bool     `json:"unique,omitempty"`
	Type    string   `json:"type,omitempty"` // btree, hash, gin, etc.
}

Index represents a database index.

type Model

type Model struct {
	Name        string     `json:"name"`
	Table       string     `json:"table"`
	Description string     `json:"description,omitempty"`
	Fields      []Field    `json:"fields"`
	Indexes     []Index    `json:"indexes,omitempty"`
	Relations   []Relation `json:"relations,omitempty"`
}

Model represents a database table.

type Reference

type Reference struct {
	Model    string `json:"model"`
	Field    string `json:"field"`
	OnDelete string `json:"onDelete,omitempty"` // CASCADE, SET NULL, RESTRICT, etc.
	OnUpdate string `json:"onUpdate,omitempty"`
}

Reference represents a foreign key reference.

type Relation

type Relation struct {
	Name       string       `json:"name"`
	Type       RelationType `json:"type"`
	Model      string       `json:"model"`
	ForeignKey string       `json:"foreignKey,omitempty"`
	References string       `json:"references,omitempty"`
	Through    string       `json:"through,omitempty"` // For many-to-many
}

Relation represents relationships between models.

type RelationType

type RelationType string

RelationType represents relationship types.

const (
	RelationBelongsTo  RelationType = "belongsTo"
	RelationHasOne     RelationType = "hasOne"
	RelationHasMany    RelationType = "hasMany"
	RelationManyToMany RelationType = "manyToMany"
)

type Schema

type Schema struct {
	Version     string           `json:"version"`
	Description string           `json:"description,omitempty"`
	Models      map[string]Model `json:"models"`
}

Schema represents the complete database schema.

func LoadFromFile

func LoadFromFile(path string) (*Schema, error)

LoadFromFile loads a schema from a JSON file.

func (*Schema) AddModel

func (s *Schema) AddModel(model Model)

AddModel adds a model to the schema.

func (*Schema) GetModel

func (s *Schema) GetModel(name string) (Model, bool)

GetModel returns a model by name.

func (*Schema) SaveToFile

func (s *Schema) SaveToFile(path string) error

SaveToFile saves a schema to a JSON file.

func (*Schema) Validate

func (s *Schema) Validate() error

Validate validates the schema for correctness.

Jump to

Keyboard shortcuts

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