Documentation ¶
Overview ¶
Package codegen generates Go code and is only used in development.
Configuration ¶
If you would like to configure the generation process because of custom EAV and attribute models please create a new file in this folder called `config_*.go` where `*` can be any name. @todo rethink that process and provide a better solution.
You must then use the `init()` function to append new values or change existing values of the configuration variables.
All defined variables in the file `config.go` can be changed. File is documented.
Why the init() function? https://golang.org/doc/effective_go.html#initialization
Index ¶
- Constants
- Variables
- func Camelize(s string) string
- func ColumnsToStructCode(tplData map[string]interface{}, name string, cols Columns, templates ...string) ([]byte, error)
- func ExtractFuncType(s string) (string, error)
- func ExtractImportPath(s string) (string, error)
- func GenerateCode(pkg, tplCode string, data interface{}, addFM template.FuncMap) ([]byte, error)
- func GetTables(db *sql.DB, query string) ([]string, error)
- func LintName(name string) (should string)
- func LogFatal(err error)
- func ParseString(tpl string, data interface{}) string
- func PrepareForTemplate(cols Columns, rows []StringEntities, amm AttributeModelDefMap, ...) []string
- func ReplaceTablePrefix(query string) string
- type AddAttrTables
- type AttributeModelDef
- type AttributeModelDefMap
- type AttributeToStruct
- type AttributeToStructMap
- type Columns
- type EntityType
- type EntityTypeMap
- type StringEntities
- type TableToStruct
- type TableToStructMap
- type TypeCodeValueTable
- type ValueSuffixes
Constants ¶
const ( TableNameSeparator string = "_" TableEavEntityType string = "eav_entity_type" )
const CSImportPath string = "github.com" + PS + "corestoreio" + PS + "csfw"
const PS = string(os.PathSeparator)
Variables ¶
var ( // TableEntityTypeSuffix e.g. for catalog_product_entity, customer_entity TableEntityTypeSuffix = "entity" // TableEntityTypeValueSuffixes defines all possible value type tables which an EAV model can have. TableEntityTypeValueSuffixes = ValueSuffixes{ "datetime", "decimal", "int", "text", "varchar", } )
var ConfigAttributeModel = AttributeModelDefMap{ "catalog/product_attribute_frontend_image": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductFrontendImage().Config(eav.AttributeFrontendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Frontend\\Image": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductFrontendImage().Config(eav.AttributeFrontendIdx({{.AttributeIndex}}))"), "eav/entity_attribute_frontend_datetime": NewAMD("github.com/corestoreio/csfw/eav.AttributeFrontendDatetime().Config(eav.AttributeFrontendIdx({{.AttributeIndex}}))"), "Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\Datetime": NewAMD("github.com/corestoreio/csfw/eav.AttributeFrontendDatetime().Config(eav.AttributeFrontendIdx({{.AttributeIndex}}))"), "catalog/attribute_backend_customlayoutupdate": NewAMD(""), "Magento\\Catalog\\Model\\Attribute\\Backend\\Customlayoutupdate": NewAMD(""), "catalog/category_attribute_backend_image": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategoryBackendImage().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Category\\Attribute\\Backend\\Image": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategoryBackendImage().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/category_attribute_backend_sortby": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategoryBackendSortby().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Category\\Attribute\\Backend\\Sortby": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategoryBackendSortby().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/category_attribute_backend_urlkey": NewAMD(""), "catalog/product_attribute_backend_boolean": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendBoolean().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Boolean": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendBoolean().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Category": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendCategory().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/product_attribute_backend_groupprice": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendGroupPrice().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\GroupPrice": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendGroupPrice().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/product_attribute_backend_media": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendMedia().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Media": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendMedia().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/product_attribute_backend_msrp": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendPrice().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/product_attribute_backend_price": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendPrice().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Price": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendPrice().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/product_attribute_backend_recurring": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendRecurring().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Recurring": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendRecurring().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/product_attribute_backend_sku": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendSku().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Sku": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendSku().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/product_attribute_backend_startdate": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendStartDate().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Startdate": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendStartDate().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Stock": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendStock().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/product_attribute_backend_tierprice": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendTierPrice().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Tierprice": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendTierPrice().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Weight": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductBackendWeight().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "catalog/product_attribute_backend_urlkey": NewAMD(""), "customer/attribute_backend_data_boolean": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendDataBoolean().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Attribute\\Backend\\Data\\Boolean": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendDataBoolean().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "customer/customer_attribute_backend_billing": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendBilling().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Customer\\Attribute\\Backend\\Billing": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendBilling().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "customer/customer_attribute_backend_password": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendPassword().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Customer\\Attribute\\Backend\\Password": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendPassword().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "customer/customer_attribute_backend_shipping": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendShipping().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Customer\\Attribute\\Backend\\Shipping": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendShipping().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "customer/customer_attribute_backend_store": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendStore().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Customer\\Attribute\\Backend\\Store": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendStore().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "customer/customer_attribute_backend_website": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendWebsite().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Customer\\Attribute\\Backend\\Website": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerBackendWebsite().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "customer/entity_address_attribute_backend_region": NewAMD("github.com/corestoreio/csfw/customer/custattr.AddressBackendRegion().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Resource\\Address\\Attribute\\Backend\\Region": NewAMD("github.com/corestoreio/csfw/customer/custattr.AddressBackendRegion().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "customer/entity_address_attribute_backend_street": NewAMD("github.com/corestoreio/csfw/customer/custattr.AddressBackendStreet().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\DefaultBackend": NewAMD("github.com/corestoreio/csfw/eav.AttributeBackendDefaultBackend().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "eav/entity_attribute_backend_datetime": NewAMD("github.com/corestoreio/csfw/eav.AttributeBackendDatetime().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\Datetime": NewAMD("github.com/corestoreio/csfw/eav.AttributeBackendDatetime().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "eav/entity_attribute_backend_time_created": NewAMD("github.com/corestoreio/csfw/eav.AttributeBackendTimeCreated().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\Time\\Created": NewAMD("github.com/corestoreio/csfw/eav.AttributeBackendTimeCreated().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "eav/entity_attribute_backend_time_updated": NewAMD("github.com/corestoreio/csfw/eav.AttributeBackendTimeUpdated().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\Time\\Updated": NewAMD("github.com/corestoreio/csfw/eav.AttributeBackendTimeUpdated().Config(eav.AttributeBackendIdx({{.AttributeIndex}}))"), "bundle/product_attribute_source_price_view": NewAMD("github.com/corestoreio/csfw/bundle.AttributeSourcePriceView().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Bundle\\Model\\Product\\Attribute\\Source\\Price\\View": NewAMD("github.com/corestoreio/csfw/bundle.AttributeSourcePriceView().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\CatalogInventory\\Model\\Source\\Stock": NewAMD("github.com/corestoreio/csfw/cataloginventory.AttributeSourceStock().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "catalog/category_attribute_source_layout": NewAMD(""), "Magento\\Catalog\\Model\\Category\\Attribute\\Source\\Layout": NewAMD(""), "catalog/category_attribute_source_mode": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategorySourceMode().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Category\\Attribute\\Source\\Mode": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategorySourceMode().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "catalog/category_attribute_source_page": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategorySourcePage().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Category\\Attribute\\Source\\Page": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategorySourcePage().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "catalog/category_attribute_source_sortby": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategorySourceSortby().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Category\\Attribute\\Source\\Sortby": NewAMD("github.com/corestoreio/csfw/catalog/catattr.CategorySourceSortby().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "catalog/entity_product_attribute_design_options_container": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceDesignOptionsContainer().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Entity\\Product\\Attribute\\Design\\Options\\Container": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceDesignOptionsContainer().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "catalog/product_attribute_source_countryofmanufacture": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceCountryOfManufacture().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Countryofmanufacture": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceCountryOfManufacture().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "catalog/product_attribute_source_layout": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceLayout().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Layout": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceLayout().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Status": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceStatus().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "catalog/product_attribute_source_msrp_type_enabled": NewAMD(""), "catalog/product_attribute_source_msrp_type_price": NewAMD("github.com/corestoreio/csfw/msrp.NewAttributeSourcePrice().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Msrp\\Model\\Product\\Attribute\\Source\\Type\\Price": NewAMD("github.com/corestoreio/csfw/msrp.NewAttributeSourcePrice().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "catalog/product_status": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceStatus().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "catalog/product_visibility": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceVisibility().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Visibility": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceVisibility().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Visibility": NewAMD("github.com/corestoreio/csfw/catalog/catattr.ProductSourceVisibility().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "core/design_source_design": NewAMD(""), "customer/customer_attribute_source_group": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerSourceGroup().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Customer\\Attribute\\Source\\Group": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerSourceGroup().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "customer/customer_attribute_source_store": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerSourceStore().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Customer\\Attribute\\Source\\Store": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerSourceStore().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "customer/customer_attribute_source_website": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerSourceWebsite().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Customer\\Attribute\\Source\\Website": NewAMD("github.com/corestoreio/csfw/customer/custattr.CustomerSourceWebsite().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "customer/entity_address_attribute_source_country": NewAMD("github.com/corestoreio/csfw/customer/custattr.AddressSourceCountry().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Resource\\Address\\Attribute\\Source\\Country": NewAMD("github.com/corestoreio/csfw/customer/custattr.AddressSourceCountry().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "customer/entity_address_attribute_source_region": NewAMD("github.com/corestoreio/csfw/customer/custattr.AddressSourceRegion().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Resource\\Address\\Attribute\\Source\\Region": NewAMD("github.com/corestoreio/csfw/customer/custattr.AddressSourceRegion().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "eav/entity_attribute_source_boolean": NewAMD("github.com/corestoreio/csfw/eav.AttributeSourceBoolean().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Boolean": NewAMD("github.com/corestoreio/csfw/eav.AttributeSourceBoolean().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "eav/entity_attribute_source_table": NewAMD("github.com/corestoreio/csfw/eav.AttributeSourceTable().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table": NewAMD("github.com/corestoreio/csfw/eav.AttributeSourceTable().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "tax/class_source_product": NewAMD("github.com/corestoreio/csfw/tax.AttributeSourceTaxClassProduct().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Tax\\Model\\TaxClass\\Source\\Product": NewAMD("github.com/corestoreio/csfw/tax.AttributeSourceTaxClassProduct().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Tax\\Model\\TaxClass\\Source\\Customer": NewAMD("github.com/corestoreio/csfw/tax.AttributeSourceTaxClassCustomer().Config(eav.AttributeSourceIdx({{.AttributeIndex}}))"), "Magento\\Theme\\Model\\Theme\\Source\\Theme": NewAMD(""), "customer/attribute_data_postcode": NewAMD("github.com/corestoreio/csfw/customer/custattr.AddressDataPostcode().Config(eav.AttributeDataIdx({{.AttributeIndex}}))"), "Magento\\Customer\\Model\\Attribute\\Data\\Postcode": NewAMD("github.com/corestoreio/csfw/customer/custattr.AddressDataPostcode().Config(eav.AttributeDataIdx({{.AttributeIndex}}))"), }
ConfigAttributeModel contains default configuration. Use the file config_user.go with the func init() to change/extend it.
var ConfigEntityType = EntityTypeMap{ "customer": &EntityType{ EntityModel: "github.com/corestoreio/csfw/customer.Customer()", AttributeModel: "github.com/corestoreio/csfw/customer/custattr.HandlerCustomer({{.EntityTypeID}})", EntityTable: "github.com/corestoreio/csfw/customer.Customer()", IncrementModel: "github.com/corestoreio/csfw/customer.Customer()", AdditionalAttributeTable: "github.com/corestoreio/csfw/customer.Customer()", EntityAttributeCollection: "github.com/corestoreio/csfw/customer/custattr.HandlerCustomer({{.EntityTypeID}})", TempAdditionalAttributeTable: "{{tableprefix}}customer_eav_attribute", TempAdditionalAttributeTableWebsite: "{{tableprefix}}customer_eav_attribute_website", AttributeCoreColumns: customerAttributeCoreColumns, }, "customer_address": &EntityType{ EntityModel: "github.com/corestoreio/csfw/customer.Address()", AttributeModel: "github.com/corestoreio/csfw/customer/custattr.HandlerAddress({{.EntityTypeID}})", EntityTable: "github.com/corestoreio/csfw/customer.Address()", AdditionalAttributeTable: "github.com/corestoreio/csfw/customer.Address()", EntityAttributeCollection: "github.com/corestoreio/csfw/customer/custattr.HandlerAddress({{.EntityTypeID}})", TempAdditionalAttributeTable: "{{tableprefix}}customer_eav_attribute", TempAdditionalAttributeTableWebsite: "{{tableprefix}}customer_eav_attribute_website", AttributeCoreColumns: customerAttributeCoreColumns, }, "catalog_category": &EntityType{ EntityModel: "github.com/corestoreio/csfw/catalog.Category()", AttributeModel: "github.com/corestoreio/csfw/catalog/catattr.HandlerCategory({{.EntityTypeID}})", EntityTable: "github.com/corestoreio/csfw/catalog.Category()", AdditionalAttributeTable: "github.com/corestoreio/csfw/catalog.Category()", EntityAttributeCollection: "github.com/corestoreio/csfw/catalog/catattr.HandlerCategory({{.EntityTypeID}})", TempAdditionalAttributeTable: "{{tableprefix}}catalog_eav_attribute", AttributeCoreColumns: catalogAttributeCoreColumns, }, "catalog_product": &EntityType{ EntityModel: "github.com/corestoreio/csfw/catalog.Product()", AttributeModel: "github.com/corestoreio/csfw/catalog/catattr.HandlerProduct({{.EntityTypeID}})", EntityTable: "github.com/corestoreio/csfw/catalog.Product()", AdditionalAttributeTable: "github.com/corestoreio/csfw/catalog.Product()", EntityAttributeCollection: "github.com/corestoreio/csfw/catalog/catattr.HandlerProduct({{.EntityTypeID}})", TempAdditionalAttributeTable: "{{tableprefix}}catalog_eav_attribute", AttributeCoreColumns: catalogAttributeCoreColumns, }, }
ConfigEntityType contains default configuration to materialize the entity types. Use the file config_user.go with the func init() to change/extend it. Needed in materializeEntityType()
var ConfigMaterializationAttributes = AttributeToStructMap{ "customer": &AttributeToStruct{ AttrPkgImp: "github.com/corestoreio/csfw/customer/custattr", FuncCollection: "SetCustomerCollection", FuncGetter: "SetCustomerGetter", AttrStruct: "Customer", MyStruct: "", Package: "testgen", OutputFile: myPath + "testgen" + PS + "generated_customer_attribute_test.go", }, "customer_address": &AttributeToStruct{ AttrPkgImp: "github.com/corestoreio/csfw/customer/custattr", FuncCollection: "SetAddressCollection", FuncGetter: "SetAddressGetter", AttrStruct: "Customer", MyStruct: "", Package: "testgen", OutputFile: myPath + "testgen" + PS + "generated_address_attribute_test.go", }, "catalog_product": &AttributeToStruct{ AttrPkgImp: "github.com/corestoreio/csfw/catalog/catattr", FuncCollection: "SetProductCollection", FuncGetter: "SetProductGetter", AttrStruct: "Catalog", MyStruct: "", Package: "testgen", OutputFile: myPath + "testgen" + PS + "generated_product_attribute_test.go", }, "catalog_category": &AttributeToStruct{ AttrPkgImp: "github.com/corestoreio/csfw/catalog/catattr", FuncCollection: "SetCategoryCollection", FuncGetter: "SetCategoryGetter", AttrStruct: "Catalog", MyStruct: "", Package: "testgen", OutputFile: myPath + "testgen" + PS + "generated_category_attribute_test.go", }, }
ConfigMaterializationAttributes contains the configuration to materialize all attributes for the defined EAV entity types.
var ConfigMaterializationEntityType = &TableToStruct{ Package: "testgen", OutputFile: myPath + "testgen" + PS + "generated_entity_type_test.go", }
ConfigMaterializationEntityType configuration for materializeEntityType() to write the materialized entity types into a folder. Other fields of the struct TableToStruct are ignored. Use the file config_user.go with the func init() to change/extend it.
var ConfigTableToStruct = TableToStructMap{ "config": &TableToStruct{ Package: "config", OutputFile: myPath + "config" + PS + "generated_tables.go", SQLQuery: `SHOW TABLES LIKE "{{tableprefix}}core_config_data"`, EntityTypeCodes: nil, }, "directory": &TableToStruct{ Package: "directory", OutputFile: myPath + "directory" + PS + "generated_tables.go", SQLQuery: `SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME LIKE '{{tableprefix}}directory%' GROUP BY TABLE_NAME;`, EntityTypeCodes: nil, }, "eav": &TableToStruct{ Package: "eav", OutputFile: myPath + "eav" + PS + "generated_tables.go", SQLQuery: `SHOW TABLES LIKE "{{tableprefix}}eav%"`, EntityTypeCodes: nil, }, "store": &TableToStruct{ Package: "store", OutputFile: myPath + "store" + PS + "generated_tables.go", SQLQuery: `SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME IN ( '{{tableprefix}}core_store','{{tableprefix}}store', '{{tableprefix}}core_store_group','{{tableprefix}}store_group', '{{tableprefix}}core_website','{{tableprefix}}store_website' ) GROUP BY TABLE_NAME;`, EntityTypeCodes: nil, }, "catalog": &TableToStruct{ Package: "catalog", OutputFile: myPath + "catalog" + PS + "generated_tables.go", SQLQuery: `SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND (TABLE_NAME LIKE '{{tableprefix}}catalog\_%' OR TABLE_NAME LIKE '{{tableprefix}}catalogindex%' ) AND TABLE_NAME NOT LIKE '{{tableprefix}}%bundle%' AND TABLE_NAME NOT LIKE '{{tableprefix}}%\_flat\_%' GROUP BY TABLE_NAME;`, EntityTypeCodes: []string{"catalog_category", "catalog_product"}, }, "customer": &TableToStruct{ Package: "customer", OutputFile: myPath + "customer" + PS + "generated_tables.go", SQLQuery: `SHOW TABLES LIKE "{{tableprefix}}customer%"`, EntityTypeCodes: []string{"customer", "customer_address"}, }, }
ConfigTableToStruct contains default configuration. Use the file config_user.go with the func init() to change/extend it.
var (
Copyright = []byte(`// Copyright 2015 CoreStore Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
`)
)
var ( // EAVAttributeCoreColumns defines the minimal required columns for table eav_attribute. // Developers can extend the table eav_attribute with additional columns but these additional // columns with its method receivers must get generated in the attribute materialize function. // These core columns are already defined below. EAVAttributeCoreColumns = utils.StringSlice{ "attribute_id", "entity_type_id", "attribute_code", "attribute_model", "backend_model", "backend_type", "backend_table", "frontend_model", "frontend_input", "frontend_label", "frontend_class", "source_model", "is_required", "is_user_defined", "default_value", "is_unique", "note", } )
var EavAttributeColumnNameToInterface = map[string]string{
"backend_model": "eav.AttributeBackendModeller",
"frontend_model": "eav.AttributeFrontendModeller",
"source_model": "eav.AttributeSourceModeller",
"frontend_input_renderer": "eav.FrontendInputRendererIFace",
"data_model": "eav.AttributeDataModeller",
}
EavAttributeColumnNameToInterface mapping column name to Go interface name. Do not add attribute_model as this column is unused in Magento 1+2. If you have custom column then add it here.
var TableMapMagento1To2 = map[string]string{
"core_cache": "cache",
"core_cache_tag": "cache_tag",
"core_config_data": "core_config_data",
"core_design_change": "design_change",
"core_directory_storage": "media_storage_directory_storage",
"core_email_template": "email_template",
"core_file_storage": "media_storage_file_storage",
"core_flag": "flag",
"core_layout_link": "layout_link",
"core_layout_update": "layout_update",
"core_resource": "setup_module",
"core_session": "session",
"core_store": "store",
"core_store_group": "store_group",
"core_variable": "variable",
"core_variable_value": "variable_value",
"core_website": "store_website",
}
TableMapMagento1To2 provides mapping between table names in tableToStruct. If a table name is in the map then the struct name will be rewritten to that new Magneto2 compatible table name. Do not change entries in this map except you can always append. @see Magento2 dev/tools/Magento/Tools/Migration/factory_table_names/replace_ce.php
var TablePrefix string
TablePrefix defines the global table name prefix. See Magento install tool. Can be overridden via func init()
Functions ¶
func Camelize ¶
Camelize transforms from snake case to camelCase e.g. catalog_product_id to CatalogProductID. Also removes quotes.
func ColumnsToStructCode ¶
func ColumnsToStructCode(tplData map[string]interface{}, name string, cols Columns, templates ...string) ([]byte, error)
ColumnsToStructCode generates Go code from a name and a slice of columns. Make sure that the fields GoType and GoName has been setup If you don't like the template you can provide your own template as 3rd to n-th argument.
func ExtractFuncType ¶
ExtractFuncType extracts from an extended import path with a function or type call the function or type call. github.com/corestoreio/csfw/customer.Customer() would become customer.Customer()
func ExtractImportPath ¶
ExtractImportPath extracts from an extended import path with a function or type call the import path. github.com/corestoreio/csfw/customer.Customer() would become github.com/corestoreio/csfw/customer
func GenerateCode ¶
GenerateCode uses text/template for create Go code. package name pkg will also be used to remove stutter in variable names.
func GetTables ¶
GetTables returns all tables from a database which starts with a prefix. % wild card will be added automatically.
func LintName ¶
LintName returns a different name if it should be different. @see github.com/golang/lint/lint.go
func LogFatal ¶
func LogFatal(err error)
LogFatal logs an error as fatal with printed location and exists the program.
func ParseString ¶
ParseString text/template for a string. Fails on error.
func PrepareForTemplate ¶
func PrepareForTemplate(cols Columns, rows []StringEntities, amm AttributeModelDefMap, targetPkg string) []string
PrepareForTemplate uses the Columns slice to transform the rows so that correct Go code can be printed. int/Float values won't be touched. Bools or IntBools will be converted to true/false. Strings will be quoted. And if there is an entry in the AttributeModelMap then the Go code from the map will be used. Returns a slice containing all the import paths. Import paths which are equal to pkg will be filtered out.
func ReplaceTablePrefix ¶
ReplaceTablePrefix replaces the {{tableprefix}} place holder with the configure real TablePrefix TablePrefix can be set via init() statement in config_user.go
Types ¶
type AddAttrTables ¶
type AddAttrTables struct { EntityTypeCode string // contains filtered or unexported fields }
Depends on generated code from tableToStruct.
func NewAddAttrTables ¶
func NewAddAttrTables(db *sql.DB, code string) *AddAttrTables
Implements interface eav.EntityTypeAdditionalAttributeTabler
func (*AddAttrTables) TableAdditionalAttribute ¶
func (aa *AddAttrTables) TableAdditionalAttribute() (*csdb.TableStructure, error)
Implements interface eav.EntityTypeAdditionalAttributeTabler
func (*AddAttrTables) TableEavWebsite ¶
func (aa *AddAttrTables) TableEavWebsite() (*csdb.TableStructure, error)
Implements interface eav.EntityTypeAdditionalAttributeTabler
type AttributeModelDef ¶
type AttributeModelDef struct { // GoFunc is a function string which implements, when later executed, one of the n interfaces // for (backend|frontend|source|data)_model. The GoFunc expects the fully qualified import path to the // final method, e.g.: github.com/corestoreio/csfw/customer.Customer() GoFunc string // contains filtered or unexported fields }
AttributeModelDef defines which Go type/func has which import path
func NewAMD ¶
func NewAMD(GoFuncWithPath string) *AttributeModelDef
NewAMD NewAttributeModelDef NewAttributeModelDef creates a new attribute model definition
func (*AttributeModelDef) Func ¶
func (d *AttributeModelDef) Func() string
Func extracts the function
func (*AttributeModelDef) Import ¶
func (d *AttributeModelDef) Import() string
Import extracts the import path
type AttributeModelDefMap ¶
type AttributeModelDefMap map[string]*AttributeModelDef
AttributeModelDefMap contains data to map the three eav_attribute columns (backend | frontend | source | data)_model to the correct Go function and package. It contains mappings for Magento 1 & 2. A developer has the option to to change/extend the value using the file config_user.go with the init() func. Def for Definition to avoid a naming conflict :-( Better name?
type AttributeToStruct ¶
type AttributeToStruct struct { // AttrPkgImp defines the package import path to use: possible ATM: custattr and catattr and your custom // EAV package. AttrPkgImp string // FuncCollection specifies the name of the SetAttributeCollection function name within the AttrPkgImp. FuncCollection string // FuncGetter specifies the name of the SetAttributeGetter function name within the AttrPkgImp. FuncGetter string // Package defines the name of the target package, must be external. Default is {{.AttrPkgImp}}_test but // for your project you must provide your package name. Package string // AttrStruct defines the name of the attribute struct in an EAV package like catattr or custattr. // This struct will have the prefix of AttrPkgImp and will be embedded the newly generated struct // which wraps additional project specific columns. AttrStruct string // MyStruct is the optional name of your struct from your package. @todo review MyStruct string // OutputFile specifies the full path where to write the newly generated code OutputFile string }
AttributeToStruct contains the configuration to materialize all attributes belonging to one EAV model
type AttributeToStructMap ¶
type AttributeToStructMap map[string]*AttributeToStruct
AttributeToStructMap is a map which points to the AttributeToStruct configuration. Default entries can be overriden by your configuration.
type Columns ¶
type Columns []*column
Columns contains a slice to pointer column types. A column has the fields: Field, Type, Null, Key, Default and Extra of type sql.NullString and GoType, GoName of type string.
func GetColumns ¶
GetColumns returns all columns from a table. It discards the column entity_type_id from some entity tables.
func SQLQueryToColumns ¶
SQLQueryToColumns generates from a SQL query an array containing all the column properties. dbSelect argument can be nil but then you must provide query strings which will be joined to the final query.
func (Columns) GetFieldNames ¶
GetFieldNames returns from a Columns slice the column names. If pkOnly is true then only the primary key columns will be returned.
func (Columns) MapSQLToGoDBRType ¶
MapSQLToGoDBRType takes a slice of Columns and sets the fields GoType and GoName to the correct value to create a Go struct. These generated structs are mainly used in a result from a SQL query. The field GoType will contain dbr.Null* types.
func (Columns) MapSQLToGoType ¶
MapSQLToGoType maps a column to a GoType. This GoType is not a dbr.Null* struct. This function only updates the fields GoType and GoName of column struct. The 2nd argument ifm interface map replaces the primitive type with an interface type, the column name must be found as a key in the map.
type EntityType ¶
type EntityType struct { // EntityModel Go type which implements eav.EntityTypeModeller. // Will be used as template so you can access the current entity_type from the database. EntityModel string // AttributeModel Go type which implements eav.EntityTypeAttributeModeller // Will be used as template so you can access the current entity_type from the database. AttributeModel string // EntityTable Go type which implements eav.EntityTypeTabler // Will be used as template so you can access the current entity_type from the database. EntityTable string // IncrementModel Go type which implements eav.EntityTypeIncrementModeller // Will be used as template so you can access the current entity_type from the database. IncrementModel string // AdditionalAttributeTable Go type which implements eav.EntityTypeAdditionalAttributeTabler // Will be used as template so you can access the current entity_type from the database. AdditionalAttributeTable string // EntityAttributeCollection Go type which implements eav.EntityTypeAttributeCollectioner // Will be used as template so you can access the current entity_type from the database. EntityAttributeCollection string // TempAdditionalAttributeTable string which defines the existing table name // and specifies more attribute configuration options besides eav_attribute table. // This table name is used in a DB query while materializing attribute configuration to Go code. // Mage_Eav_Model_Resource_Attribute_Collection::_initSelect() TempAdditionalAttributeTable string // TempAdditionalAttributeTableWebsite string which defines the existing table name // and stores website-dependent attribute parameters. // If an EAV model doesn't demand this functionality, let this string empty. // This table name is used in a DB query while materializing attribute configuration to Go code. // Mage_Customer_Model_Resource_Attribute::_getEavWebsiteTable() // Mage_Eav_Model_Resource_Attribute_Collection::_getEavWebsiteTable() TempAdditionalAttributeTableWebsite string AttributeCoreColumns utils.StringSlice }
EntityType is configuration struct which maps the PHP classes to Go types, interfaces and table names. Each struct field has a special import path with function to make easier to specify different packages
type EntityTypeMap ¶
type EntityTypeMap map[string]*EntityType
EntityTypeMap uses a string key as easy identifier, which must also exists in the table eav_EntityTable, for maybe later manipulation in config_user.go and as value a pointer to a EntityType struct. Developers can later use the init() func in config_user.go to change the value of variable ConfigEntityType. The values of EntityType will be uses for materialization in Go code of the eav_entity_type table data.
func (EntityTypeMap) Keys ¶
func (m EntityTypeMap) Keys() []string
Keys returns all keys from a EntityTypeMap
type StringEntities ¶
StringEntities contains as key the column name and value the string value from the column. sql.RawBytes are converted to a string.
func LoadStringEntities ¶
func LoadStringEntities(db *sql.DB, dbSelect *dbr.SelectBuilder, query ...string) ([]StringEntities, error)
LoadStringEntities executes a SELECT query and returns a slice containing columns names and its string values
type TableToStruct ¶
type TableToStruct struct { // Package defines the name of the target package Package string // OutputFile specifies the full path where to write the newly generated code OutputFile string // QueryString SQL query to filter all the tables which you desire, e.g. SHOW TABLES LIKE 'catalog\_%' // This query must specify all tables you need for a package. SQLQuery string // EntityTypeCodes If provided then eav_entity_type.value_table_prefix will be evaluated for further tables. EntityTypeCodes []string }
type TableToStructMap ¶
type TableToStructMap map[string]*TableToStruct
TableToStructMap uses a string key as easy identifier for maybe later manipulation in config_user.go and a pointer to a TableToStruct struct. Developers can later use the init() func in config_user.go to change the value of variable ConfigTableToStruct.
type TypeCodeValueTable ¶
TypeCodeValueTable 2 dimensional map. 1. key entity_type_code 2. key table name => value ValueSuffix
func GetEavValueTables ¶
func GetEavValueTables(dbrConn *dbr.Connection, entityTypeCodes []string) (TypeCodeValueTable, error)
GetEavValueTables returns a map of all custom and default EAV value tables for entity type codes. Despite value_table_prefix can have in Magento a different table name we treat it here as the table name itself. Not thread safe.
func (TypeCodeValueTable) Empty ¶
func (m TypeCodeValueTable) Empty() bool
Empty checks if the map is empty or has an empty "" entry.
type ValueSuffixes ¶
type ValueSuffixes []string
ValueSuffixes contains the suffixes for an entity type table, e.g. datetime, decimal, int ... then a table value name would be catalog_product_entity_datetime, catalog_product_entity_decimal, ...
func (ValueSuffixes) String ¶
func (vs ValueSuffixes) String() string
String joins the slice of strings separated by a comma. Only for debug.
Directories ¶
Path | Synopsis |
---|---|
Package csMake replaces the Makefile and is only used via go:generate.
|
Package csMake replaces the Makefile and is only used via go:generate. |
package main materializes attributes, sets, groups, entity types, stores, websites, etc.
|
package main materializes attributes, sets, groups, entity types, stores, websites, etc. |
package main generates Go structs and slices from SQL tables.
|
package main generates Go structs and slices from SQL tables. |