🎨 Query embed blocks support UNION queries https://github.com/siyuan-note/siyuan/issues/16594

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-12-16 12:15:28 +08:00
parent 3e9bd1547c
commit a201aebf59
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -602,6 +602,38 @@ func SelectBlocksRawStmt(stmt string, page, limit int) (ret []*Block) {
}
stmt = sqlparser.String(slct)
case *sqlparser.Union:
union := parsedStmt.(*sqlparser.Union)
if nil == union.Limit {
union.Limit = &sqlparser.Limit{
Rowcount: &sqlparser.SQLVal{
Type: sqlparser.IntVal,
Val: []byte(strconv.Itoa(limit)),
},
}
union.Limit.Offset = &sqlparser.SQLVal{
Type: sqlparser.IntVal,
Val: []byte(strconv.Itoa((page - 1) * limit)),
}
} else {
if nil != union.Limit.Rowcount && 0 < len(union.Limit.Rowcount.(*sqlparser.SQLVal).Val) {
limit, _ = strconv.Atoi(string(union.Limit.Rowcount.(*sqlparser.SQLVal).Val))
if 0 >= limit {
limit = 32
}
}
union.Limit.Rowcount = &sqlparser.SQLVal{
Type: sqlparser.IntVal,
Val: []byte(strconv.Itoa(limit)),
}
union.Limit.Offset = &sqlparser.SQLVal{
Type: sqlparser.IntVal,
Val: []byte(strconv.Itoa((page - 1) * limit)),
}
}
stmt = sqlparser.String(union)
default:
return
}