block.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. "database/sql"
  19. "github.com/siyuan-note/siyuan/kernel/cache"
  20. )
  21. type Block struct {
  22. ID string
  23. ParentID string
  24. RootID string
  25. Hash string
  26. Box string
  27. Path string
  28. HPath string
  29. Name string
  30. Alias string
  31. Memo string
  32. Tag string
  33. Content string
  34. FContent string
  35. Markdown string
  36. Length int
  37. Type string
  38. SubType string
  39. IAL string
  40. Sort int
  41. Created string
  42. Updated string
  43. }
  44. func updateRootContent(tx *sql.Tx, content, updated, id string) (err error) {
  45. stmt := "UPDATE blocks SET content = ?, fcontent = ?, updated = ? WHERE id = ?"
  46. if err = execStmtTx(tx, stmt, content, content, updated, id); nil != err {
  47. return
  48. }
  49. stmt = "UPDATE blocks_fts SET content = ?, fcontent = ?, updated = ? WHERE id = ?"
  50. if err = execStmtTx(tx, stmt, content, content, updated, id); nil != err {
  51. return
  52. }
  53. if !caseSensitive {
  54. stmt = "UPDATE blocks_fts_case_insensitive SET content = ?, fcontent = ?, updated = ? WHERE id = ?"
  55. if err = execStmtTx(tx, stmt, content, content, updated, id); nil != err {
  56. return
  57. }
  58. }
  59. removeBlockCache(id)
  60. cache.RemoveBlockIAL(id)
  61. return
  62. }
  63. func updateBlockContent(tx *sql.Tx, block *Block) (err error) {
  64. stmt := "UPDATE blocks SET content = ? WHERE id = ?"
  65. if err = execStmtTx(tx, stmt, block.Content, block.ID); nil != err {
  66. tx.Rollback()
  67. return
  68. }
  69. stmt = "UPDATE blocks_fts SET content = ? WHERE id = ?"
  70. if err = execStmtTx(tx, stmt, block.Content, block.ID); nil != err {
  71. tx.Rollback()
  72. return
  73. }
  74. if !caseSensitive {
  75. stmt = "UPDATE blocks_fts_case_insensitive SET content = ? WHERE id = ?"
  76. if err = execStmtTx(tx, stmt, block.Content, block.ID); nil != err {
  77. tx.Rollback()
  78. return
  79. }
  80. }
  81. putBlockCache(block)
  82. return
  83. }