Gen Guides

GEN Guides

GEN: Friendly & Safer GORM powered by Code Generation.


  • Idiomatic & Reusable API from Dynamic Raw SQL
  • 100% Type-safe DAO API without interface{}
  • Database To Struct follows GORM conventions
  • GORM under the hood, supports all features, plugins, DBMS that GORM supports


go get -u

Quick start

It is quite straightforward to use gen for your application, here is how it works:

1. Write the configuration in golang

package main

import ""

// Dynamic SQL
type Querier interface {
// SELECT * FROM @@table WHERE name = @name{{if role !=""}} AND role = @role{{end}}
FilterWithNameAndRole(name, role string) ([]gen.T, error)

func main() {
g := gen.NewGenerator(gen.Config{
OutPath: "../query",
Mode: gen.WithoutContext|gen.WithDefaultQuery|gen.WithQueryInterface, // generate mode

// gormdb, _ := gorm.Open(mysql.Open("root:@("))
g.UseDB(gormdb) // reuse your gorm db

// Generate basic type-safe DAO API for struct `model.User` following conventions

// Generate Type Safe API with Dynamic SQL defined on Querier interface for `model.User` and `model.Company`
g.ApplyInterface(func(Querier){}, model.User{}, model.Company{})

// Generate the code

2. Generate Code

go run main.go

3. Use the generated code in your project

import "your_project/query"

func main() {
// Basic DAO API
user, err := query.User.Where(u.Name.Eq("modi")).First()

// Dynamic SQL API
users, err := query.User.FilterWithNameAndRole("modi", "admin")

Platinum Sponsors

Gold Sponsors

Platinum Sponsors

Gold Sponsors