gormdao

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 12 Imported by: 0

README

gorm-dao

模板生成gorm的dao

简介

  • 根据Model生成Dao
  • 生成的Dao支持简易链式操作

开始

下载gorm-dao
cd $your_project
go get github.com/zl-leaf/gorm-dao
开始生成
package main

import (
	gormdao "github.com/zl-leaf/gorm-dao"
	"model"
)

func main() {
	g := gormdao.NewGenerator("./gen/dao") // 初始化,指定生成dao代码的目录
	g.Apply(model.User{}, model.Role{})    // 指定Model对象生成dao代码
	err := g.Generate()
	if err != nil {
		panic(err)
	}
}

开始使用

var (
    db = *gorm.DB
    userList []*model.User
    total int64
    err error
)
userList, total, err = dao.NewDao(db).
    WhereUsernameLike("demo").
    WhereCreatedAtLt(time.Now().Unix()).
    Find()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

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

func NewGenerator

func NewGenerator(outputPath string) *Generator

func (*Generator) Apply

func (g *Generator) Apply(models ...interface{})

func (*Generator) Generate

func (g *Generator) Generate() error

Directories

Path Synopsis
internal
tpl

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL