forked from mirrors/homebox
introduce scaffold for new models
This commit is contained in:
parent
14315cb88a
commit
4725d9c823
2 changed files with 55 additions and 0 deletions
18
.scaffold/model/scaffold.yaml
Normal file
18
.scaffold/model/scaffold.yaml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
messages:
|
||||||
|
pre: |
|
||||||
|
# Ent Model Generation
|
||||||
|
|
||||||
|
With Boilerplate!
|
||||||
|
post: |
|
||||||
|
Complete!
|
||||||
|
|
||||||
|
questions:
|
||||||
|
- name: "model"
|
||||||
|
prompt:
|
||||||
|
message: "What is the name of the model? (PascalCase)"
|
||||||
|
required: true
|
||||||
|
|
||||||
|
rewrites:
|
||||||
|
- from: 'templates/model.go'
|
||||||
|
to: 'backend/internal/data/ent/schema/{{ lower .Scaffold.model }}.go'
|
37
.scaffold/model/templates/model.go
Normal file
37
.scaffold/model/templates/model.go
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
||||||
|
)
|
||||||
|
|
||||||
|
type {{ .Scaffold.model }} struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func ({{ .Scaffold.model }}) Mixin() []ent.Mixin {
|
||||||
|
return []ent.Mixin{
|
||||||
|
mixins.BaseMixin{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the {{ .Scaffold.model }}.
|
||||||
|
func ({{ .Scaffold.model }}) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
// field.String("name").
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the {{ .Scaffold.model }}.
|
||||||
|
func ({{ .Scaffold.model }}) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
// edge.From("group", Group.Type).
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ({{ .Scaffold.model }}) Indexes() []ent.Index {
|
||||||
|
return []ent.Index{
|
||||||
|
// index.Fields("token"),
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue