Simplify sqlJoin required arguments

This commit is contained in:
trevor-signal 2023-11-22 17:48:53 -05:00 committed by GitHub
parent e87873c929
commit c3248be854
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 13 deletions

View file

@ -1861,7 +1861,7 @@ async function searchMessages({
ON
messages.id = mentions.messageId
AND mentions.mentionAci IN (
${sqlJoin(contactServiceIdsMatchingQuery, ', ')}
${sqlJoin(contactServiceIdsMatchingQuery)}
)
AND ${
conversationId
@ -2944,7 +2944,7 @@ async function getNearbyMessageFromDeletedSet({
conversationId = ${conversationId} AND
(${_storyIdPredicate(storyId, includeStoryReplies)}) AND
isStory IS 0 AND
id NOT IN (${sqlJoin(deletedMessageIds, ', ')}) AND
id NOT IN (${sqlJoin(deletedMessageIds)}) AND
type IN ('incoming', 'outgoing')
AND (
(received_at = ${received_at} AND sent_at ${compare} ${sent_at}) OR
@ -3495,10 +3495,7 @@ function getCallHistoryGroupDataSync(
db.exec(createTempTable);
batchMultiVarQuery(db, conversationIds, ids => {
const idList = sqlJoin(
ids.map(id => sqlFragment`${id}`),
','
);
const idList = sqlJoin(ids.map(id => sqlFragment`${id}`));
const [insertQuery, insertParams] = sql`
INSERT INTO temp_callHistory_filtered_conversations
@ -5499,7 +5496,7 @@ function modifyStoryDistributionMembersSync(
db,
toRemove,
(serviceIds: ReadonlyArray<ServiceIdString>) => {
const serviceIdSet = sqlJoin(serviceIds, ',');
const serviceIdSet = sqlJoin(serviceIds);
const [sqlQuery, sqlParams] = sql`
DELETE FROM storyDistributionMembers
WHERE listId = ${listId} AND serviceId IN (${serviceIdSet});

View file

@ -105,9 +105,9 @@ export function sqlConstant(value: QueryTemplateParam): QueryFragment {
/**
* Like `Array.prototype.join`, but for SQL fragments.
*/
const SQL_JOIN_SEPARATOR = ',';
export function sqlJoin(
items: ReadonlyArray<QueryFragmentValue>,
separator: string
items: ReadonlyArray<QueryFragmentValue>
): QueryFragment {
let query = '';
const params: Array<QueryTemplateParam> = [];
@ -118,7 +118,7 @@ export function sqlJoin(
params.push(...fragmentParams);
if (index < items.length - 1) {
query += separator;
query += SQL_JOIN_SEPARATOR;
}
});
@ -344,7 +344,7 @@ export function removeById<Key extends string | number>(
const removeByIdsSync = (ids: ReadonlyArray<string | number>): void => {
const [query, params] = sql`
DELETE FROM ${table}
WHERE id IN (${sqlJoin(ids, ', ')});
WHERE id IN (${sqlJoin(ids)});
`;
totalChanges += db.prepare(query).run(params).changes;
};

View file

@ -38,7 +38,7 @@ describe('sql/utils/sql', () => {
const [selectQuery, selectParams] = sql`
SELECT * FROM examples WHERE
id IN (${sqlJoin([1, 2], ', ')}) OR
id IN (${sqlJoin([1, 2])}) OR
${predicate};
`;

View file

@ -3447,7 +3447,7 @@ describe('SQL migrations test', () => {
ON
messages.id = mentions.messageId
AND mentions.mentionUuid IN (
${sqlJoin(['a', 'b', 'c'], ', ')}
${sqlJoin(['a', 'b', 'c'])}
)
AND messages.isViewOnce IS NOT 1
AND messages.storyId IS NULL