Simplify sqlJoin required arguments
This commit is contained in:
parent
e87873c929
commit
c3248be854
4 changed files with 10 additions and 13 deletions
|
@ -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});
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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};
|
||||
`;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue