소스 검색

:art: Add Relation column to database table view https://github.com/siyuan-note/siyuan/issues/9888

Daniel 1 년 전
부모
커밋
ddc07027a7
1개의 변경된 파일22개의 추가작업 그리고 2개의 파일을 삭제
  1. 22 2
      kernel/av/table.go

+ 22 - 2
kernel/av/table.go

@@ -203,9 +203,29 @@ func (value *Value) Compare(other *Value) int {
 			return 0
 		}
 	case KeyTypeRelation:
-		// TODO: relation compare
+		if nil != value.Relation && nil != other.Relation {
+			vContent := strings.TrimSpace(strings.Join(value.Relation.Contents, " "))
+			oContent := strings.TrimSpace(strings.Join(other.Relation.Contents, " "))
+			return strings.Compare(vContent, oContent)
+		}
 	case KeyTypeRollup:
-		// TODO: rollup compare
+		if nil != value.Rollup && nil != other.Rollup {
+			vContent := strings.TrimSpace(strings.Join(value.Relation.Contents, " "))
+			oContent := strings.TrimSpace(strings.Join(other.Relation.Contents, " "))
+			if util.IsNumeric(vContent) && util.IsNumeric(oContent) {
+				v1, _ := strconv.ParseFloat(vContent, 64)
+				v2, _ := strconv.ParseFloat(oContent, 64)
+				if v1 > v2 {
+					return 1
+				}
+
+				if v1 < v2 {
+					return -1
+				}
+				return 0
+			}
+			return strings.Compare(vContent, oContent)
+		}
 	}
 	return 0
 }