file_annotation_ref.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SiYuan - Refactor your thinking
  2. // Copyright (c) 2020-present, b3log.org
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. package sql
  17. import (
  18. "github.com/siyuan-note/logging"
  19. )
  20. type FileAnnotationRef struct {
  21. ID string
  22. FilePath string
  23. AnnotationID string
  24. BlockID string
  25. RootID string
  26. Box string
  27. Path string
  28. Content string
  29. Type string
  30. }
  31. func QueryRefIDsByAnnotationID(annotationID string) (refIDs, refTexts []string) {
  32. refIDs = []string{}
  33. rows, err := query("SELECT block_id, content FROM file_annotation_refs WHERE annotation_id = ?", annotationID)
  34. if nil != err {
  35. logging.LogErrorf("sql query failed: %s", err)
  36. return
  37. }
  38. defer rows.Close()
  39. for rows.Next() {
  40. var id, content string
  41. if err = rows.Scan(&id, &content); nil != err {
  42. logging.LogErrorf("query scan field failed: %s", err)
  43. return
  44. }
  45. refIDs = append(refIDs, id)
  46. refTexts = append(refTexts, content)
  47. }
  48. return
  49. }