reverse

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindComplexJunctionTables

func FindComplexJunctionTables(allTables *TableRegistry, junctionTables map[string]*JunctionInfo) map[string]string

FindComplexJunctionTables identifies complex junction tables (junction tables with additional fields)

func FindJunctionTables

func FindJunctionTables(allTables *TableRegistry) map[string]*JunctionInfo

FindJunctionTables identifies junction tables (m2m relationship tables) A junction table must have exactly 2 foreign keys and only primary keys + bool columns Bool columns are identified by names starting with "Is" (e.g., IsActive)

func GenerateModel

func GenerateModel(buf *bytes.Buffer, info *TableInfo,
	junctionTables map[string]*JunctionInfo, complexJunctionTables map[string]string,
	driverType, prefix string) error

GenerateModel generates Go struct code for a table

func MapSQLTypeToGo

func MapSQLTypeToGo(sqlType string, driver string) string

MapSQLTypeToGo maps SQL data types to Go types

func TrimShortPrefix

func TrimShortPrefix(name, prefix string) string

TrimShortPrefix trims the short prefix from the name if it exists.

func UnquoteWord

func UnquoteWord(word string) string

UnquoteWord removes quotes from a word if it is quoted.

Types

type ColumnInfo

type ColumnInfo struct {
	Name         string
	DataType     string
	IsNullable   bool
	IsPrimaryKey bool
	IsUnique     bool
	IsIndex      bool
	DefaultValue *string
}

ColumnInfo represents database column metadata

type ForeignKeyInfo

type ForeignKeyInfo struct {
	Name              string
	Columns           []string
	ReferencedTable   string
	ReferencedColumns []string
	IsUnique          bool
}

ForeignKeyInfo represents foreign key metadata

type IndexInfo

type IndexInfo struct {
	Name     string
	Columns  []string
	IsUnique bool
}

IndexInfo represents index metadata

type JunctionInfo

type JunctionInfo struct {
	Name             string
	ReferencedTables []string
}

JunctionInfo represents a junction table for m2m relationships

type O2MField

type O2MField struct {
	FieldName string
	TypeName  string
}

O2MField represents an o2m relationship field

type PrimaryKeyInfo

type PrimaryKeyInfo struct {
	Name    string
	Columns []string
}

PrimaryKeyInfo represents primary key metadata

type ReverseConfig

type ReverseConfig struct {
	DriverType  string
	DatabaseDSN string
	SchemaName  string
	TablePrefix string
}

func (*ReverseConfig) FixConfigData

func (rc *ReverseConfig) FixConfigData()

type ReverseEngineer

type ReverseEngineer struct {
	Config *ReverseConfig
	// contains filtered or unexported fields
}

ReverseEngineer implements database reverse engineering

func NewPgsqlReverseEngineer

func NewPgsqlReverseEngineer(dsn, schema string) (*ReverseEngineer, error)

NewPgsqlReverseEngineer creates a new PostgreSQL reverse engineer

func NewSqliteReverseEngineer

func NewSqliteReverseEngineer(dsn string) (*ReverseEngineer, error)

NewSqliteReverseEngineer creates a new SQLite reverse engineer

func (*ReverseEngineer) Close

func (r *ReverseEngineer) Close()

Close closes the database connection

func (*ReverseEngineer) GetDatabaseConfig

func (r *ReverseEngineer) GetDatabaseConfig() *model.DatabaseConfig

func (*ReverseEngineer) GetTableInfo

func (r *ReverseEngineer) GetTableInfo(tableName string) (*TableInfo, error)

GetTableInfo returns detailed information about a table

func (*ReverseEngineer) GetTables

func (r *ReverseEngineer) GetTables(prefix string) ([]string, error)

GetTables returns all tables in the schema

type SQLTemplates

type SQLTemplates struct {
	GetTables      string
	GetColumns     string
	GetPrimaryKey  string
	GetForeignKeys string
	GetIndexes     string
}

SQLTemplates holds database-specific SQL queries

type TableInfo

type TableInfo struct {
	Schema      string
	Name        string
	Columns     []*ColumnInfo
	PrimaryKey  *PrimaryKeyInfo
	ForeignKeys []*ForeignKeyInfo
	Indexes     []*IndexInfo
}

TableInfo represents database table metadata

type TableRegistry

type TableRegistry = utils.CoMap[string, TableInfo]

type TableRelationshipInfo

type TableRelationshipInfo struct {
	Type                 TableType
	JunctionOtherTable   string
	ComplexJunctionTable string
	O2OFields            []string
	O2MFields            []O2MField
}

TableRelationshipInfo holds relationship information for a table

type TableType

type TableType int

TableType represents the type of table

const (
	TableTypeNormal TableType = iota
	TableTypeJunction
	TableTypeComplexJunction
)

Jump to

Keyboard shortcuts

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