bun_templates

package
v0.0.0-...-f670af2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Constr = template.Tr[inspected.Entity](template.AtConstructor, `
{{- if eq .Opts.Constr "func" }}
{{ $entity := . }}
{{range .Opts.Cores }}
func New{{ . }}{{ $entity.Name }}(ctx context.Context, db `+dbObjectIdent+`) {{ $entity.Name }} {
	return {{ $entity.Name | printf $entity.Opts.TypeNamePattern }}{ Repo: core{{ . }}.New[{{ $entity.ModelIdent}}](ctx, db) }
}
{{ end }}
{{ end -}}

{{- if eq .Opts.Constr "factory" -}}
{{ $entity := . }}
{{range .Opts.Cores }}
func (factory {{ . }}) New{{ $entity.Name }}(ctx context.Context) {{ $entity.Name }} {
	return {{ $entity.Name | printf $entity.Opts.TypeNamePattern }}{ Repo: core{{ . }}.New[{{ $entity.ModelIdent}}](ctx, factory.DB) }
}
{{ end -}}
{{ end -}}
`)
View Source
var CoreImport = template.Tr[inspected.Opts](template.AtImport, `
{{- range .Cores }}
	core{{ . }} "github.com/iamgoroot/dbie/core/{{ . | toSnake }}"
	{{ if eq . "Bun" }}"github.com/uptrace/bun"{{ end -}}
	{{ if eq . "Gorm" }}"gorm.io/gorm"{{ end -}}
	{{ if eq . "Bee" }}"github.com/beego/beego/v2/client/orm"{{ end -}}
	{{ if eq . "Pg" }}"github.com/go-pg/pg/v10"{{ end -}}
	{{ if eq . "Mongo" }}"go.mongodb.org/mongo-driver/mongo"{{ end -}}
{{- end -}}
`)
View Source
var Factory = template.Tr[inspected.Opts](template.AtConstructor, `
{{- if eq .Constr "factory" }}
{{range .Cores }}
type {{ . }} struct {
`+dbObjectIdent+`
}
{{ end -}}
{{ end -}}
`)
View Source
var SelectByField = template.Tr[inspected.SelectorMethod](template.AtFunc,
	"{{if .OrderBy}}"+
		"var sort{{ .MethodName }}Setting = []dbie.Sort{\n"+
		"{{ range $val := .OrderBy }}\t{Field: `{{ $val.Field }}`, Order: {{ $val.Order }}},\n{{ end }}"+
		"}{{ end }}"+`

func (g {{ .Name | printf .Opts.TypeNamePattern }}) {{ .MethodName }}(
{{- if .PageParamName }}{{ .PageParamName }} dbie.Page, {{ end -}}
{{- .SelectFieldName }} {{ .SelectFieldType -}}
) ({{ .ModelIdent }}, error) {
	return g.Repo.{{ .CallMethod }}({{ if .PageParamName }}{{ .PageParamName }}, {{ end -}}`+
		"\"{{ .SelectFieldName }}\""+
		`, dbie.{{ .Op }}, {{ .SelectFieldName }}{{if .OrderBy}}, sort{{ .MethodName }}Setting...{{ end }})		
}
`)
View Source
var Struct = template.Tr[inspected.Entity](template.AtTypes, `
type {{ .Name | printf .Opts.TypeNamePattern }} struct {
	dbie.Repo[{{ .ModelIdent }}]
}
`)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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