From 528a6b289594a2580793bcf37eee8c100e41a9cb Mon Sep 17 00:00:00 2001 From: it512 Date: Mon, 23 Sep 2024 23:01:09 +0800 Subject: [PATCH] - --- member/cmd/member/main.go | 7 +++ member/orm/schema/member.go | 88 +++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 member/cmd/member/main.go create mode 100644 member/orm/schema/member.go diff --git a/member/cmd/member/main.go b/member/cmd/member/main.go new file mode 100644 index 0000000..b417f1d --- /dev/null +++ b/member/cmd/member/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("member") +} diff --git a/member/orm/schema/member.go b/member/orm/schema/member.go new file mode 100644 index 0000000..1545648 --- /dev/null +++ b/member/orm/schema/member.go @@ -0,0 +1,88 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" + "entgo.io/ent/schema/mixin" + "github.com/google/uuid" + + "github.com/twiglab/crm/member/orm/schema/x" +) + +type Member struct { + ent.Schema +} + +func (Member) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.Nil). + Default(x.ID). + Unique(). + Immutable(), + + field.String("code"). + MaxLen(36). + NotEmpty(). + Unique(). + Immutable(). + DefaultFunc(x.Code36). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("phone"). + MaxLen(64). + Unique(). + Validate(x.CheckMobile). + SchemaType(map[string]string{ + dialect.MySQL: "varchar(64)", // Override MySQL. + dialect.Postgres: "varchar(64)", // Override Postgres. + dialect.SQLite: "varchar(64)", // Override Postgres. + }), + + field.String("nickname"). + MaxLen(64). + SchemaType(map[string]string{ + dialect.MySQL: "varchar(64)", // Override MySQL. + dialect.Postgres: "varchar(64)", // Override Postgres. + dialect.SQLite: "varchar(64)", // Override Postgres. + }), + + field.String("wx_open_id"). + MaxLen(256). + Unique(). + SchemaType(map[string]string{ + dialect.MySQL: "varchar(256)", // Override MySQL. + dialect.Postgres: "varchar(256)", // Override Postgres. + dialect.SQLite: "varchar(256)", // Override Postgres. + }), + + field.Int("status").Default(0), + } +} + +func (Member) Mixin() []ent.Mixin { + return []ent.Mixin{ + mixin.Time{}, + } +} + +func (Member) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("code"), + index.Fields("wx_open_id"), + index.Fields("phone"), + } +} + +func (Member) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "t_member"}, + } +}