parent
58ef1c04c7
commit
ca7288cbdd
4 changed files with 48 additions and 29 deletions
@ -0,0 +1,33 @@ |
|||||||
|
import join from './join'; |
||||||
|
import { sanitizeQS } from './sanitizeQS'; |
||||||
|
|
||||||
|
const buildIDCondition = ( |
||||||
|
ids: Parameters<JoinFunction>[0], |
||||||
|
conditionPrefix: string, |
||||||
|
{ |
||||||
|
onFallback = () => '', |
||||||
|
beforeReturn = (result) => |
||||||
|
result ? `${conditionPrefix} IN (${result})` : onFallback(), |
||||||
|
}: Pick<JoinOptions, 'beforeReturn'> & { onFallback?: () => string } = {}, |
||||||
|
) => |
||||||
|
join(ids, { |
||||||
|
beforeReturn, |
||||||
|
elementWrapper: "'", |
||||||
|
separator: ', ', |
||||||
|
}) as string; |
||||||
|
|
||||||
|
export const buildQSIDCondition = ( |
||||||
|
ids: unknown, |
||||||
|
conditionPrefix: string, |
||||||
|
{ onFallback = () => '' }: { onFallback?: () => string }, |
||||||
|
): { after: string; before: string[] } => { |
||||||
|
const before = sanitizeQS(ids, { isForSQL: true, returnType: 'string[]' }); |
||||||
|
const after = buildIDCondition(before, conditionPrefix, { onFallback }); |
||||||
|
|
||||||
|
return { after, before }; |
||||||
|
}; |
||||||
|
|
||||||
|
export const buildParamIDCondition = ( |
||||||
|
ids: string[] | '*' = '*', |
||||||
|
conditionPrefix: string, |
||||||
|
) => (ids[0] === '*' ? '' : buildIDCondition(ids, conditionPrefix)); |
@ -1,18 +0,0 @@ |
|||||||
import join from './join'; |
|
||||||
import { sanitizeQS } from './sanitizeQS'; |
|
||||||
|
|
||||||
export const buildIDCondition = ( |
|
||||||
ids: unknown, |
|
||||||
field: string, |
|
||||||
{ onFallback = () => '' }: { onFallback?: () => string }, |
|
||||||
): { after: string; before: string[] } => { |
|
||||||
const before = sanitizeQS(ids, { isForSQL: true, returnType: 'string[]' }); |
|
||||||
const after = join(before, { |
|
||||||
beforeReturn: (toReturn) => |
|
||||||
toReturn ? `${field} IN (${toReturn})` : onFallback.call(null), |
|
||||||
elementWrapper: "'", |
|
||||||
separator: ', ', |
|
||||||
}) as string; |
|
||||||
|
|
||||||
return { after, before }; |
|
||||||
}; |
|
Loading…
Reference in new issue