Skip to content

anqur/cogen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cogen

co-generator, or codegen.

cogen is a DDL codegen for GORM structs.

Example

package main

import (
	"fmt"

	"github.com/anqur/cogen"
)

type Item struct {
	ID    uint64 `gorm:"column:id;primary_key;auto_increment;not null;type:bigint(20) unsigned"`
	Name  string `gorm:"column:name;not null;type:varchar(64);default:\"\";uniqueindex"`
	Price uint32 `gorm:"column:price;not null;type:uint;default:0"`
}

func (Item) TableName() string {
	return "t_item"
}

func main() {
	g, err := cogen.MySQL(Item{})
	if err != nil {
		panic(err)
	}
	fmt.Println(g.String())
}

Why

  • It's hard to do that in GORM. We need some hacks and tricks
  • I believe that DB schemas are mostly not the real business entities without invariants. Let's generate the DDLs from some intermediate ORM structs!

License

MIT

About

DDL codegen for GORM structs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages