diff --git a/README.ZH_CN.md b/README.ZH_CN.md index 6eed7bc4..4a5eff42 100644 --- a/README.ZH_CN.md +++ b/README.ZH_CN.md @@ -35,6 +35,7 @@ - [项目路径](#project-directory) - [API 示例](#api-examples) - [生成](#generate) + - [生成模式](#generate-mode) - [模型生成](#generate-model) - [类型映射](#data-mapping) - [字段表达式](#field-expression) @@ -237,6 +238,20 @@ demo ### 生成 +#### 生成模式 + +```go + g := gen.NewGenerator(gen.Config{ + ... + Mode: gen.WithoutContext|gen.WithDefaultQuery|gen.WithQueryInterface, + ... + }) +``` + +- `WithDefaultQuery` 生成默认查询结构体(作为全局变量使用) +- `WithoutContext` 生成没有context调用限制的代码供查询 +- `WithQueryInterface` 生成interface形式的查询代码(可导出) + #### 模型生成 ```go diff --git a/README.md b/README.md index 627c663a..ff65fe3f 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Gen: Friendly & Safer [GORM](https://github.com/go-gorm/gorm) powered by Code Ge - [Project Directory](#project-directory) - [API Examples](#api-examples) - [Generate](#generate) + - [Generate Mode](#generate-mode) - [Generate Model](#generate-model) - [Data Mapping](#data-mapping) - [Field Expression](#field-expression) @@ -233,6 +234,20 @@ demo ### Generate +#### Generate Mode + +```go + g := gen.NewGenerator(gen.Config{ + ... + Mode: gen.WithoutContext|gen.WithDefaultQuery|gen.WithQueryInterface, + ... + }) +``` + +- `WithDefaultQuery` generate default query struct +- `WithoutContext` generate code without context constrain +- `WithQueryInterface` generate interface instead of struct for querying + #### Generate Model ```go diff --git a/config.go b/config.go index 7a400665..8af599e4 100644 --- a/config.go +++ b/config.go @@ -22,8 +22,8 @@ const ( // WithoutContext generate code without context constrain WithoutContext - // WithQueryIface generate code with exported interface object - WithQueryIface + // WithQueryInterface generate code with exported interface object + WithQueryInterface ) // Config generator's basic configuration diff --git a/generator.go b/generator.go index 83230669..64cb7969 100644 --- a/generator.go +++ b/generator.go @@ -375,7 +375,7 @@ func (g *Generator) generateSingleQueryFile(data *genInfo) (err error) { return err } - data.BaseStruct = data.BaseStruct.IfaceMode(g.judgeMode(WithQueryIface)) + data.BaseStruct = data.BaseStruct.IfaceMode(g.judgeMode(WithQueryInterface)) structTmpl := tmpl.TableQueryStructWithContext if g.judgeMode(WithoutContext) { @@ -386,7 +386,7 @@ func (g *Generator) generateSingleQueryFile(data *genInfo) (err error) { return err } - if g.judgeMode(WithQueryIface) { + if g.judgeMode(WithQueryInterface) { err = render(tmpl.TableQueryIface, &buf, data) if err != nil { return err