From 08d1acb15eda01ac11c0a870ca48f672552e7a5b Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Mon, 26 Aug 2024 18:33:46 +0800 Subject: [PATCH] feat: added hash to models --- core/entity/database.go | 2 ++ core/utils/hash.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 core/utils/hash.go diff --git a/core/entity/database.go b/core/entity/database.go index bd89b7ce..eccb7d4f 100644 --- a/core/entity/database.go +++ b/core/entity/database.go @@ -24,6 +24,7 @@ type DatabaseColumn struct { Default string `json:"default,omitempty"` Extra string `json:"extra,omitempty"` Children []DatabaseColumn `json:"children,omitempty"` + Hash string `json:"hash,omitempty"` } type DatabaseIndex struct { @@ -31,6 +32,7 @@ type DatabaseIndex struct { Type string `json:"type,omitempty"` Columns []DatabaseIndexColumn `json:"columns"` Unique bool `json:"unique"` + Hash string `json:"hash,omitempty"` } type DatabaseIndexColumn struct { diff --git a/core/utils/hash.go b/core/utils/hash.go new file mode 100644 index 00000000..8fcbf0a1 --- /dev/null +++ b/core/utils/hash.go @@ -0,0 +1,12 @@ +package utils + +import "encoding/json" + +func GetObjectHash(obj any) string { + data, _ := json.Marshal(obj) + if data == nil { + // random hash + return EncryptMd5(NewUUIDString()) + } + return EncryptMd5(string(data)) +}