mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
This commit is contained in:
parent
d4e3c1e660
commit
d5e07318ee
3 changed files with 57 additions and 29 deletions
|
|
@ -157,16 +157,28 @@ func QueryDefRootBlocksByRefRootID(refRootID string) (ret []*Block) {
|
|||
return
|
||||
}
|
||||
|
||||
func QueryRefRootBlocksByDefRootID(defRootID string) (ret []*Block) {
|
||||
rows, err := query("SELECT * FROM blocks WHERE id IN (SELECT DISTINCT root_id FROM refs WHERE def_block_root_id = ?)", defRootID)
|
||||
func QueryRefRootBlocksByDefRootIDs(defRootIDs []string) (ret map[string][]*Block) {
|
||||
ret = map[string][]*Block{}
|
||||
|
||||
stmt := "SELECT r.def_block_root_id, b.* FROM refs AS r, blocks AS b ON r.def_block_root_id IN ('" + strings.Join(defRootIDs, "','") + "')" + " AND b.id = r.root_id"
|
||||
rows, err := query(stmt)
|
||||
if nil != err {
|
||||
logging.LogErrorf("sql query failed: %s", err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
if block := scanBlockRows(rows); nil != block {
|
||||
ret = append(ret, block)
|
||||
var block Block
|
||||
var defRootID string
|
||||
if err := rows.Scan(&defRootID, &block.ID, &block.ParentID, &block.RootID, &block.Hash, &block.Box, &block.Path, &block.HPath, &block.Name, &block.Alias, &block.Memo, &block.Tag, &block.Content, &block.FContent, &block.Markdown, &block.Length, &block.Type, &block.SubType, &block.IAL, &block.Sort, &block.Created, &block.Updated); nil != err {
|
||||
logging.LogErrorf("query scan field failed: %s\n%s", err, logging.ShortStack())
|
||||
return
|
||||
}
|
||||
|
||||
if nil == ret[defRootID] {
|
||||
ret[defRootID] = []*Block{}
|
||||
} else {
|
||||
ret[defRootID] = append(ret[defRootID], &block)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue