mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	unified SQL syntax to uppercase
This commit is contained in:
		| @@ -38,7 +38,7 @@ const addLink = (function() { | |||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|             // this is called when user goes through autocomplete list with keyboard |             // this is called when user goes through autocomplete list with keyboard | ||||||
|             // at this point the item isn't selected yet so we use supplied ui.item to see where the cursor is |             // at this point the item isn't selected yet so we use supplied ui.item to see WHERE the cursor is | ||||||
|             focus: (event, ui) => { |             focus: (event, ui) => { | ||||||
|                 const noteId = link.getNodePathFromLabel(ui.item.value); |                 const noteId = link.getNodePathFromLabel(ui.item.value); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -123,7 +123,7 @@ const noteEditor = (function() { | |||||||
|  |  | ||||||
|     async function createNote(node, parentTreeId, target, isProtected) { |     async function createNote(node, parentTreeId, target, isProtected) { | ||||||
|         // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted |         // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted | ||||||
|         // but this is quite weird since user doesn't see where the note is being created so it shouldn't occur often |         // but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often | ||||||
|         if (!isProtected || !protected_session.isProtectedSessionAvailable()) { |         if (!isProtected || !protected_session.isProtectedSessionAvailable()) { | ||||||
|             isProtected = false; |             isProtected = false; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ const sync_table = require('../../services/sync_table'); | |||||||
|  |  | ||||||
| router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => { | router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => { | ||||||
|     const noteId = req.params.noteId; |     const noteId = req.params.noteId; | ||||||
|     const history = await sql.getResults("select * from notes_history where note_id = ? order by date_modified_to desc", [noteId]); |     const history = await sql.getResults("SELECT * FROM notes_history WHERE note_id = ? order by date_modified_to desc", [noteId]); | ||||||
|  |  | ||||||
|     const dataKey = protected_session.getDataKey(req); |     const dataKey = protected_session.getDataKey(req); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ const RequestContext = require('../../services/request_context'); | |||||||
| router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => { | router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => { | ||||||
|     const noteId = req.params.noteId; |     const noteId = req.params.noteId; | ||||||
|  |  | ||||||
|     const detail = await sql.getSingleResult("select * from notes where note_id = ?", [noteId]); |     const detail = await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [noteId]); | ||||||
|  |  | ||||||
|     if (detail.is_protected) { |     if (detail.is_protected) { | ||||||
|         const dataKey = protected_session.getDataKey(req); |         const dataKey = protected_session.getDataKey(req); | ||||||
| @@ -24,7 +24,7 @@ router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => { | |||||||
|  |  | ||||||
|     res.send({ |     res.send({ | ||||||
|         detail: detail, |         detail: detail, | ||||||
|         images: await sql.getResults("select * from images where note_id = ? order by note_offset", [detail.note_id]), |         images: await sql.getResults("SELECT * FROM images WHERE note_id = ? order by note_offset", [detail.note_id]), | ||||||
|         loadTime: utils.nowTimestamp() |         loadTime: utils.nowTimestamp() | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
| @@ -65,7 +65,7 @@ router.delete('/:noteTreeId', async (req, res, next) => { | |||||||
| router.get('/', async (req, res, next) => { | router.get('/', async (req, res, next) => { | ||||||
|     const search = '%' + req.query.search + '%'; |     const search = '%' + req.query.search + '%'; | ||||||
|  |  | ||||||
|     const result = await sql.getResults("select note_id from notes where note_title like ? or note_text like ?", [search, search]); |     const result = await sql.getResults("SELECT note_id FROM notes WHERE note_title liKE ? OR note_text LIKE ?", [search, search]); | ||||||
|  |  | ||||||
|     const noteIdList = []; |     const noteIdList = []; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,13 +12,13 @@ router.put('/:noteTreeId/moveTo/:parentNoteId', auth.checkApiAuth, async (req, r | |||||||
|     const noteTreeId = req.params.noteTreeId; |     const noteTreeId = req.params.noteTreeId; | ||||||
|     const parentNoteId = req.params.parentNoteId; |     const parentNoteId = req.params.parentNoteId; | ||||||
|  |  | ||||||
|     const maxNotePos = await sql.getSingleValue('select max(note_pos) from notes_tree where note_pid = ? and is_deleted = 0', [parentNoteId]); |     const maxNotePos = await sql.getSingleValue('SELECT MAX(note_pos) FROM notes_tree WHERE note_pid = ? AND is_deleted = 0', [parentNoteId]); | ||||||
|     const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1; |     const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1; | ||||||
|  |  | ||||||
|     const now = utils.nowTimestamp(); |     const now = utils.nowTimestamp(); | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     await sql.doInTransaction(async () => { | ||||||
|         await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_tree_id = ?", |         await sql.execute("UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?", | ||||||
|             [parentNoteId, newNotePos, now, noteTreeId]); |             [parentNoteId, newNotePos, now, noteTreeId]); | ||||||
|  |  | ||||||
|         await sync_table.addNoteTreeSync(noteTreeId); |         await sync_table.addNoteTreeSync(noteTreeId); | ||||||
| @@ -32,17 +32,17 @@ router.put('/:noteTreeId/moveBefore/:beforeNoteTreeId', async (req, res, next) = | |||||||
|     const noteTreeId = req.params.noteTreeId; |     const noteTreeId = req.params.noteTreeId; | ||||||
|     const beforeNoteTreeId = req.params.beforeNoteTreeId; |     const beforeNoteTreeId = req.params.beforeNoteTreeId; | ||||||
|  |  | ||||||
|     const beforeNote = await sql.getSingleResult("select * from notes_tree where note_tree_id = ?", [beforeNoteTreeId]); |     const beforeNote = await sql.getSingleResult("SELECT * FROM notes_tree WHERE note_tree_id = ?", [beforeNoteTreeId]); | ||||||
|  |  | ||||||
|     if (beforeNote) { |     if (beforeNote) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.doInTransaction(async () => { | ||||||
|             // we don't change date_modified so other changes are prioritized in case of conflict |             // we don't change date_modified so other changes are prioritized in case of conflict | ||||||
|             await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos >= ? and is_deleted = 0", |             await sql.execute("UPDATE notes_tree SET note_pos = note_pos + 1 WHERE note_pid = ? AND note_pos >= ? AND is_deleted = 0", | ||||||
|                 [beforeNote.note_pid, beforeNote.note_pos]); |                 [beforeNote.note_pid, beforeNote.note_pos]); | ||||||
|  |  | ||||||
|             const now = utils.nowTimestamp(); |             const now = utils.nowTimestamp(); | ||||||
|  |  | ||||||
|             await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_tree_id = ?", |             await sql.execute("UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?", | ||||||
|                 [beforeNote.note_pid, beforeNote.note_pos, now, noteTreeId]); |                 [beforeNote.note_pid, beforeNote.note_pos, now, noteTreeId]); | ||||||
|  |  | ||||||
|             await sync_table.addNoteTreeSync(noteTreeId); |             await sync_table.addNoteTreeSync(noteTreeId); | ||||||
| @@ -61,17 +61,17 @@ router.put('/:noteTreeId/moveAfter/:afterNoteTreeId', async (req, res, next) => | |||||||
|     const noteTreeId = req.params.noteTreeId; |     const noteTreeId = req.params.noteTreeId; | ||||||
|     const afterNoteTreeId = req.params.afterNoteTreeId; |     const afterNoteTreeId = req.params.afterNoteTreeId; | ||||||
|  |  | ||||||
|     const afterNote = await sql.getSingleResult("select * from notes_tree where note_tree_id = ?", [afterNoteTreeId]); |     const afterNote = await sql.getSingleResult("SELECT * FROM notes_tree WHERE note_tree_id = ?", [afterNoteTreeId]); | ||||||
|  |  | ||||||
|     if (afterNote) { |     if (afterNote) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.doInTransaction(async () => { | ||||||
|             // we don't change date_modified so other changes are prioritized in case of conflict |             // we don't change date_modified so other changes are prioritized in case of conflict | ||||||
|             await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos > ? and is_deleted = 0", |             await sql.execute("UPDATE notes_tree SET note_pos = note_pos + 1 WHERE note_pid = ? AND note_pos > ? AND is_deleted = 0", | ||||||
|                 [afterNote.note_pid, afterNote.note_pos]); |                 [afterNote.note_pid, afterNote.note_pos]); | ||||||
|  |  | ||||||
|             const now = utils.nowTimestamp(); |             const now = utils.nowTimestamp(); | ||||||
|  |  | ||||||
|             await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_tree_id = ?", |             await sql.execute("UPDATE notes_tree SET note_pid = ?, note_pos = ?, date_modified = ? WHERE note_tree_id = ?", | ||||||
|                 [afterNote.note_pid, afterNote.note_pos + 1, now, noteTreeId]); |                 [afterNote.note_pid, afterNote.note_pos + 1, now, noteTreeId]); | ||||||
|  |  | ||||||
|             await sync_table.addNoteTreeSync(noteTreeId); |             await sync_table.addNoteTreeSync(noteTreeId); | ||||||
| @@ -91,7 +91,7 @@ router.put('/:noteTreeId/expanded/:expanded', async (req, res, next) => { | |||||||
|     const expanded = req.params.expanded; |     const expanded = req.params.expanded; | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     await sql.doInTransaction(async () => { | ||||||
|         await sql.execute("update notes_tree set is_expanded = ? where note_tree_id = ?", [expanded, noteTreeId]); |         await sql.execute("UPDATE notes_tree SET is_expanded = ? WHERE note_tree_id = ?", [expanded, noteTreeId]); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     res.send({}); |     res.send({}); | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ const sql = require('../../services/sql'); | |||||||
| const auth = require('../../services/auth'); | const auth = require('../../services/auth'); | ||||||
|  |  | ||||||
| router.get('/', auth.checkApiAuth, async (req, res, next) => { | router.get('/', auth.checkApiAuth, async (req, res, next) => { | ||||||
|     const recentChanges = await sql.getResults("select * from notes_history order by date_modified_to desc limit 1000"); |     const recentChanges = await sql.getResults("SELECT * FROM notes_history order by date_modified_to desc limit 1000"); | ||||||
|  |  | ||||||
|     res.send(recentChanges); |     res.send(recentChanges); | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -12,14 +12,14 @@ const notes = require('../../services/notes'); | |||||||
| const sync_table = require('../../services/sync_table'); | const sync_table = require('../../services/sync_table'); | ||||||
|  |  | ||||||
| router.get('/', auth.checkApiAuth, async (req, res, next) => { | router.get('/', auth.checkApiAuth, async (req, res, next) => { | ||||||
|     const notes = await sql.getResults("select " |     const notes = await sql.getResults("SELECT " | ||||||
|         + "notes_tree.*, " |         + "notes_tree.*, " | ||||||
|         + "notes.note_title, " |         + "notes.note_title, " | ||||||
|         + "notes.is_protected " |         + "notes.is_protected " | ||||||
|         + "from notes_tree " |         + "FROM notes_tree " | ||||||
|         + "join notes on notes.note_id = notes_tree.note_id " |         + "JOIN notes ON notes.note_id = notes_tree.note_id " | ||||||
|         + "where notes.is_deleted = 0 and notes_tree.is_deleted = 0 " |         + "WHERE notes.is_deleted = 0 AND notes_tree.is_deleted = 0 " | ||||||
|         + "order by note_pos"); |         + "ORDER BY note_pos"); | ||||||
|  |  | ||||||
|     const dataKey = protected_session.getDataKey(req); |     const dataKey = protected_session.getDataKey(req); | ||||||
|  |  | ||||||
| @@ -52,10 +52,10 @@ router.put('/:parentNoteId/addChild/:childNoteId', auth.checkApiAuth, async (req | |||||||
|     const parentNoteId = req.params.parentNoteId; |     const parentNoteId = req.params.parentNoteId; | ||||||
|     const childNoteId = req.params.childNoteId; |     const childNoteId = req.params.childNoteId; | ||||||
|  |  | ||||||
|     const existing = await sql.getSingleValue('select * from notes_tree where note_id = ? and note_pid = ?', [childNoteId, parentNoteId]); |     const existing = await sql.getSingleValue('SELECT * FROM notes_tree WHERE note_id = ? AND note_pid = ?', [childNoteId, parentNoteId]); | ||||||
|  |  | ||||||
|     if (!existing) { |     if (!existing) { | ||||||
|         const maxNotePos = await sql.getSingleValue('select max(note_pos) from notes_tree where note_pid = ? and is_deleted = 0', [parentNoteId]); |         const maxNotePos = await sql.getSingleValue('SELECT MAX(note_pos) FROM notes_tree WHERE note_pid = ? AND is_deleted = 0', [parentNoteId]); | ||||||
|         const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1; |         const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1; | ||||||
|  |  | ||||||
|         const noteTreeId = utils.newNoteTreeId(); |         const noteTreeId = utils.newNoteTreeId(); | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
| module.exports = { | module.exports = { | ||||||
|     UPDATE_CONTENT: 'CONTENT', |     UPDATE_CONTENT: 'CONTENT', | ||||||
|     UPDATE_TITLE: 'TITLE', |     UPDATE_TITLE: 'TITLE', | ||||||
|     // associated noteId is parent of notes where position changes happened |     // associated noteId is parent of notes WHERE position changes happened | ||||||
|     CHANGE_POSITION: 'POSITION', |     CHANGE_POSITION: 'POSITION', | ||||||
|     CHANGE_EXPANDED: 'EXPANDED', |     CHANGE_EXPANDED: 'EXPANDED', | ||||||
|     CREATE_NOTE: 'CREATE', |     CREATE_NOTE: 'CREATE', | ||||||
|   | |||||||
| @@ -13,16 +13,16 @@ async function createNewNote(parentNoteId, note, browserId) { | |||||||
|     let newNotePos = 0; |     let newNotePos = 0; | ||||||
|  |  | ||||||
|     if (note.target === 'into') { |     if (note.target === 'into') { | ||||||
|         const maxNotePos = await sql.getSingleValue('select max(note_pos) from notes_tree where note_pid = ? and is_deleted = 0', [parentNoteId]); |         const maxNotePos = await sql.getSingleValue('SELECT MAX(note_pos) FROM notes_tree WHERE note_pid = ? AND is_deleted = 0', [parentNoteId]); | ||||||
|  |  | ||||||
|         newNotePos = maxNotePos === null ? 0 : maxNotePos + 1; |         newNotePos = maxNotePos === null ? 0 : maxNotePos + 1; | ||||||
|     } |     } | ||||||
|     else if (note.target === 'after') { |     else if (note.target === 'after') { | ||||||
|         const afterNote = await sql.getSingleResult('select note_pos from notes_tree where note_id = ?', [note.target_note_id]); |         const afterNote = await sql.getSingleResult('SELECT note_pos FROM notes_tree WHERE note_id = ?', [note.target_note_id]); | ||||||
|  |  | ||||||
|         newNotePos = afterNote.note_pos + 1; |         newNotePos = afterNote.note_pos + 1; | ||||||
|  |  | ||||||
|         await sql.execute('update notes_tree set note_pos = note_pos + 1, date_modified = ? where note_pid = ? and note_pos > ? and is_deleted = 0', |         await sql.execute('UPDATE notes_tree SET note_pos = note_pos + 1, date_modified = ? WHERE note_pid = ? AND note_pos > ? AND is_deleted = 0', | ||||||
|             [utils.nowTimestamp(), parentNoteId, afterNote.note_pos]); |             [utils.nowTimestamp(), parentNoteId, afterNote.note_pos]); | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
| @@ -139,7 +139,7 @@ async function updateNote(noteId, newNote, ctx) { | |||||||
|         await encryptNote(newNote, ctx); |         await encryptNote(newNote, ctx); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const origNoteDetail = await sql.getSingleResult("select * from notes where note_id = ?", [noteId]); |     const origNoteDetail = await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [noteId]); | ||||||
|  |  | ||||||
|     const now = utils.nowTimestamp(); |     const now = utils.nowTimestamp(); | ||||||
|  |  | ||||||
| @@ -147,22 +147,21 @@ async function updateNote(noteId, newNote, ctx) { | |||||||
|  |  | ||||||
|     const historyCutoff = now - historySnapshotTimeInterval; |     const historyCutoff = now - historySnapshotTimeInterval; | ||||||
|  |  | ||||||
|     const existingNoteHistoryId = await sql.getSingleValue("select note_history_id from notes_history where note_id = ? and date_modified_from >= ?", [noteId, historyCutoff]); |     const existingNoteHistoryId = await sql.getSingleValue("SELECT note_history_id FROM notes_history WHERE note_id = ? AND date_modified_from >= ?", [noteId, historyCutoff]); | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     await sql.doInTransaction(async () => { | ||||||
|         if (!existingNoteHistoryId) { |         if (!existingNoteHistoryId) { | ||||||
|             const newNoteHistoryId = utils.newNoteHistoryId(); |             const newNoteHistoryId = utils.newNoteHistoryId(); | ||||||
|  |  | ||||||
|             await sql.execute("insert into notes_history (note_history_id, note_id, note_title, note_text, is_protected, date_modified_from, date_modified_to) " + |             await sql.insert('notes_history', { | ||||||
|                 "values (?, ?, ?, ?, ?, ?, ?)", [ |                 note_history_id: newNoteHistoryId, | ||||||
|                 newNoteHistoryId, |                 note_id: noteId, | ||||||
|                 noteId, |                 note_title: noteTitleForHistory, | ||||||
|                 noteTitleForHistory, |                 note_text: noteTextForHistory, | ||||||
|                 noteTextForHistory, |                 is_protected: false, // we don't care about encryption - this will be handled in protectNoteHistory() | ||||||
|                 false, // we don't care about encryption - this will be handled in protectNoteHistory() |                 date_modified_from: now, | ||||||
|                 now, |                 date_modified_to: now | ||||||
|                 now |             }); | ||||||
|             ]); |  | ||||||
|  |  | ||||||
|             await sync_table.addNoteHistorySync(newNoteHistoryId); |             await sync_table.addNoteHistorySync(newNoteHistoryId); | ||||||
|         } |         } | ||||||
| @@ -171,7 +170,7 @@ async function updateNote(noteId, newNote, ctx) { | |||||||
|  |  | ||||||
|         await addNoteAudits(origNoteDetail, newNote.detail, ctx.browserId); |         await addNoteAudits(origNoteDetail, newNote.detail, ctx.browserId); | ||||||
|  |  | ||||||
|         await sql.execute("update notes set note_title = ?, note_text = ?, is_protected = ?, date_modified = ? where note_id = ?", [ |         await sql.execute("UPDATE notes SET note_title = ?, note_text = ?, is_protected = ?, date_modified = ? WHERE note_id = ?", [ | ||||||
|             newNote.detail.note_title, |             newNote.detail.note_title, | ||||||
|             newNote.detail.note_text, |             newNote.detail.note_text, | ||||||
|             newNote.detail.is_protected, |             newNote.detail.is_protected, | ||||||
| @@ -220,7 +219,7 @@ async function addNoteAudits(origNote, newNote, browserId) { | |||||||
|  |  | ||||||
| async function deleteNote(noteTreeId, browserId) { | async function deleteNote(noteTreeId, browserId) { | ||||||
|     const now = utils.nowTimestamp(); |     const now = utils.nowTimestamp(); | ||||||
|     await sql.execute("update notes_tree set is_deleted = 1, date_modified = ? where note_tree_id = ?", [now, noteTreeId]); |     await sql.execute("UPDATE notes_tree SET is_deleted = 1, date_modified = ? WHERE note_tree_id = ?", [now, noteTreeId]); | ||||||
|     await sync_table.addNoteTreeSync(noteTreeId); |     await sync_table.addNoteTreeSync(noteTreeId); | ||||||
|  |  | ||||||
|     const noteId = await sql.getSingleValue("SELECT note_id FROM notes_tree WHERE note_tree_id = ?", [noteTreeId]); |     const noteId = await sql.getSingleValue("SELECT note_id FROM notes_tree WHERE note_tree_id = ?", [noteTreeId]); | ||||||
| @@ -228,10 +227,10 @@ async function deleteNote(noteTreeId, browserId) { | |||||||
|     const notDeletedNoteTreesCount = await sql.getSingleValue("SELECT COUNT(*) FROM notes_tree WHERE note_id = ?", [noteId]); |     const notDeletedNoteTreesCount = await sql.getSingleValue("SELECT COUNT(*) FROM notes_tree WHERE note_id = ?", [noteId]); | ||||||
|  |  | ||||||
|     if (!notDeletedNoteTreesCount) { |     if (!notDeletedNoteTreesCount) { | ||||||
|         await sql.execute("update notes set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteTreeId]); |         await sql.execute("UPDATE notes SET is_deleted = 1, date_modified = ? WHERE note_id = ?", [now, noteTreeId]); | ||||||
|         await sync_table.addNoteSync(noteTreeId); |         await sync_table.addNoteSync(noteTreeId); | ||||||
|  |  | ||||||
|         const children = await sql.getResults("select note_tree_id from notes_tree where note_pid = ? and is_deleted = 0", [noteTreeId]); |         const children = await sql.getResults("SELECT note_tree_id FROM notes_tree WHERE note_pid = ? AND is_deleted = 0", [noteTreeId]); | ||||||
|  |  | ||||||
|         for (const child of children) { |         for (const child of children) { | ||||||
|             await deleteNote(child.note_tree_id, browserId); |             await deleteNote(child.note_tree_id, browserId); | ||||||
|   | |||||||
| @@ -110,8 +110,16 @@ async function addAudit(category, browserId=null, noteId=null, changeFrom=null, | |||||||
|  |  | ||||||
|     const id = utils.randomString(14); |     const id = utils.randomString(14); | ||||||
|  |  | ||||||
|     await execute("INSERT INTO audit_log (id, date_modified, category, browser_id, note_id, change_from, change_to, comment)" |     await insert("audit_log", { | ||||||
|         + " VALUES (?, ?, ?, ?, ?, ?, ?, ?)", [id, now, category, browserId, noteId, changeFrom, changeTo, comment]); |         id: id, | ||||||
|  |         date_modified: now, | ||||||
|  |         category: category, | ||||||
|  |         browser_id: browserId, | ||||||
|  |         note_id: noteId, | ||||||
|  |         change_from: changeFrom, | ||||||
|  |         change_to: changeTo, | ||||||
|  |         comment: comment | ||||||
|  |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function deleteRecentAudits(category, browserId, noteId) { | async function deleteRecentAudits(category, browserId, noteId) { | ||||||
|   | |||||||
| @@ -217,7 +217,7 @@ async function sendEntity(syncContext, entity, entityName) { | |||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     if (entityName === 'notes') { |     if (entityName === 'notes') { | ||||||
|         payload.links = await sql.getResults('select * from links where note_id = ?', [entity.note_id]); |         payload.links = await sql.getResults('SELECT * FROM links WHERE note_id = ?', [entity.note_id]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     await syncRequest(syncContext, 'PUT', '/api/sync/' + entityName, payload); |     await syncRequest(syncContext, 'PUT', '/api/sync/' + entityName, payload); | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ const notes = require('./notes'); | |||||||
| const sync_table = require('./sync_table'); | const sync_table = require('./sync_table'); | ||||||
|  |  | ||||||
| async function updateNote(entity, links, sourceId) { | async function updateNote(entity, links, sourceId) { | ||||||
|     const origNote = await sql.getSingleResult("select * from notes where note_id = ?", [entity.note_id]); |     const origNote = await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [entity.note_id]); | ||||||
|  |  | ||||||
|     if (!origNote || origNote.date_modified <= entity.date_modified) { |     if (!origNote || origNote.date_modified <= entity.date_modified) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.doInTransaction(async () => { | ||||||
| @@ -35,7 +35,7 @@ async function updateNote(entity, links, sourceId) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function updateNoteTree(entity, sourceId) { | async function updateNoteTree(entity, sourceId) { | ||||||
|     const orig = await sql.getSingleResultOrNull("select * from notes_tree where note_tree_id = ?", [entity.note_tree_id]); |     const orig = await sql.getSingleResultOrNull("SELECT * FROM notes_tree WHERE note_tree_id = ?", [entity.note_tree_id]); | ||||||
|  |  | ||||||
|     if (orig === null || orig.date_modified < entity.date_modified) { |     if (orig === null || orig.date_modified < entity.date_modified) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.doInTransaction(async () => { | ||||||
| @@ -57,7 +57,7 @@ async function updateNoteTree(entity, sourceId) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function updateNoteHistory(entity, sourceId) { | async function updateNoteHistory(entity, sourceId) { | ||||||
|     const orig = await sql.getSingleResultOrNull("select * from notes_history where note_history_id = ?", [entity.note_history_id]); |     const orig = await sql.getSingleResultOrNull("SELECT * FROM notes_history WHERE note_history_id = ?", [entity.note_history_id]); | ||||||
|  |  | ||||||
|     if (orig === null || orig.date_modified_to < entity.date_modified_to) { |     if (orig === null || orig.date_modified_to < entity.date_modified_to) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.doInTransaction(async () => { | ||||||
| @@ -89,7 +89,7 @@ async function updateOptions(entity, sourceId) { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const orig = await sql.getSingleResultOrNull("select * from options where opt_name = ?", [entity.opt_name]); |     const orig = await sql.getSingleResultOrNull("SELECT * FROM options WHERE opt_name = ?", [entity.opt_name]); | ||||||
|  |  | ||||||
|     if (orig === null || orig.date_modified < entity.date_modified) { |     if (orig === null || orig.date_modified < entity.date_modified) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.doInTransaction(async () => { | ||||||
| @@ -106,7 +106,7 @@ async function updateOptions(entity, sourceId) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function updateRecentNotes(entity, sourceId) { | async function updateRecentNotes(entity, sourceId) { | ||||||
|     const orig = await sql.getSingleResultOrNull("select * from recent_notes where note_path = ?", [entity.note_path]); |     const orig = await sql.getSingleResultOrNull("SELECT * FROM recent_notes WHERE note_path = ?", [entity.note_path]); | ||||||
|  |  | ||||||
|     if (orig === null || orig.date_accessed < entity.date_accessed) { |     if (orig === null || orig.date_accessed < entity.date_accessed) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.doInTransaction(async () => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user