feat: add entgo mixin and sonyflake.
This commit is contained in:
@@ -12,8 +12,8 @@ type CreateBy struct{ mixin.Schema }
|
||||
|
||||
func (CreateBy) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("create_by").
|
||||
Comment("创建者").
|
||||
field.Uint32("create_by").
|
||||
Comment("创建者ID").
|
||||
Optional().
|
||||
Nillable(),
|
||||
}
|
||||
@@ -25,8 +25,8 @@ type UpdateBy struct{ mixin.Schema }
|
||||
|
||||
func (UpdateBy) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("update_by").
|
||||
Comment("更新者").
|
||||
field.Uint32("update_by").
|
||||
Comment("更新者ID").
|
||||
Optional().
|
||||
Nillable(),
|
||||
}
|
||||
@@ -38,8 +38,8 @@ type DeleteBy struct{ mixin.Schema }
|
||||
|
||||
func (DeleteBy) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("delete_by").
|
||||
Comment("删除者").
|
||||
field.Uint32("delete_by").
|
||||
Comment("删除者ID").
|
||||
Optional().
|
||||
Nillable(),
|
||||
}
|
||||
@@ -51,8 +51,8 @@ type CreatedBy struct{ mixin.Schema }
|
||||
|
||||
func (CreatedBy) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("created_by").
|
||||
Comment("创建者").
|
||||
field.Uint32("created_by").
|
||||
Comment("创建者ID").
|
||||
Optional().
|
||||
Nillable(),
|
||||
}
|
||||
@@ -64,8 +64,8 @@ type UpdatedBy struct{ mixin.Schema }
|
||||
|
||||
func (UpdatedBy) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("updated_by").
|
||||
Comment("更新者").
|
||||
field.Uint32("updated_by").
|
||||
Comment("更新者ID").
|
||||
Optional().
|
||||
Nillable(),
|
||||
}
|
||||
@@ -77,8 +77,8 @@ type DeletedBy struct{ mixin.Schema }
|
||||
|
||||
func (DeletedBy) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("deleted_by").
|
||||
Comment("删除者").
|
||||
field.Uint32("deleted_by").
|
||||
Comment("删除者ID").
|
||||
Optional().
|
||||
Nillable(),
|
||||
}
|
||||
|
||||
21
entgo/mixin/remark.go
Normal file
21
entgo/mixin/remark.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package mixin
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
)
|
||||
|
||||
type Remark struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (Remark) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("remark").
|
||||
Comment("备注").
|
||||
Default("").
|
||||
Optional().
|
||||
Nillable(),
|
||||
}
|
||||
}
|
||||
37
entgo/mixin/switch_status.go
Normal file
37
entgo/mixin/switch_status.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package mixin
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
)
|
||||
|
||||
type SwitchStatus struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (SwitchStatus) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
/**
|
||||
在PostgreSQL下,还需要为此创建一个Type,否则无法使用。
|
||||
|
||||
DROP TYPE IF EXISTS switch_status CASCADE;
|
||||
CREATE TYPE switch_status AS ENUM (
|
||||
'OFF',
|
||||
'ON'
|
||||
);
|
||||
*/
|
||||
field.Enum("status").
|
||||
Comment("状态").
|
||||
Optional().
|
||||
Nillable().
|
||||
//SchemaType(map[string]string{
|
||||
// dialect.MySQL: "switch_status",
|
||||
// dialect.Postgres: "switch_status",
|
||||
//}).
|
||||
Values(
|
||||
"OFF",
|
||||
"ON",
|
||||
),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user