From 3a4e0c1046276235488326bb4e032c801280fc15 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 30 Nov 2024 15:06:57 -0600 Subject: auto detect unique keys in protobuf file --- sort.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'sort.go') diff --git a/sort.go b/sort.go index 4409eba..56b2fdd 100644 --- a/sort.go +++ b/sort.go @@ -5,6 +5,8 @@ import ( "io" "os" "strings" + + "go.wit.com/log" ) func makeSortfile() { @@ -22,6 +24,21 @@ func makeSortfile() { iterAppend(f, sortmap) // Append() enforce unique key argv.Append } + for _, s := range uniqueKeys { + log.Info("found unique key in .proto", s) + sortmap["sortBy"] = s + sortmap["sortKey"] = s + + iterSortBy(f, sortmap) + + sortmap["append"] = sortmap["sortKey"] + iterAppend(f, sortmap) // Append() enforce unique key argv.Append + + iterDelete(f, sortmap) + iterReplace(f, sortmap) + iterFind(f, sortmap) + } + for _, s := range argv.Sort { sortparts := strings.Split(s, ",") sortmap["sortBy"] = sortparts[0] @@ -133,7 +150,7 @@ func iterSortAll(w io.Writer, names map[string]string) { } func iterSortBy(w io.Writer, names map[string]string) { - fmt.Fprintln(w, "func (all *"+names["Bases"]+") Sort"+names["sortBy"]+"() *"+names["Base"]+"Iterator {") + fmt.Fprintln(w, "func (all *"+names["Bases"]+") SortBy"+names["sortBy"]+"() *"+names["Base"]+"Iterator {") fmt.Fprintln(w, " packs := all.selectAll"+names["Base"]+"()") fmt.Fprintln(w, "") fmt.Fprintln(w, " sort.Sort("+names["Base"]+""+names["sortBy"]+"(packs))") -- cgit v1.2.3