substancegen

package
v0.0.0-...-559915d Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2019 License: AGPL-3.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 Generate

func Generate(generatorName string, dbType string, db *sql.DB, tableNames []string) bytes.Buffer

Generate is a one stop function to quickly generate code

func GetObjectTypesFunc

func GetObjectTypesFunc(dbType string, db *sql.DB, tableNames []string) map[string]*GenObjectType

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

func StringInSlice(searchVal string, list []string) bool

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

type GenObjectTag map[string][]string

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

Jump to

Keyboard shortcuts

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