gorma: github.com/goadesign/gorma Index | Files | Directories

package gorma

import "github.com/goadesign/gorma"

Package gorma is a plugin generator for Goa (http://goa.design). See the documentation in the `dsl` package for details on how to create a definition for your API.

The `example` folder contains an example Goa design package. The `models.go` file is the Gorma definition, which is responsible for generating all the files in the `example\models` folder.

See specific documentation in the `dsl` package.

Index

Package Files

buildsources.go definitions.go doc.go generator.go init.go manytomany.go mapdefinition.go relationalfield.go relationalmodel.go relationalstore.go storagegroup.go validate.go writers.go

Constants

const (
    // StorageGroup is the constant string used as the index in the
    // GormaConstructs map
    StorageGroup = "storagegroup"
    // MySQL is the StorageType for MySQL databases
    MySQL RelationalStorageType = "mysql"
    // Postgres is the StorageType for Postgres
    Postgres RelationalStorageType = "postgres"
    // SQLite3 is the StorageType for SQLite3 databases
    SQLite3 RelationalStorageType = "sqlite3"
    // None is For tests
    None RelationalStorageType = ""
    // Boolean is a bool field type
    Boolean FieldType = "bool"
    // Integer is an integer field type
    Integer FieldType = "integer"
    // BigInteger is a large integer field type
    BigInteger FieldType = "biginteger"
    // AutoInteger is not implemented
    AutoInteger FieldType = "auto_integer"
    // AutoBigInteger is not implemented
    AutoBigInteger FieldType = "auto_biginteger"
    // Decimal is a float field type
    Decimal FieldType = "decimal"
    // BigDecimal is a large float field type
    BigDecimal FieldType = "bigdecimal"
    // String is a varchar field type
    String FieldType = "string"
    // Text is a large string field type
    Text FieldType = "text"
    // UUID is not implemented yet
    UUID FieldType = "uuid"
    // Timestamp is a date/time field in the database
    Timestamp FieldType = "timestamp"
    // NullableTimestamp is a timestamp that may not be
    // populated.  Fields with no value will be null in the database
    NullableTimestamp FieldType = "nulltimestamp"
    // NotFound is used internally
    NotFound FieldType = "notfound"
    // HasOne is used internally
    HasOne FieldType = "hasone"
    // HasOneKey is used internally
    HasOneKey FieldType = "hasonekey"
    // HasMany is used internally
    HasMany FieldType = "hasmany"
    // HasManyKey is used internally
    HasManyKey FieldType = "hasmanykey"
    // Many2Many is used internally
    Many2Many FieldType = "many2many"
    // Many2ManyKey is used internally
    Many2ManyKey FieldType = "many2manykey"
    // BelongsTo is used internally
    BelongsTo FieldType = "belongsto"
)

func Generate Uses

func Generate() (files []string, err error)

Generate is the generator entry point called by the meta generator.

type BuildSource Uses

type BuildSource struct {
    dslengine.Definition
    DefinitionDSL   func()
    Parent          *RelationalModelDefinition
    BuildSourceName string
}

BuildSource stores the BuildsFrom sources for parsing.

func NewBuildSource Uses

func NewBuildSource() *BuildSource

NewBuildSource returns an initialized BuildSource

func (*BuildSource) Context Uses

func (f *BuildSource) Context() string

Context returns the generic definition name used in error messages.

func (*BuildSource) DSL Uses

func (f *BuildSource) DSL() func()

DSL returns this object's DSL.

type BuildSourceIterator Uses

type BuildSourceIterator func(m *BuildSource) error

BuildSourceIterator is a function that iterates over Fields in a RelationalModel.

type FieldIterator Uses

type FieldIterator func(m *RelationalFieldDefinition) error

FieldIterator is a function that iterates over Fields in a RelationalModel.

type FieldType Uses

type FieldType string

FieldType is the storage data type for a database field.

type Generator Uses

type Generator struct {
    // contains filtered or unexported fields
}

Generator is the application code generator.

func (*Generator) Cleanup Uses

func (g *Generator) Cleanup()

Cleanup removes the entire "app" directory if it was created by this generator.

func (*Generator) Generate Uses

func (g *Generator) Generate(api *design.APIDefinition) (_ []string, err error)

Generate the application code, implement codegen.Generator.

type ManyToManyDefinition Uses

type ManyToManyDefinition struct {
    dslengine.Definition
    DefinitionDSL    func()
    Left             *RelationalModelDefinition
    Right            *RelationalModelDefinition
    RelationshipName string // ??
    DatabaseField    string
}

ManyToManyDefinition stores information about a ManyToMany relationship between two domain objects.

func (*ManyToManyDefinition) LeftName Uses

func (m *ManyToManyDefinition) LeftName() string

LeftName returns the name of the "owner" of the m2m relationship.

func (*ManyToManyDefinition) LeftNamePlural Uses

func (m *ManyToManyDefinition) LeftNamePlural() string

LeftNamePlural returns the pluralized version of the "owner" of the m2m relationship.

func (*ManyToManyDefinition) LowerLeftName Uses

func (m *ManyToManyDefinition) LowerLeftName() string

LowerLeftName returns the lower case name of the "owner" of the m2m relationship.

func (*ManyToManyDefinition) LowerRightName Uses

func (m *ManyToManyDefinition) LowerRightName() string

LowerRightName returns the name of the "child" of the m2m relationship.

func (*ManyToManyDefinition) RightName Uses

func (m *ManyToManyDefinition) RightName() string

RightName returns the name of the "child" of the m2m relationship.

func (*ManyToManyDefinition) RightNamePlural Uses

func (m *ManyToManyDefinition) RightNamePlural() string

RightNamePlural returns the pluralized version of the "child" of the m2m relationship.

type MapDefinition Uses

type MapDefinition struct {
    RemoteType  *design.UserTypeDefinition
    RemoteField string
}

MapDefinition represents field mapping to and from Gorma models.

func NewMapDefinition Uses

func NewMapDefinition() *MapDefinition

NewMapDefinition returns an initialized MapDefinition.

type MediaTypeAdapterDefinition Uses

type MediaTypeAdapterDefinition struct {
    dslengine.Definition
    DefinitionDSL func()
    Name          string
    Description   string
    Left          *design.MediaTypeDefinition
    Right         *RelationalModelDefinition
}

MediaTypeAdapterDefinition represents the transformation of a Goa media type into a Gorma Model.

Unimplemented at this time.

type ModelIterator Uses

type ModelIterator func(m *RelationalModelDefinition) error

ModelIterator is a function that iterates over Models in a RelationalStore.

type PayloadAdapterDefinition Uses

type PayloadAdapterDefinition struct {
    dslengine.Definition
    DefinitionDSL func()
    Name          string
    Description   string
    Left          *design.UserTypeDefinition
    Right         *RelationalModelDefinition
}

PayloadAdapterDefinition represents the transformation of a Goa Payload (which is really a UserTypeDefinition) into a Gorma model.

Unimplemented at this time.

type RelationalFieldDefinition Uses

type RelationalFieldDefinition struct {
    dslengine.Definition
    DefinitionDSL func()
    Parent        *RelationalModelDefinition

    FieldName         string
    TableName         string
    Datatype          FieldType
    SQLTag            string
    DatabaseFieldName string // gorm:column
    Description       string
    Nullable          bool
    PrimaryKey        bool
    Timestamp         bool
    Size              int // string field size
    BelongsTo         string
    HasOne            string
    HasMany           string
    Many2Many         string
    Mappings          map[string]*MapDefinition
    // contains filtered or unexported fields
}

RelationalFieldDefinition represents a field in a relational database.

func NewRelationalFieldDefinition Uses

func NewRelationalFieldDefinition() *RelationalFieldDefinition

NewRelationalFieldDefinition returns an initialized RelationalFieldDefinition.

func (*RelationalFieldDefinition) Attribute Uses

func (f *RelationalFieldDefinition) Attribute() *design.AttributeDefinition

Attribute implements the Container interface of the goa Attribute model.

func (RelationalFieldDefinition) Children Uses

func (f RelationalFieldDefinition) Children() []dslengine.Definition

Children returns a slice of this objects children.

func (*RelationalFieldDefinition) Context Uses

func (f *RelationalFieldDefinition) Context() string

Context returns the generic definition name used in error messages.

func (*RelationalFieldDefinition) DSL Uses

func (f *RelationalFieldDefinition) DSL() func()

DSL returns this object's DSL.

func (*RelationalFieldDefinition) FieldDefinition Uses

func (f *RelationalFieldDefinition) FieldDefinition() string

FieldDefinition returns the field's struct definition.

func (*RelationalFieldDefinition) LowerName Uses

func (f *RelationalFieldDefinition) LowerName() string

LowerName returns the field name as a lowercase string.

func (*RelationalFieldDefinition) Tags Uses

func (f *RelationalFieldDefinition) Tags() string

Tags returns the sql and gorm struct tags for the Definition.

func (*RelationalFieldDefinition) Underscore Uses

func (f *RelationalFieldDefinition) Underscore() string

Underscore returns the field name as a lowercase string in snake case.

func (*RelationalFieldDefinition) Validate Uses

func (field *RelationalFieldDefinition) Validate() *dslengine.ValidationErrors

Validate tests whether the RelationalField definition is consistent.

type RelationalModelDefinition Uses

type RelationalModelDefinition struct {
    dslengine.Definition
    *design.UserTypeDefinition
    DefinitionDSL    func()
    ModelName        string
    Description      string
    GoaType          *design.MediaTypeDefinition
    Parent           *RelationalStoreDefinition
    BuiltFrom        map[string]*design.UserTypeDefinition
    BuildSources     []*BuildSource
    RenderTo         map[string]*design.MediaTypeDefinition
    BelongsTo        map[string]*RelationalModelDefinition
    HasMany          map[string]*RelationalModelDefinition
    HasOne           map[string]*RelationalModelDefinition
    ManyToMany       map[string]*ManyToManyDefinition
    Alias            string // gorm:tablename
    Cached           bool
    CacheDuration    int
    Roler            bool
    DynamicTableName bool
    SQLTag           string
    RelationalFields map[string]*RelationalFieldDefinition
    PrimaryKeys      []*RelationalFieldDefinition
    // contains filtered or unexported fields
}

RelationalModelDefinition implements the storage of a domain model into a table in a relational database.

func NewRelationalModelDefinition Uses

func NewRelationalModelDefinition() *RelationalModelDefinition

NewRelationalModelDefinition returns an initialized RelationalModelDefinition.

func (*RelationalModelDefinition) Attribute Uses

func (f *RelationalModelDefinition) Attribute() *design.AttributeDefinition

Attribute implements the Container interface of goa.

func (RelationalModelDefinition) Children Uses

func (f RelationalModelDefinition) Children() []dslengine.Definition

Children returns a slice of this objects children.

func (*RelationalModelDefinition) Context Uses

func (f *RelationalModelDefinition) Context() string

Context returns the generic definition name used in error messages.

func (*RelationalModelDefinition) DSL Uses

func (f *RelationalModelDefinition) DSL() func()

DSL returns this object's DSL.

func (*RelationalModelDefinition) IterateBuildSources Uses

func (f *RelationalModelDefinition) IterateBuildSources(it BuildSourceIterator) error

IterateBuildSources runs an iterator function once per Model in the Store's model list.

func (*RelationalModelDefinition) IterateFields Uses

func (f *RelationalModelDefinition) IterateFields(it FieldIterator) error

IterateFields returns an iterator function useful for iterating through this model's field list.

func (*RelationalModelDefinition) LowerName Uses

func (f *RelationalModelDefinition) LowerName() string

LowerName returns the model name as a lowercase string.

func (*RelationalModelDefinition) PKAttributes Uses

func (f *RelationalModelDefinition) PKAttributes() string

PKAttributes constructs a pair of field + definition strings useful for method parameters.

func (*RelationalModelDefinition) PKUpdateFields Uses

func (f *RelationalModelDefinition) PKUpdateFields(modelname string) string

PKUpdateFields returns something? This function doesn't look useful in current form. Perhaps it isn't.

func (*RelationalModelDefinition) PKWhere Uses

func (f *RelationalModelDefinition) PKWhere() string

PKWhere returns an array of strings representing the where clause of a retrieval by primary key(s) -- x = ? and y = ?.

func (*RelationalModelDefinition) PKWhereFields Uses

func (f *RelationalModelDefinition) PKWhereFields() string

PKWhereFields returns the fields for a where clause for the primary keys of a model.

func (*RelationalModelDefinition) PopulateFromModeledType Uses

func (f *RelationalModelDefinition) PopulateFromModeledType()

PopulateFromModeledType creates fields for the model based on the goa UserTypeDefinition it models, which is set using BuildsFrom(). This happens before fields are processed, so it's ok to just assign without testing.

func (*RelationalModelDefinition) Project Uses

func (f *RelationalModelDefinition) Project(name, v string) *design.MediaTypeDefinition

Project does something interesting, and I don't remember if I use it anywhere.

TODO find out

func (*RelationalModelDefinition) StructDefinition Uses

func (f *RelationalModelDefinition) StructDefinition() string

StructDefinition returns the struct definition for the model.

func (RelationalModelDefinition) TableName Uses

func (f RelationalModelDefinition) TableName() string

TableName returns the TableName of the struct.

func (*RelationalModelDefinition) Underscore Uses

func (f *RelationalModelDefinition) Underscore() string

Underscore returns the model name as a lowercase string in snake case.

func (*RelationalModelDefinition) Validate Uses

func (a *RelationalModelDefinition) Validate() *dslengine.ValidationErrors

Validate tests whether the RelationalModel definition is consistent.

type RelationalStorageType Uses

type RelationalStorageType string

RelationalStorageType is the type of database.

type RelationalStoreDefinition Uses

type RelationalStoreDefinition struct {
    dslengine.Definition
    DefinitionDSL    func()
    Name             string
    Description      string
    Parent           *StorageGroupDefinition
    Type             RelationalStorageType
    RelationalModels map[string]*RelationalModelDefinition
    NoAutoIDFields   bool
    NoAutoTimestamps bool
    NoAutoSoftDelete bool
}

RelationalStoreDefinition is the parent configuration structure for Gorm relational model definitions.

func NewRelationalStoreDefinition Uses

func NewRelationalStoreDefinition() *RelationalStoreDefinition

NewRelationalStoreDefinition returns an initialized RelationalStoreDefinition.

func (RelationalStoreDefinition) Children Uses

func (sd RelationalStoreDefinition) Children() []dslengine.Definition

Children returns a slice of this objects children.

func (*RelationalStoreDefinition) Context Uses

func (sd *RelationalStoreDefinition) Context() string

Context returns the generic definition name used in error messages.

func (*RelationalStoreDefinition) DSL Uses

func (sd *RelationalStoreDefinition) DSL() func()

DSL returns this object's DSL.

func (*RelationalStoreDefinition) IterateModels Uses

func (sd *RelationalStoreDefinition) IterateModels(it ModelIterator) error

IterateModels runs an iterator function once per Model in the Store's model list.

func (*RelationalStoreDefinition) Validate Uses

func (a *RelationalStoreDefinition) Validate() *dslengine.ValidationErrors

Validate tests whether the RelationalStore definition is consistent.

type StorageGroupDefinition Uses

type StorageGroupDefinition struct {
    dslengine.Definition
    DefinitionDSL    func()
    Name             string
    Description      string
    RelationalStores map[string]*RelationalStoreDefinition
}

StorageGroupDefinition is the parent configuration structure for Gorma definitions.

var GormaDesign *StorageGroupDefinition

GormaDesign is the root definition for Gorma

func NewStorageGroupDefinition Uses

func NewStorageGroupDefinition() *StorageGroupDefinition

NewStorageGroupDefinition returns an initialized StorageGroupDefinition.

func (StorageGroupDefinition) Children Uses

func (sd StorageGroupDefinition) Children() []dslengine.Definition

Children returns a slice of this objects children.

func (StorageGroupDefinition) Context Uses

func (sd StorageGroupDefinition) Context() string

Context returns the generic definition name used in error messages.

func (StorageGroupDefinition) DSL Uses

func (sd StorageGroupDefinition) DSL() func()

DSL returns this object's DSL.

func (*StorageGroupDefinition) DSLName Uses

func (sd *StorageGroupDefinition) DSLName() string

DSLName is displayed to the user when the DSL executes.

func (*StorageGroupDefinition) DependsOn Uses

func (sd *StorageGroupDefinition) DependsOn() []dslengine.Root

DependsOn return the DSL roots the Gorma DSL root depends on, that's the goa API DSL.

func (*StorageGroupDefinition) IterateSets Uses

func (sd *StorageGroupDefinition) IterateSets(iterator dslengine.SetIterator)

IterateSets goes over all the definition sets of the StorageGroup: the StorageGroup definition itself, each store definition, models and fields.

func (*StorageGroupDefinition) IterateStores Uses

func (sd *StorageGroupDefinition) IterateStores(it StoreIterator) error

IterateStores runs an iterator function once per Relational Store in the StorageGroup's Store list.

func (*StorageGroupDefinition) Reset Uses

func (sd *StorageGroupDefinition) Reset()

Reset resets the storage group to pre DSL execution state.

func (*StorageGroupDefinition) Validate Uses

func (a *StorageGroupDefinition) Validate() *dslengine.ValidationErrors

Validate tests whether the StorageGroup definition is consistent.

type StoreIterator Uses

type StoreIterator func(m *RelationalStoreDefinition) error

StoreIterator is a function that iterates over Relational Stores in a StorageGroup.

type UserHelperWriter Uses

type UserHelperWriter struct {
    *codegen.SourceFile
    UserHelperTmpl *template.Template
}

UserHelperWriter generate code for a goa application user types. User types are data structures defined in the DSL with "Type".

func NewUserHelperWriter Uses

func NewUserHelperWriter(filename string) (*UserHelperWriter, error)

NewUserHelperWriter returns a contexts code writer. User types contain custom data structured defined in the DSL with "Type".

func (*UserHelperWriter) Execute Uses

func (w *UserHelperWriter) Execute(data *UserTypeTemplateData) error

Execute writes the code for the context types to the writer.

type UserTypeAdapterDefinition Uses

type UserTypeAdapterDefinition struct {
    dslengine.Definition
    DefinitionDSL func()
    Name          string
    Description   string
    Left          *RelationalModelDefinition
    Right         *RelationalModelDefinition
}

UserTypeAdapterDefinition represents the transformation of a Goa user type into a Gorma Model.

Unimplemented at this time.

type UserTypeTemplateData Uses

type UserTypeTemplateData struct {
    APIDefinition *design.APIDefinition
    UserType      *RelationalModelDefinition
    DefaultPkg    string
    AppPkg        string
}

UserTypeTemplateData contains all the information used by the template to redner the media types code.

type UserTypesWriter Uses

type UserTypesWriter struct {
    *codegen.SourceFile
    UserTypeTmpl   *template.Template
    UserHelperTmpl *template.Template
}

UserTypesWriter generate code for a goa application user types. User types are data structures defined in the DSL with "Type".

func NewUserTypesWriter Uses

func NewUserTypesWriter(filename string) (*UserTypesWriter, error)

NewUserTypesWriter returns a contexts code writer. User types contain custom data structured defined in the DSL with "Type".

func (*UserTypesWriter) Execute Uses

func (w *UserTypesWriter) Execute(data *UserTypeTemplateData) error

Execute writes the code for the context types to the writer.

Directories

PathSynopsis
dslPackage dsl uses the Goa DSL engine to generate a data storage layer for your Goa API.

Package gorma imports 15 packages (graph) and is imported by 25 packages. Updated 2019-05-21. Refresh now. Tools for package owners.