github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/schema/currency.go (about) 1 //nolint:dupl 2 package schema 3 4 import ( 5 "entgo.io/ent" 6 "entgo.io/ent/dialect" 7 "entgo.io/ent/schema/field" 8 "entgo.io/ent/schema/index" 9 "github.com/NpoolPlatform/chain-middleware/pkg/db/mixin" 10 crudermixin "github.com/NpoolPlatform/libent-cruder/pkg/mixin" 11 basetypes "github.com/NpoolPlatform/message/npool/basetypes/v1" 12 "github.com/google/uuid" 13 "github.com/shopspring/decimal" 14 ) 15 16 // Currency holds the schema definition for the Currency entity. 17 type Currency struct { 18 ent.Schema 19 } 20 21 func (Currency) Mixin() []ent.Mixin { 22 return []ent.Mixin{ 23 mixin.TimeMixin{}, 24 crudermixin.AutoIDMixin{}, 25 } 26 } 27 28 // Fields of the Currency. 29 func (Currency) Fields() []ent.Field { 30 return []ent.Field{ 31 field. 32 UUID("coin_type_id", uuid.UUID{}). 33 Optional(). 34 Default(uuid.New), 35 field. 36 String("feed_type"). 37 Optional(). 38 Default(basetypes.CurrencyFeedType_DefaultFeedType.String()), 39 field. 40 Other("market_value_high", decimal.Decimal{}). 41 SchemaType(map[string]string{ 42 dialect.MySQL: "decimal(37,18)", 43 }). 44 Optional(). 45 Default(decimal.Decimal{}), 46 field. 47 Other("market_value_low", decimal.Decimal{}). 48 SchemaType(map[string]string{ 49 dialect.MySQL: "decimal(37,18)", 50 }). 51 Optional(). 52 Default(decimal.Decimal{}), 53 } 54 } 55 56 // Edges of the Currency. 57 func (Currency) Edges() []ent.Edge { 58 return nil 59 } 60 61 func (Currency) Indexes() []ent.Index { 62 return []ent.Index{ 63 index.Fields("coin_type_id", "id"), 64 index.Fields("coin_type_id"), 65 } 66 }