mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 00:38:49 +01:00
🎨 The database template column supports queryBlocks function https://github.com/siyuan-note/siyuan/issues/10077
This commit is contained in:
parent
9b6cb211ab
commit
20cd2ac696
3 changed files with 31 additions and 28 deletions
|
|
@ -18,9 +18,14 @@ package util
|
|||
|
||||
import (
|
||||
"math"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
|
|
@ -34,6 +39,30 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) {
|
|||
ret["powf"] = powf
|
||||
ret["log"] = log
|
||||
ret["logf"] = logf
|
||||
|
||||
ret["queryBlocks"] = func(stmt string, args ...string) (retBlocks []*sql.Block) {
|
||||
for _, arg := range args {
|
||||
stmt = strings.Replace(stmt, "?", arg, 1)
|
||||
}
|
||||
retBlocks = sql.SelectBlocksRawStmt(stmt, 1, 512)
|
||||
return
|
||||
}
|
||||
ret["querySpans"] = func(stmt string, args ...string) (retSpans []*sql.Span) {
|
||||
for _, arg := range args {
|
||||
stmt = strings.Replace(stmt, "?", arg, 1)
|
||||
}
|
||||
retSpans = sql.SelectSpansRawStmt(stmt, 512)
|
||||
return
|
||||
}
|
||||
ret["parseTime"] = func(dateStr string) time.Time {
|
||||
now := time.Now()
|
||||
retTime, err := dateparse.ParseIn(dateStr, now.Location())
|
||||
if nil != err {
|
||||
logging.LogWarnf("parse date [%s] failed [%s], return current time instead", dateStr, err)
|
||||
return now
|
||||
}
|
||||
return retTime
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue