Gen Guides

GEN Guides

GEN: Friendly & Safer GORM powered by Code Generation.


  • Idiomatic Go Code
  • 100% Type-safe API without interface{}
  • Reusable and Safe API with hand-optimized SQL
  • Database To Golang Struct follows GORM conventions
  • GORM under the hood, supports all DBMS, features that GORM supports


go get -u

Quick start

package main

import ""

type Querier interface {
// SELECT * FROM @@table WHERE name = @name AND role = @role
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 API for struct `model.User` following conventions

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

// Generate the code

Use the generated code in your project

import "your_project/query"

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

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

More examples: gendemo

Platinum Sponsors

Gold Sponsors

Platinum Sponsors

Gold Sponsors