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.
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.
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.
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.
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.
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.
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.
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 ¶
- type Config
- func (c *Config) AddCustomDefault(database, key, value string)
- func (c *Config) AddTypeMapping(goType, sqlType string)
- func (c *Config) GetCustomDefault(database, key string) (string, bool)
- func (c *Config) GetTypeMapping(goType string) (string, bool)
- func (c *Config) SaveConfig(filename string) error
- type ForeignKeyInfo
- type Generator
- type GoField
- type GoStruct
- type ManyToManyInfo
- type Processor
- type ProcessorConfig
- type Relationship
- type RelationshipDetector
- func (rd *RelationshipDetector) DetectRelationships(structs []GoStruct) []Relationship
- func (rd *RelationshipDetector) GetRelationshipsBySource(relationships []Relationship, sourceStruct string) []Relationship
- func (rd *RelationshipDetector) GetRelationshipsByTarget(relationships []Relationship, targetStruct string) []Relationship
- func (rd *RelationshipDetector) GetRelationshipsByType(relationships []Relationship, relType RelationshipType) []Relationship
- type RelationshipType
- type Scanner
- type TableNamingConfig
- type TagInfo
- type TagParser
- type TypeMapper
- type TypeMapping
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
TypeMappings map[string]string `yaml:"type_mappings"`
CustomDefaults map[string]map[string]string `yaml:"custom_defaults"`
TableNaming TableNamingConfig `yaml:"table_naming"`
}
Config represents the configuration for struct2schema conversion
func GetDefaultConfig ¶
func GetDefaultConfig() *Config
GetDefaultConfig returns a default configuration
func LoadConfig ¶
LoadConfig loads configuration from a YAML file
func (*Config) AddCustomDefault ¶
AddCustomDefault adds a custom default value for a database
func (*Config) AddTypeMapping ¶
AddTypeMapping adds a custom type mapping
func (*Config) GetCustomDefault ¶
GetCustomDefault gets a custom default value
func (*Config) GetTypeMapping ¶
GetTypeMapping gets a custom type mapping
func (*Config) SaveConfig ¶
SaveConfig saves configuration to a YAML file
type ForeignKeyInfo ¶
ForeignKeyInfo contains foreign key relationship information
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator handles generation of YAML schema from Go structs
func NewGenerator ¶
func NewGenerator(typeMapper *TypeMapper, tagParser *TagParser, verbose bool) *Generator
NewGenerator creates a new schema generator
func (*Generator) GenerateSchema ¶
func (g *Generator) GenerateSchema(structs []GoStruct, relationships []Relationship) (*types.Schema, error)
GenerateSchema generates a complete schema from Go structs and relationships
type GoField ¶
type GoField struct {
Name string
Type string
Tag string
IsPointer bool
IsSlice bool
IsEmbedded bool
IsExported bool
UnderlyingType string // For custom types
Position token.Pos
}
GoField represents a field within a Go struct
type GoStruct ¶
type GoStruct struct {
Name string
Package string
Fields []GoField
Tags map[string]string // struct-level tags
SourceFile string
Position token.Pos
}
GoStruct represents a parsed Go struct with metadata
type ManyToManyInfo ¶
ManyToManyInfo contains many-to-many relationship information
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor handles the conversion from Go structs to YAML schema
func NewProcessor ¶
func NewProcessor(config ProcessorConfig) (*Processor, error)
NewProcessor creates a new struct2schema processor
type ProcessorConfig ¶
type ProcessorConfig struct {
InputDir string
OutputFile string
ConfigFile string
TargetDB string
DryRun bool
Verbose bool
}
ProcessorConfig holds configuration for the struct2schema processor
type Relationship ¶
type Relationship struct {
Type RelationshipType
SourceStruct string
SourceTable string
SourceField string
TargetStruct string
TargetTable string
TargetField string
JunctionTable string
OnDelete string
OnUpdate string
}
Relationship represents a relationship between two structs/tables
type RelationshipDetector ¶
type RelationshipDetector struct {
// contains filtered or unexported fields
}
RelationshipDetector analyzes Go structs to detect relationships
func NewRelationshipDetector ¶
func NewRelationshipDetector(verbose bool) *RelationshipDetector
NewRelationshipDetector creates a new relationship detector
func (*RelationshipDetector) DetectRelationships ¶
func (rd *RelationshipDetector) DetectRelationships(structs []GoStruct) []Relationship
DetectRelationships analyzes structs to identify relationships between them
func (*RelationshipDetector) GetRelationshipsBySource ¶
func (rd *RelationshipDetector) GetRelationshipsBySource(relationships []Relationship, sourceStruct string) []Relationship
GetRelationshipsBySource filters relationships by source struct
func (*RelationshipDetector) GetRelationshipsByTarget ¶
func (rd *RelationshipDetector) GetRelationshipsByTarget(relationships []Relationship, targetStruct string) []Relationship
GetRelationshipsByTarget filters relationships by target struct
func (*RelationshipDetector) GetRelationshipsByType ¶
func (rd *RelationshipDetector) GetRelationshipsByType(relationships []Relationship, relType RelationshipType) []Relationship
GetRelationshipsByType filters relationships by type
type RelationshipType ¶
type RelationshipType int
RelationshipType represents the type of relationship between structs
const ( RelationshipForeignKey RelationshipType = iota RelationshipManyToMany )
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner handles scanning Go source files and extracting struct definitions
func NewScanner ¶
NewScanner creates a new Go source code scanner
type TableNamingConfig ¶
type TableNamingConfig struct {
ConvertCase string `yaml:"convert_case"` // snake_case, camelCase, PascalCase
Prefix string `yaml:"prefix"`
Suffix string `yaml:"suffix"`
}
TableNamingConfig configures how table names are generated
type TagInfo ¶
type TagInfo struct {
ColumnName string
Type string
Length int
Precision int
Scale int
PrimaryKey bool
Nullable *bool
Default string
AutoCreate bool
AutoUpdate bool
ForeignKey *ForeignKeyInfo
ManyToMany *ManyToManyInfo
Index bool
Unique bool
Ignore bool
}
TagInfo contains parsed information from struct field tags
type TagParser ¶
type TagParser struct {
// contains filtered or unexported fields
}
TagParser handles parsing of struct field tags
func NewTagParser ¶
func NewTagParser() *TagParser
NewTagParser creates a new tag parser with priority ordering
func (*TagParser) GetTableName ¶
GetTableName extracts table name from struct tags
type TypeMapper ¶
type TypeMapper struct {
// contains filtered or unexported fields
}
TypeMapper handles mapping Go types to SQL types
func NewTypeMapper ¶
func NewTypeMapper(configFile, targetDB string) (*TypeMapper, error)
NewTypeMapper creates a new type mapper
func (*TypeMapper) CreateDefaultsForAllDBs ¶
func (tm *TypeMapper) CreateDefaultsForAllDBs() types.Defaults
CreateDefaultsForAllDBs creates default mappings for all supported databases
func (*TypeMapper) GetDefaults ¶
func (tm *TypeMapper) GetDefaults() map[string]string
GetDefaults returns the default values for the target database
type TypeMapping ¶
TypeMapping represents a mapping from Go type to SQL type
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer handles writing schema files and previewing output
func (*Writer) CreateOutputDirectory ¶
CreateOutputDirectory creates the output directory if it doesn't exist
func (*Writer) PreviewSchema ¶
PreviewSchema prints the schema to stdout for dry-run mode
func (*Writer) ValidateOutputPath ¶
ValidateOutputPath validates that the output path is suitable for writing