Added more examples and pgsql reader
Some checks are pending
CI / Build (push) Waiting to run
CI / Test (1.23) (push) Waiting to run
CI / Test (1.24) (push) Waiting to run
CI / Test (1.25) (push) Waiting to run
CI / Lint (push) Waiting to run

This commit is contained in:
2025-12-17 10:08:50 +02:00
parent 5d60bc3b2c
commit db6cd21511
22 changed files with 6741 additions and 1 deletions

View File

@@ -30,6 +30,8 @@ type Schema struct {
Name string `json:"name" yaml:"name" xml:"name"`
Description string `json:"description,omitempty" yaml:"description,omitempty" xml:"description,omitempty"`
Tables []*Table `json:"tables" yaml:"tables" xml:"-"`
Views []*View `json:"views,omitempty" yaml:"views,omitempty" xml:"-"`
Sequences []*Sequence `json:"sequences,omitempty" yaml:"sequences,omitempty" xml:"-"`
Owner string `json:"owner" yaml:"owner" xml:"owner"`
Permissions map[string]string `json:"permissions,omitempty" yaml:"permissions,omitempty" xml:"-"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
@@ -84,6 +86,47 @@ func (m Table) GetForeignKeys() []*Constraint {
return keys
}
// View represents a database view (read-only)
type View struct {
Name string `json:"name" yaml:"name" xml:"name"`
Description string `json:"description,omitempty" yaml:"description,omitempty" xml:"description,omitempty"`
Schema string `json:"schema" yaml:"schema" xml:"schema"`
Definition string `json:"definition" yaml:"definition" xml:"definition"` // SQL definition
Columns map[string]*Column `json:"columns" yaml:"columns" xml:"-"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty" xml:"-"`
Sequence uint `json:"sequence,omitempty" yaml:"sequence,omitempty" xml:"sequence,omitempty"`
RefSchema *Schema `json:"ref_schema,omitempty" yaml:"ref_schema,omitempty" xml:"ref_schema,omitempty"`
}
// SQLName returns the view name in lowercase
func (d *View) SQLName() string {
return strings.ToLower(d.Name)
}
// Sequence represents a database sequence (auto-increment generator)
type Sequence struct {
Name string `json:"name" yaml:"name" xml:"name"`
Description string `json:"description,omitempty" yaml:"description,omitempty" xml:"description,omitempty"`
Schema string `json:"schema" yaml:"schema" xml:"schema"`
StartValue int64 `json:"start_value" yaml:"start_value" xml:"start_value"`
MinValue int64 `json:"min_value,omitempty" yaml:"min_value,omitempty" xml:"min_value,omitempty"`
MaxValue int64 `json:"max_value,omitempty" yaml:"max_value,omitempty" xml:"max_value,omitempty"`
IncrementBy int64 `json:"increment_by" yaml:"increment_by" xml:"increment_by"`
CacheSize int64 `json:"cache_size,omitempty" yaml:"cache_size,omitempty" xml:"cache_size,omitempty"`
Cycle bool `json:"cycle" yaml:"cycle" xml:"cycle"`
OwnedByTable string `json:"owned_by_table,omitempty" yaml:"owned_by_table,omitempty" xml:"owned_by_table,omitempty"`
OwnedByColumn string `json:"owned_by_column,omitempty" yaml:"owned_by_column,omitempty" xml:"owned_by_column,omitempty"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
Sequence uint `json:"sequence,omitempty" yaml:"sequence,omitempty" xml:"sequence,omitempty"`
RefSchema *Schema `json:"ref_schema,omitempty" yaml:"ref_schema,omitempty" xml:"ref_schema,omitempty"`
}
// SQLName returns the sequence name in lowercase
func (d *Sequence) SQLName() string {
return strings.ToLower(d.Name)
}
// Column represents a table column
type Column struct {
Name string `json:"name" yaml:"name" xml:"name"`
@@ -218,6 +261,8 @@ func InitSchema(name string) *Schema {
return &Schema{
Name: name,
Tables: make([]*Table, 0),
Views: make([]*View, 0),
Sequences: make([]*Sequence, 0),
Permissions: make(map[string]string),
Metadata: make(map[string]any),
Scripts: make([]*Script, 0),
@@ -281,3 +326,23 @@ func InitScript(name string) *Script {
RunAfter: make([]string, 0),
}
}
// InitView initializes a new View with empty maps
func InitView(name, schema string) *View {
return &View{
Name: name,
Schema: schema,
Columns: make(map[string]*Column),
Metadata: make(map[string]any),
}
}
// InitSequence initializes a new Sequence with default values
func InitSequence(name, schema string) *Sequence {
return &Sequence{
Name: name,
Schema: schema,
IncrementBy: 1,
StartValue: 1,
}
}