Skip to content

joeblew99/gorma

This branch is 98 commits behind goadesign/gorma:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

569cda3 · May 17, 2016
May 5, 2016
Apr 29, 2016
Feb 10, 2016
Feb 10, 2016
Mar 19, 2016
Dec 31, 2015
Apr 10, 2016
Feb 12, 2016
Feb 10, 2016
Feb 26, 2016
Feb 10, 2016
May 13, 2016
Mar 24, 2016
Feb 10, 2016
Feb 10, 2016
Apr 27, 2016
Apr 27, 2016
May 17, 2016
Feb 10, 2016
Feb 10, 2016
Feb 25, 2016
Mar 3, 2016
Jan 23, 2016
Feb 5, 2016
Apr 29, 2016

Repository files navigation

gorma

Gorma is a storage generator for goa.

GoDoc Build Status Go Report Card

Table of Contents

Purpose

Gorma uses a custom goa DSL to generate a working storage system for your API.

Opinionated

Gorma generates Go code that uses gorm to access your database, therefore it is quite opinionated about how the data access layer is generated.

By default, a primary key field is created as type int with name ID. Also Gorm's magic date stamp fields created_at, updated_at and deleted_at are created. Override this behavior with the Automatic* DSL functions on the Store.

Translations

Use the BuildsFrom and RendersTo DSL to have Gorma generate translation functions to translate your model to Media Types and from Payloads (User Types). If you don't have any complex business logic in your controllers, this makes a typical controller function 3-4 lines long.

Use

Write a storage definition using DSL from the dsl package. Example:


	var sg = StorageGroup("MyStorageGroup", func() {
		Description("This is the global storage group")
		Store("mysql", gorma.MySQL, func() {
			Description("This is the mysql relational store")
			Model("Bottle", func() {
				BuildsFrom(func() {
					Payload("myresource","actionname")  // e.g. "bottle", "create" resource definition
				})
				RendersTo(Bottle)						// a Media Type definition
				Description("This is the bottle model")
				Field("ID", gorma.Integer, func() {    //  redundant
					PrimaryKey()
					Description("This is the ID PK field")
				})
				Field("Vintage", gorma.Integer, func() {
					SQLTag("index")						// Add an index
				})
				Field("CreatedAt", gorma.Timestamp)
				Field("UpdatedAt", gorma.Timestamp)			 // Shown for demonstration
				Field("DeletedAt", gorma.NullableTimestamp)  // These are added by default
			})
		})
	})


See the dsl GoDoc for all the details and options.

From the root of your application, issue the goagen command as follows:

	goagen --design=github.com/gopheracademy/congo/design gen --pkg-path=github.com/goadesign/gorma

Be sure to replace github.com/gopheracademy/congo/design with the design package of your goa application.

About

Storage generation plugin for Goa

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 95.5%
  • JavaScript 3.8%
  • Other 0.7%