diff --git a/db/migrations/0216__move_content_into_blobs.ts b/db/migrations/0216__move_content_into_blobs.ts index f37e570f2..c10fcc780 100644 --- a/db/migrations/0216__move_content_into_blobs.ts +++ b/db/migrations/0216__move_content_into_blobs.ts @@ -17,8 +17,8 @@ interface NoteRevisionContents { export default () => { const existingBlobIds = new Set(); - for (const noteId of sql.getColumn(`SELECT noteId FROM note_contents`)) { - const row = sql.getRow(`SELECT noteId, content, dateModified, utcDateModified FROM note_contents WHERE noteId = ?`, [noteId]); + for (const noteId of sql.getColumn(/*sql*/`SELECT noteId FROM note_contents`)) { + const row = sql.getRow(/*sql*/`SELECT noteId, content, dateModified, utcDateModified FROM note_contents WHERE noteId = ?`, [noteId]); const blobId = utils.hashedBlobId(row.content); if (!existingBlobIds.has(blobId)) { @@ -40,8 +40,8 @@ export default () => { sql.execute("UPDATE notes SET blobId = ? WHERE noteId = ?", [blobId, row.noteId]); } - for (const noteRevisionId of sql.getColumn(`SELECT noteRevisionId FROM note_revision_contents`)) { - const row = sql.getRow(`SELECT noteRevisionId, content, utcDateModified FROM note_revision_contents WHERE noteRevisionId = ?`, [noteRevisionId]); + for (const noteRevisionId of sql.getColumn(/*sql*/`SELECT noteRevisionId FROM note_revision_contents`)) { + const row = sql.getRow(/*sql*/`SELECT noteRevisionId, content, utcDateModified FROM note_revision_contents WHERE noteRevisionId = ?`, [noteRevisionId]); const blobId = utils.hashedBlobId(row.content); if (!existingBlobIds.has(blobId)) { diff --git a/db/migrations/0220__migrate_images_to_attachments.ts b/db/migrations/0220__migrate_images_to_attachments.ts index 53eac5958..f54f4a956 100644 --- a/db/migrations/0220__migrate_images_to_attachments.ts +++ b/db/migrations/0220__migrate_images_to_attachments.ts @@ -7,7 +7,7 @@ import sql from "../../src/services/sql"; export default () => { cls.init(() => { // emergency disabling of image compression since it appears to make problems in migration to 0.61 - sql.execute(`UPDATE options SET value = 'false' WHERE name = 'compressImages'`); + sql.execute(/*sql*/`UPDATE options SET value = 'false' WHERE name = 'compressImages'`); becca_loader.load(); diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index cdee5d1cd..3bc470b5c 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -171,11 +171,11 @@ export default class Becca { opts.includeContentLength = !!opts.includeContentLength; const query = opts.includeContentLength - ? `SELECT attachments.*, LENGTH(blobs.content) AS contentLength + ? /*sql*/`SELECT attachments.*, LENGTH(blobs.content) AS contentLength FROM attachments JOIN blobs USING (blobId) WHERE attachmentId = ? AND isDeleted = 0` - : `SELECT * FROM attachments WHERE attachmentId = ? AND isDeleted = 0`; + : /*sql*/`SELECT * FROM attachments WHERE attachmentId = ? AND isDeleted = 0`; return sql.getRows(query, [attachmentId]).map((row) => new BAttachment(row))[0]; } diff --git a/src/becca/becca_loader.ts b/src/becca/becca_loader.ts index 8397b2dec..4e6154e4a 100644 --- a/src/becca/becca_loader.ts +++ b/src/becca/becca_loader.ts @@ -40,11 +40,11 @@ function load() { // using a raw query and passing arrays to avoid allocating new objects, // this is worth it for the becca load since it happens every run and blocks the app until finished - for (const row of sql.getRawRows(`SELECT noteId, title, type, mime, isProtected, blobId, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes WHERE isDeleted = 0`)) { + for (const row of sql.getRawRows(/*sql*/`SELECT noteId, title, type, mime, isProtected, blobId, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes WHERE isDeleted = 0`)) { new BNote().update(row).init(); } - const branchRows = sql.getRawRows(`SELECT branchId, noteId, parentNoteId, prefix, notePosition, isExpanded, utcDateModified FROM branches WHERE isDeleted = 0`); + const branchRows = sql.getRawRows(/*sql*/`SELECT branchId, noteId, parentNoteId, prefix, notePosition, isExpanded, utcDateModified FROM branches WHERE isDeleted = 0`); // in-memory sort is faster than in the DB branchRows.sort((a, b) => (a.notePosition || 0) - (b.notePosition || 0)); @@ -52,15 +52,15 @@ function load() { new BBranch().update(row).init(); } - for (const row of sql.getRawRows(`SELECT attributeId, noteId, type, name, value, isInheritable, position, utcDateModified FROM attributes WHERE isDeleted = 0`)) { + for (const row of sql.getRawRows(/*sql*/`SELECT attributeId, noteId, type, name, value, isInheritable, position, utcDateModified FROM attributes WHERE isDeleted = 0`)) { new BAttribute().update(row).init(); } - for (const row of sql.getRows(`SELECT name, value, isSynced, utcDateModified FROM options`)) { + for (const row of sql.getRows(/*sql*/`SELECT name, value, isSynced, utcDateModified FROM options`)) { new BOption(row); } - for (const row of sql.getRows(`SELECT etapiTokenId, name, tokenHash, utcDateCreated, utcDateModified FROM etapi_tokens WHERE isDeleted = 0`)) { + for (const row of sql.getRows(/*sql*/`SELECT etapiTokenId, name, tokenHash, utcDateCreated, utcDateModified FROM etapi_tokens WHERE isDeleted = 0`)) { new BEtapiToken(row); } }); diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index a36132f3a..1f3bd0d86 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -259,7 +259,7 @@ abstract class AbstractBeccaEntity> { } protected _getContent(): string | Buffer { - const row = sql.getRow<{ content: string | Buffer }>(`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); + const row = sql.getRow<{ content: string | Buffer }>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); if (!row) { const constructorData = this.constructor as unknown as ConstructorData; @@ -282,7 +282,7 @@ abstract class AbstractBeccaEntity> { this.utcDateModified = dateUtils.utcNowDateTime(); sql.execute( - `UPDATE ${entityName} SET isDeleted = 1, deleteId = ?, utcDateModified = ? + /*sql*/`UPDATE ${entityName} SET isDeleted = 1, deleteId = ?, utcDateModified = ? WHERE ${constructorData.primaryKeyName} = ?`, [deleteId, this.utcDateModified, entityId] ); @@ -290,7 +290,7 @@ abstract class AbstractBeccaEntity> { if (this.dateModified) { this.dateModified = dateUtils.localNowDateTime(); - sql.execute(`UPDATE ${entityName} SET dateModified = ? WHERE ${constructorData.primaryKeyName} = ?`, [this.dateModified, entityId]); + sql.execute(/*sql*/`UPDATE ${entityName} SET dateModified = ? WHERE ${constructorData.primaryKeyName} = ?`, [this.dateModified, entityId]); } log.info(`Marking ${entityName} ${entityId} as deleted`); @@ -308,7 +308,7 @@ abstract class AbstractBeccaEntity> { this.utcDateModified = dateUtils.utcNowDateTime(); sql.execute( - `UPDATE ${entityName} SET isDeleted = 1, utcDateModified = ? + /*sql*/`UPDATE ${entityName} SET isDeleted = 1, utcDateModified = ? WHERE ${constructorData.primaryKeyName} = ?`, [this.utcDateModified, entityId] ); diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts index 9461647af..b4d0c4d18 100644 --- a/src/becca/entities/battachment.ts +++ b/src/becca/entities/battachment.ts @@ -210,7 +210,7 @@ class BAttachment extends AbstractBeccaEntity { this.position = 10 + sql.getValue( - `SELECT COALESCE(MAX(position), 0) + /*sql*/`SELECT COALESCE(MAX(position), 0) FROM attachments WHERE ownerId = ?`, [this.noteId] diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index 720e954e5..cda4d5f2f 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -1108,12 +1108,12 @@ class BNote extends AbstractBeccaEntity { // given that we're always fetching attachments only for a specific note, we might just do it always const query = opts.includeContentLength - ? `SELECT attachments.*, LENGTH(blobs.content) AS contentLength + ? /*sql*/`SELECT attachments.*, LENGTH(blobs.content) AS contentLength FROM attachments JOIN blobs USING (blobId) WHERE ownerId = ? AND isDeleted = 0 ORDER BY position` - : `SELECT * FROM attachments WHERE ownerId = ? AND isDeleted = 0 ORDER BY position`; + : /*sql*/`SELECT * FROM attachments WHERE ownerId = ? AND isDeleted = 0 ORDER BY position`; return sql.getRows(query, [this.noteId]).map((row) => new BAttachment(row)); } @@ -1122,11 +1122,11 @@ class BNote extends AbstractBeccaEntity { opts.includeContentLength = !!opts.includeContentLength; const query = opts.includeContentLength - ? `SELECT attachments.*, LENGTH(blobs.content) AS contentLength + ? /*sql*/`SELECT attachments.*, LENGTH(blobs.content) AS contentLength FROM attachments JOIN blobs USING (blobId) WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0` - : `SELECT * FROM attachments WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`; + : /*sql*/`SELECT * FROM attachments WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`; return sql.getRows(query, [this.noteId, attachmentId]).map((row) => new BAttachment(row))[0]; } diff --git a/src/becca/entities/brevision.ts b/src/becca/entities/brevision.ts index bc9ce360c..de5dcd19f 100644 --- a/src/becca/entities/brevision.ts +++ b/src/becca/entities/brevision.ts @@ -141,11 +141,11 @@ class BRevision extends AbstractBeccaEntity { opts.includeContentLength = !!opts.includeContentLength; const query = opts.includeContentLength - ? `SELECT attachments.*, LENGTH(blobs.content) AS contentLength + ? /*sql*/`SELECT attachments.*, LENGTH(blobs.content) AS contentLength FROM attachments JOIN blobs USING (blobId) WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0` - : `SELECT * FROM attachments WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`; + : /*sql*/`SELECT * FROM attachments WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`; return sql.getRows(query, [this.revisionId, attachmentId]).map((row) => new BAttachment(row))[0]; } diff --git a/src/routes/api/attributes.ts b/src/routes/api/attributes.ts index b28ca4b4f..7d542ac16 100644 --- a/src/routes/api/attributes.ts +++ b/src/routes/api/attributes.ts @@ -70,7 +70,7 @@ function setNoteAttribute(req: Request) { const noteId = req.params.noteId; const body = req.body; - const attributeId = sql.getValue(`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = ? AND name = ?`, [noteId, body.type, body.name]); + const attributeId = sql.getValue(/*sql*/`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = ? AND name = ?`, [noteId, body.type, body.name]); if (attributeId) { const attr = becca.getAttribute(attributeId); @@ -196,7 +196,7 @@ function createRelation(req: Request) { const targetNoteId = req.params.targetNoteId; const name = req.params.name; - const attributeId = sql.getValue(`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = 'relation' AND name = ? AND value = ?`, [ + const attributeId = sql.getValue(/*sql*/`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = 'relation' AND name = ? AND value = ?`, [ sourceNoteId, name, targetNoteId @@ -220,7 +220,7 @@ function deleteRelation(req: Request) { const targetNoteId = req.params.targetNoteId; const name = req.params.name; - const attributeId = sql.getValue(`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = 'relation' AND name = ? AND value = ?`, [ + const attributeId = sql.getValue(/*sql*/`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = 'relation' AND name = ? AND value = ?`, [ sourceNoteId, name, targetNoteId diff --git a/src/routes/api/autocomplete.ts b/src/routes/api/autocomplete.ts index 584c2c88a..bbe990bcd 100644 --- a/src/routes/api/autocomplete.ts +++ b/src/routes/api/autocomplete.ts @@ -83,7 +83,7 @@ function getRecentNotes(activeNoteId: string) { // Get the total number of notes function getNotesCount(req: Request) { const notesCount = sql.getRow( - `SELECT COUNT(*) AS count FROM notes WHERE isDeleted = 0;`, + /*sql*/`SELECT COUNT(*) AS count FROM notes WHERE isDeleted = 0;`, ) as { count: number }; return notesCount.count; } diff --git a/src/routes/api/branches.ts b/src/routes/api/branches.ts index b81d0cfc0..bed1c93b7 100644 --- a/src/routes/api/branches.ts +++ b/src/routes/api/branches.ts @@ -171,7 +171,7 @@ function setExpandedForSubtree(req: Request) { // root is always expanded branchIds = branchIds.filter((branchId) => branchId !== "none_root"); - sql.executeMany(`UPDATE branches SET isExpanded = ${expanded} WHERE branchId IN (???)`, branchIds); + sql.executeMany(/*sql*/`UPDATE branches SET isExpanded = ${expanded} WHERE branchId IN (???)`, branchIds); for (const branchId of branchIds) { const branch = becca.branches[branchId]; diff --git a/src/routes/api/recent_notes.ts b/src/routes/api/recent_notes.ts index b09e166d7..df56e2e6e 100644 --- a/src/routes/api/recent_notes.ts +++ b/src/routes/api/recent_notes.ts @@ -15,7 +15,7 @@ function addRecentNote(req: Request) { // it's not necessary to run this every time ... const cutOffDate = dateUtils.utcDateTimeStr(new Date(Date.now() - 24 * 3600 * 1000)); - sql.execute(`DELETE FROM recent_notes WHERE utcDateCreated < ?`, [cutOffDate]); + sql.execute(/*sql*/`DELETE FROM recent_notes WHERE utcDateCreated < ?`, [cutOffDate]); } } diff --git a/src/routes/api/relation-map.ts b/src/routes/api/relation-map.ts index 2cf591b50..0f0df6149 100644 --- a/src/routes/api/relation-map.ts +++ b/src/routes/api/relation-map.ts @@ -40,7 +40,7 @@ function getRelationMap(req: Request) { const hideRelationsVal = relationMapNote.getLabelValue("hideRelations"); const hideRelations = !hideRelationsVal ? [] : hideRelationsVal.split(",").map((token) => token.trim()); - const foundNoteIds = sql.getColumn(`SELECT noteId FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds); + const foundNoteIds = sql.getColumn(/*sql*/`SELECT noteId FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds); const notes = becca.getNotes(foundNoteIds); for (const note of notes) { diff --git a/src/routes/api/sql.ts b/src/routes/api/sql.ts index a78c3e2f4..ce2fc5127 100644 --- a/src/routes/api/sql.ts +++ b/src/routes/api/sql.ts @@ -7,7 +7,7 @@ import ValidationError from "../../errors/validation_error.js"; import { safeExtractMessageAndStackFromError } from "../../services/utils.js"; function getSchema() { - const tableNames = sql.getColumn(`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name`); + const tableNames = sql.getColumn(/*sql*/`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name`); const tables = []; for (const tableName of tableNames) { diff --git a/src/services/anonymization.ts b/src/services/anonymization.ts index 2d855130f..e776cecf6 100644 --- a/src/services/anonymization.ts +++ b/src/services/anonymization.ts @@ -35,7 +35,7 @@ VACUUM; } function getLightAnonymizationScript() { - return `UPDATE blobs SET content = 'text' WHERE content IS NOT NULL AND blobId NOT IN ( + return /*sql*/`UPDATE blobs SET content = 'text' WHERE content IS NOT NULL AND blobId NOT IN ( SELECT blobId FROM notes WHERE mime IN ('application/javascript;env=backend', 'application/javascript;env=frontend') UNION ALL SELECT blobId FROM revisions WHERE mime IN ('application/javascript;env=backend', 'application/javascript;env=frontend') diff --git a/src/services/attributes.ts b/src/services/attributes.ts index 43332280e..c87defa43 100644 --- a/src/services/attributes.ts +++ b/src/services/attributes.ts @@ -65,7 +65,7 @@ function getAttributeNames(type: string, nameLike: string) { nameLike = nameLike.toLowerCase(); let names = sql.getColumn( - `SELECT DISTINCT name + /*sql*/`SELECT DISTINCT name FROM attributes WHERE isDeleted = 0 AND type = ? diff --git a/src/services/cloning.ts b/src/services/cloning.ts index 4166d8a11..3c197cdfa 100644 --- a/src/services/cloning.ts +++ b/src/services/cloning.ts @@ -103,7 +103,7 @@ function ensureNoteIsPresentInParent(noteId: string, parentNoteId: string, prefi } function ensureNoteIsAbsentFromParent(noteId: string, parentNoteId: string) { - const branchId = sql.getValue(`SELECT branchId FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0`, [noteId, parentNoteId]); + const branchId = sql.getValue(/*sql*/`SELECT branchId FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0`, [noteId, parentNoteId]); const branch = becca.getBranch(branchId); if (branch) { diff --git a/src/services/consistency_checks.ts b/src/services/consistency_checks.ts index 8e7da9c9e..147d6ae74 100644 --- a/src/services/consistency_checks.ts +++ b/src/services/consistency_checks.ts @@ -375,7 +375,7 @@ class ConsistencyChecks { ({ noteId, parentNoteId }) => { if (this.autoFix) { const branchIds = sql.getColumn( - `SELECT branchId + /*sql*/`SELECT branchId FROM branches WHERE noteId = ? and parentNoteId = ? @@ -729,7 +729,7 @@ class ConsistencyChecks { LEFT JOIN entity_changes ec ON ec.entityName = '${entityName}' AND ec.entityId = ${entityName}.${key} WHERE ec.id IS NULL`, ({ entityId }) => { - const entityRow = sql.getRow(`SELECT * FROM ${entityName} WHERE ${key} = ?`, [entityId]); + const entityRow = sql.getRow(/*sql*/`SELECT * FROM ${entityName} WHERE ${key} = ?`, [entityId]); if (this.autoFix) { entityChangesService.putEntityChange({ @@ -778,7 +778,7 @@ class ConsistencyChecks { AND entity_changes.entityName = '${entityName}'`, ({ id, entityId }) => { if (this.autoFix) { - sql.execute(`DELETE FROM ${entityName} WHERE ${key} = ?`, [entityId]); + sql.execute(/*sql*/`DELETE FROM ${entityName} WHERE ${key} = ?`, [entityId]); this.reloadNeeded = true; @@ -802,7 +802,7 @@ class ConsistencyChecks { } findWronglyNamedAttributes() { - const attrNames = sql.getColumn(`SELECT DISTINCT name FROM attributes`); + const attrNames = sql.getColumn(/*sql*/`SELECT DISTINCT name FROM attributes`); for (const origName of attrNames) { const fixedName = sanitizeAttributeName(origName); @@ -883,7 +883,7 @@ class ConsistencyChecks { runDbDiagnostics() { function getTableRowCount(tableName: string) { - const count = sql.getValue(`SELECT COUNT(1) FROM ${tableName}`); + const count = sql.getValue(/*sql*/`SELECT COUNT(1) FROM ${tableName}`); return `${tableName}: ${count}`; } diff --git a/src/services/entity_changes.ts b/src/services/entity_changes.ts index f3abfba5d..66c2613ce 100644 --- a/src/services/entity_changes.ts +++ b/src/services/entity_changes.ts @@ -60,7 +60,7 @@ function putNoteReorderingEntityChange(parentNoteId: string, componentId?: strin eventService.emit(eventService.ENTITY_CHANGED, { entityName: "note_reordering", - entity: sql.getMap(`SELECT branchId, notePosition FROM branches WHERE isDeleted = 0 AND parentNoteId = ?`, [parentNoteId]) + entity: sql.getMap(/*sql*/`SELECT branchId, notePosition FROM branches WHERE isDeleted = 0 AND parentNoteId = ?`, [parentNoteId]) }); } @@ -73,7 +73,7 @@ function putEntityChangeForOtherInstances(ec: EntityChange) { } function addEntityChangesForSector(entityName: string, sector: string) { - const entityChanges = sql.getRows(`SELECT * FROM entity_changes WHERE entityName = ? AND SUBSTR(entityId, 1, 1) = ?`, [entityName, sector]); + const entityChanges = sql.getRows(/*sql*/`SELECT * FROM entity_changes WHERE entityName = ? AND SUBSTR(entityId, 1, 1) = ?`, [entityName, sector]); let entitiesInserted = entityChanges.length; @@ -125,7 +125,7 @@ function fillEntityChanges(entityName: string, entityPrimaryKey: string, conditi cleanupEntityChangesForMissingEntities(entityName, entityPrimaryKey); sql.transactional(() => { - const entityIds = sql.getColumn(`SELECT ${entityPrimaryKey} FROM ${entityName} ${condition}`); + const entityIds = sql.getColumn(/*sql*/`SELECT ${entityPrimaryKey} FROM ${entityName} ${condition}`); let createdCount = 0; diff --git a/src/services/erase.ts b/src/services/erase.ts index e07cfaa4c..28603e136 100644 --- a/src/services/erase.ts +++ b/src/services/erase.ts @@ -12,19 +12,19 @@ function eraseNotes(noteIdsToErase: string[]) { return; } - sql.executeMany(`DELETE FROM notes WHERE noteId IN (???)`, noteIdsToErase); - setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'notes' AND entityId IN (???)`, noteIdsToErase)); + sql.executeMany(/*sql*/`DELETE FROM notes WHERE noteId IN (???)`, noteIdsToErase); + setEntityChangesAsErased(sql.getManyRows(/*sql*/`SELECT * FROM entity_changes WHERE entityName = 'notes' AND entityId IN (???)`, noteIdsToErase)); // we also need to erase all "dependent" entities of the erased notes - const branchIdsToErase = sql.getManyRows<{ branchId: string }>(`SELECT branchId FROM branches WHERE noteId IN (???)`, noteIdsToErase).map((row) => row.branchId); + const branchIdsToErase = sql.getManyRows<{ branchId: string }>(/*sql*/`SELECT branchId FROM branches WHERE noteId IN (???)`, noteIdsToErase).map((row) => row.branchId); eraseBranches(branchIdsToErase); - const attributeIdsToErase = sql.getManyRows<{ attributeId: string }>(`SELECT attributeId FROM attributes WHERE noteId IN (???)`, noteIdsToErase).map((row) => row.attributeId); + const attributeIdsToErase = sql.getManyRows<{ attributeId: string }>(/*sql*/`SELECT attributeId FROM attributes WHERE noteId IN (???)`, noteIdsToErase).map((row) => row.attributeId); eraseAttributes(attributeIdsToErase); - const revisionIdsToErase = sql.getManyRows<{ revisionId: string }>(`SELECT revisionId FROM revisions WHERE noteId IN (???)`, noteIdsToErase).map((row) => row.revisionId); + const revisionIdsToErase = sql.getManyRows<{ revisionId: string }>(/*sql*/`SELECT revisionId FROM revisions WHERE noteId IN (???)`, noteIdsToErase).map((row) => row.revisionId); eraseRevisions(revisionIdsToErase); @@ -47,9 +47,9 @@ function eraseBranches(branchIdsToErase: string[]) { return; } - sql.executeMany(`DELETE FROM branches WHERE branchId IN (???)`, branchIdsToErase); + sql.executeMany(/*sql*/`DELETE FROM branches WHERE branchId IN (???)`, branchIdsToErase); - setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'branches' AND entityId IN (???)`, branchIdsToErase)); + setEntityChangesAsErased(sql.getManyRows(/*sql*/`SELECT * FROM entity_changes WHERE entityName = 'branches' AND entityId IN (???)`, branchIdsToErase)); log.info(`Erased branches: ${JSON.stringify(branchIdsToErase)}`); } @@ -59,9 +59,9 @@ function eraseAttributes(attributeIdsToErase: string[]) { return; } - sql.executeMany(`DELETE FROM attributes WHERE attributeId IN (???)`, attributeIdsToErase); + sql.executeMany(/*sql*/`DELETE FROM attributes WHERE attributeId IN (???)`, attributeIdsToErase); - setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'attributes' AND entityId IN (???)`, attributeIdsToErase)); + setEntityChangesAsErased(sql.getManyRows(/*sql*/`SELECT * FROM entity_changes WHERE entityName = 'attributes' AND entityId IN (???)`, attributeIdsToErase)); log.info(`Erased attributes: ${JSON.stringify(attributeIdsToErase)}`); } @@ -71,9 +71,9 @@ function eraseAttachments(attachmentIdsToErase: string[]) { return; } - sql.executeMany(`DELETE FROM attachments WHERE attachmentId IN (???)`, attachmentIdsToErase); + sql.executeMany(/*sql*/`DELETE FROM attachments WHERE attachmentId IN (???)`, attachmentIdsToErase); - setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'attachments' AND entityId IN (???)`, attachmentIdsToErase)); + setEntityChangesAsErased(sql.getManyRows(/*sql*/`SELECT * FROM entity_changes WHERE entityName = 'attachments' AND entityId IN (???)`, attachmentIdsToErase)); log.info(`Erased attachments: ${JSON.stringify(attachmentIdsToErase)}`); } @@ -83,9 +83,9 @@ function eraseRevisions(revisionIdsToErase: string[]) { return; } - sql.executeMany(`DELETE FROM revisions WHERE revisionId IN (???)`, revisionIdsToErase); + sql.executeMany(/*sql*/`DELETE FROM revisions WHERE revisionId IN (???)`, revisionIdsToErase); - setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'revisions' AND entityId IN (???)`, revisionIdsToErase)); + setEntityChangesAsErased(sql.getManyRows(/*sql*/`SELECT * FROM entity_changes WHERE entityName = 'revisions' AND entityId IN (???)`, revisionIdsToErase)); log.info(`Removed revisions: ${JSON.stringify(revisionIdsToErase)}`); } @@ -105,10 +105,10 @@ function eraseUnusedBlobs() { return; } - sql.executeMany(`DELETE FROM blobs WHERE blobId IN (???)`, unusedBlobIds); + sql.executeMany(/*sql*/`DELETE FROM blobs WHERE blobId IN (???)`, unusedBlobIds); // blobs are not marked as erased in entity_changes, they are just purged completely // this is because technically every keystroke can create a new blob and there would be just too many - sql.executeMany(`DELETE FROM entity_changes WHERE entityName = 'blobs' AND entityId IN (???)`, unusedBlobIds); + sql.executeMany(/*sql*/`DELETE FROM entity_changes WHERE entityName = 'blobs' AND entityId IN (???)`, unusedBlobIds); log.info(`Erased unused blobs: ${JSON.stringify(unusedBlobIds)}`); } diff --git a/src/services/migration.ts b/src/services/migration.ts index 17f1be40d..d73e34253 100644 --- a/src/services/migration.ts +++ b/src/services/migration.ts @@ -52,7 +52,7 @@ async function migrate() { executeMigration(mig); sql.execute( - `UPDATE options + /*sql*/`UPDATE options SET value = ? WHERE name = ?`, [mig.dbVersion.toString(), "dbVersion"] diff --git a/src/services/sql_init.ts b/src/services/sql_init.ts index b03c12f51..56422c794 100644 --- a/src/services/sql_init.ts +++ b/src/services/sql_init.ts @@ -21,7 +21,7 @@ import backup from "./backup.js"; const dbReady = deferred(); function schemaExists() { - return !!sql.getValue(`SELECT name FROM sqlite_master + return !!sql.getValue(/*sql*/`SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'options'`); } diff --git a/src/services/sync.ts b/src/services/sync.ts index bfaf828f9..47985b4bd 100644 --- a/src/services/sync.ts +++ b/src/services/sync.ts @@ -347,7 +347,7 @@ function getEntityChangeRow(entityChange: EntityChange) { throw new Error(`Unknown entity for entity change ${JSON.stringify(entityChange)}`); } - const entityRow = sql.getRow(`SELECT * FROM ${entityName} WHERE ${primaryKey} = ?`, [entityId]); + const entityRow = sql.getRow(/*sql*/`SELECT * FROM ${entityName} WHERE ${primaryKey} = ?`, [entityId]); if (!entityRow) { log.error(`Cannot find entity for entity change ${JSON.stringify(entityChange)}`); diff --git a/src/services/sync_update.ts b/src/services/sync_update.ts index fae50dd70..c6c0228a1 100644 --- a/src/services/sync_update.ts +++ b/src/services/sync_update.ts @@ -70,7 +70,7 @@ function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow | undef } function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string, updateContext: UpdateContext) { - const localEC = sql.getRow(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [remoteEC.entityName, remoteEC.entityId]); + const localEC = sql.getRow(/*sql*/`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [remoteEC.entityName, remoteEC.entityId]); const localECIsOlderOrSameAsRemote = localEC && localEC.utcDateChanged && remoteEC.utcDateChanged && localEC.utcDateChanged <= remoteEC.utcDateChanged; if (!localEC || localECIsOlderOrSameAsRemote) { @@ -153,7 +153,7 @@ function eraseEntity(entityChange: EntityChange) { const primaryKeyName = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName; - sql.execute(`DELETE FROM ${entityName} WHERE ${primaryKeyName} = ?`, [entityId]); + sql.execute(/*sql*/`DELETE FROM ${entityName} WHERE ${primaryKeyName} = ?`, [entityId]); } function logUpdateContext(updateContext: UpdateContext) { diff --git a/src/services/ws.ts b/src/services/ws.ts index f2674dd20..a405500e6 100644 --- a/src/services/ws.ts +++ b/src/services/ws.ts @@ -139,19 +139,19 @@ function fillInAdditionalProperties(entityChange: EntityChange) { entityChange.entity = becca.getAttribute(entityChange.entityId); if (!entityChange.entity) { - entityChange.entity = sql.getRow(`SELECT * FROM attributes WHERE attributeId = ?`, [entityChange.entityId]); + entityChange.entity = sql.getRow(/*sql*/`SELECT * FROM attributes WHERE attributeId = ?`, [entityChange.entityId]); } } else if (entityChange.entityName === "branches") { entityChange.entity = becca.getBranch(entityChange.entityId); if (!entityChange.entity) { - entityChange.entity = sql.getRow(`SELECT * FROM branches WHERE branchId = ?`, [entityChange.entityId]); + entityChange.entity = sql.getRow(/*sql*/`SELECT * FROM branches WHERE branchId = ?`, [entityChange.entityId]); } } else if (entityChange.entityName === "notes") { entityChange.entity = becca.getNote(entityChange.entityId); if (!entityChange.entity) { - entityChange.entity = sql.getRow(`SELECT * FROM notes WHERE noteId = ?`, [entityChange.entityId]); + entityChange.entity = sql.getRow(/*sql*/`SELECT * FROM notes WHERE noteId = ?`, [entityChange.entityId]); if (entityChange.entity?.isProtected) { entityChange.entity.title = protectedSessionService.decryptString(entityChange.entity.title || ""); @@ -159,7 +159,7 @@ function fillInAdditionalProperties(entityChange: EntityChange) { } } else if (entityChange.entityName === "revisions") { entityChange.noteId = sql.getValue( - `SELECT noteId + /*sql*/`SELECT noteId FROM revisions WHERE revisionId = ?`, [entityChange.entityId] @@ -180,11 +180,11 @@ function fillInAdditionalProperties(entityChange: EntityChange) { entityChange.entity = becca.getOption(entityChange.entityId); if (!entityChange.entity) { - entityChange.entity = sql.getRow(`SELECT * FROM options WHERE name = ?`, [entityChange.entityId]); + entityChange.entity = sql.getRow(/*sql*/`SELECT * FROM options WHERE name = ?`, [entityChange.entityId]); } } else if (entityChange.entityName === "attachments") { entityChange.entity = sql.getRow( - `SELECT attachments.*, LENGTH(blobs.content) AS contentLength + /*sql*/`SELECT attachments.*, LENGTH(blobs.content) AS contentLength FROM attachments JOIN blobs USING (blobId) WHERE attachmentId = ?`, @@ -217,7 +217,7 @@ function sendPing(client: WebSocket, entityChangeIds = []) { return; } - const entityChanges = sql.getManyRows(`SELECT * FROM entity_changes WHERE id IN (???)`, entityChangeIds); + const entityChanges = sql.getManyRows(/*sql*/`SELECT * FROM entity_changes WHERE id IN (???)`, entityChangeIds); if (!entityChanges) { return; } diff --git a/src/share/shaca/entities/sattachment.ts b/src/share/shaca/entities/sattachment.ts index e8d1e50d9..11d3af096 100644 --- a/src/share/shaca/entities/sattachment.ts +++ b/src/share/shaca/entities/sattachment.ts @@ -37,7 +37,7 @@ class SAttachment extends AbstractShacaEntity { } getContent(silentNotFoundError = false) { - const row = sql.getRow>(`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); + const row = sql.getRow>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); if (!row) { if (silentNotFoundError) { diff --git a/src/share/shaca/entities/snote.ts b/src/share/shaca/entities/snote.ts index e4ba17d0c..6b192b57e 100644 --- a/src/share/shaca/entities/snote.ts +++ b/src/share/shaca/entities/snote.ts @@ -95,7 +95,7 @@ class SNote extends AbstractShacaEntity { } getContent(silentNotFoundError = false) { - const row = sql.getRow>(`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); + const row = sql.getRow>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); if (!row) { if (silentNotFoundError) {