Documentation
¶
Index ¶
- Variables
- func AddJSONTagsToProperties(gqlObjectTypes map[string]GenObjectType)
- func Generate(generatorName string, dbType string, db *sql.DB, tableNames []string) bytes.Buffer
- func GetObjectTypesFunc(dbType string, db *sql.DB, tableNames []string) map[string]*GenObjectType
- func Register(pluginName string, pluginInterface GeneratorInterface)
- func ResolveConstraintsFunc(dbType string, constraintDesc []*substance.ColumnConstraint, ...)
- func ResolveForeignRefsFunc(dbType string, relationshipDesc []*substance.ColumnRelationship, ...)
- func ResolveRelationshipsFunc(dbType string, db *sql.DB, tableNames []string, ...) map[string]*GenObjectType
- func SearchForKeyColumnByKeyType(gqlObjectType GenObjectType, searchKeyType string) string
- func StringInSlice(searchVal string, list []string) bool
- type GenObjectProperties
- type GenObjectProperty
- type GenObjectTag
- type GenObjectType
- type GeneratorInterface
Constants ¶
This section is empty.
Variables ¶
var SubstanceGenPlugins = make(map[string]GeneratorInterface)
SubstanceGenPlugins is a map storing a reference to the current plugins Key: pluginName Value: reference to an implementation of SubstanceGenInterface
Functions ¶
func AddJSONTagsToProperties ¶
func AddJSONTagsToProperties(gqlObjectTypes map[string]GenObjectType)
AddJSONTagsToProperties adds json go tags to each property for each object
func GetObjectTypesFunc ¶
GetObjectTypesFunc returns all object definitions as a map given tableNames and db
func Register ¶
func Register(pluginName string, pluginInterface GeneratorInterface)
Register registers a GeneratorInterface plugin
func ResolveConstraintsFunc ¶
func ResolveConstraintsFunc(dbType string, constraintDesc []*substance.ColumnConstraint, gqlObjectTypes map[string]*GenObjectType)
ResolveConstraintsFunc maps assigns key constraints received from ColumnConstraint and appends them to an array for the corresponding property This function also appends gorm tags for primary_key constraints
func ResolveForeignRefsFunc ¶
func ResolveForeignRefsFunc(dbType string, relationshipDesc []*substance.ColumnRelationship, gqlObjectTypes map[string]*GenObjectType)
ResolveForeignRefsFunc resolves the foreign key relationships between objects and inserts properties that have associations This is able to handle many-to-one and one-to-many Untested is the many-to-many assocation using a cross-reference table. For example:
Customer table
ID
NAME
Account table
AccountNumber
Product
CustomerToAccount table
CustomerID <- Foreign Key
AccountNumber <- Foreign Key
RelationshipType
The current expected result is that this would resolve to:
struct Customer type{
...
CustomerToAccount []CustomerToAccountType
}
struct Account type{
...
CustomerToAccount []CustomerToAccountType
}
func ResolveRelationshipsFunc ¶
func ResolveRelationshipsFunc(dbType string, db *sql.DB, tableNames []string, gqlObjectTypes map[string]*GenObjectType) map[string]*GenObjectType
ResolveRelationshipsFunc calls out to multiple functions to orchestrate the resolution of constraints and relationships
func SearchForKeyColumnByKeyType ¶
func SearchForKeyColumnByKeyType(gqlObjectType GenObjectType, searchKeyType string) string
SearchForKeyColumnByKeyType returns a string containing the name of the column of a certain key type
func StringInSlice ¶
StringInSlice returns true if a string is an element within a slice
Types ¶
type GenObjectProperties ¶
type GenObjectProperties map[string]*GenObjectProperty
GenObjectProperties a type defining a map of GenObjectProperty Key: PropertyName Value: GenObjectProperty
type GenObjectProperty ¶
type GenObjectProperty struct {
ScalarName string `json:"scalarName"`
ScalarNameUpper string
ScalarType string `json:"scalarType"`
AltScalarType map[string]string
IsList bool `json:"isList"`
Nullable bool `json:"nullable"`
KeyType []string `json:"keyType"`
Tags GenObjectTag `json:"tags"`
IsObjectType bool `json:"isObjectType"`
}
GenObjectProperty represents a property of an object (aka a field of a struct)
type GenObjectTag ¶
GenObjectTag stores a key value pair of go struct a tag and their value(s) Example: Key: gorm Tabs: {'primary_key','column_name'}
type GenObjectType ¶
type GenObjectType struct {
Name string `json:"objectName"`
SourceTableName string `json:"sourceTableName"`
LowerName string
Properties GenObjectProperties `json:"properties"`
}
GenObjectType represents an object (aka a struct)
type GeneratorInterface ¶
type GeneratorInterface interface {
OutputCodeFunc(dbType string, db *sql.DB, gqlObjectTypes map[string]*GenObjectType) bytes.Buffer
}
GeneratorInterface describes the implementation required to generate code from substance objects