mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958
This commit is contained in:
parent
be4ebe776d
commit
93dc9f5c22
3 changed files with 50 additions and 2 deletions
|
|
@ -105,8 +105,14 @@ func NewKey(id, name, icon string, keyType KeyType) *Key {
|
|||
}
|
||||
|
||||
type Rollup struct {
|
||||
RelationKeyID string `json:"relationKeyID"` // 关联列 ID
|
||||
KeyID string `json:"keyID"` // 目标列 ID
|
||||
RelationKeyID string `json:"relationKeyID"` // 关联列 ID
|
||||
KeyID string `json:"keyID"` // 目标列 ID
|
||||
Calc *RollupCalc `json:"calc"` // 计算方式
|
||||
}
|
||||
|
||||
type RollupCalc struct {
|
||||
Operator CalcOperator `json:"operator"`
|
||||
Result *Value `json:"result"`
|
||||
}
|
||||
|
||||
type Relation struct {
|
||||
|
|
|
|||
|
|
@ -774,6 +774,46 @@ func getRowBlockValue(keyValues []*av.KeyValues) (ret *av.Value) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doUpdateAttrViewColRollup(operation *Operation) (ret *TxErr) {
|
||||
err := updateAttributeViewColRollup(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func updateAttributeViewColRollup(operation *Operation) (err error) {
|
||||
// operation.AvID 汇总列所在 av
|
||||
// operation.ID 汇总列 ID
|
||||
// operation.ParentID 汇总列基于的关联列 ID
|
||||
// operation.KeyID 目标列 ID
|
||||
// operation.Data 计算方式
|
||||
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
rollUpKey, _ := attrView.GetKey(operation.ID)
|
||||
if nil == rollUpKey {
|
||||
return
|
||||
}
|
||||
|
||||
rollUpKey.Rollup = &av.Rollup{
|
||||
RelationKeyID: operation.ParentID,
|
||||
KeyID: operation.KeyID,
|
||||
}
|
||||
|
||||
if "" != operation.Data {
|
||||
if err = gulu.JSON.UnmarshalJSON([]byte(operation.Data.(string)), &rollUpKey.Rollup.Calc); nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doUpdateAttrViewColRelation(operation *Operation) (ret *TxErr) {
|
||||
err := updateAttributeViewColRelation(operation)
|
||||
if nil != err {
|
||||
|
|
|
|||
|
|
@ -274,6 +274,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doSortAttrViewView(op)
|
||||
case "updateAttrViewColRelation":
|
||||
ret = tx.doUpdateAttrViewColRelation(op)
|
||||
case "updateAttrViewColRollup":
|
||||
ret = tx.doUpdateAttrViewColRollup(op)
|
||||
}
|
||||
|
||||
if nil != ret {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue