-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.go
34 lines (28 loc) · 870 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package db
import (
"log/slog"
"github.com/opentdf/platform/protocol/go/common"
"google.golang.org/protobuf/encoding/protojson"
)
func constructMetadata(table string, isJSON bool) string {
if table != "" {
table += "."
}
metadata := "JSON_STRIP_NULLS(JSON_BUILD_OBJECT('labels', " + table + "metadata->'labels', 'created_at', " + table + "created_at, 'updated_at', " + table + "updated_at))"
if isJSON {
metadata = "'metadata', " + metadata + ", "
} else {
metadata += " AS metadata"
}
return metadata
}
var createSuffix = "RETURNING id, " + constructMetadata("", false)
func unmarshalMetadata(metadataJSON []byte, m *common.Metadata) error {
if metadataJSON != nil {
if err := protojson.Unmarshal(metadataJSON, m); err != nil {
slog.Error("could not unmarshal metadata", slog.String("error", err.Error()))
return err
}
}
return nil
}