({
tableExpression,
idKey,
orderKey,
columns,
options,
predicates,
}: {
tableExpression: SQLTableName | string;
idKey: string;
orderKey: string;
columns: string[];
options: DatabaseQueryOptions<any>;
predicates: DatabaseQueryPredicate[];
})
| 416 | } |
| 417 | |
| 418 | function constructListSQLQuery({ |
| 419 | tableExpression, |
| 420 | idKey, |
| 421 | orderKey, |
| 422 | columns, |
| 423 | options, |
| 424 | predicates, |
| 425 | }: { |
| 426 | tableExpression: SQLTableName | string; |
| 427 | idKey: string; |
| 428 | orderKey: string; |
| 429 | columns: string[]; |
| 430 | options: DatabaseQueryOptions<any>; |
| 431 | predicates: DatabaseQueryPredicate[]; |
| 432 | }): { statement: string; args: any[] } { |
| 433 | const args: any[] = []; |
| 434 | |
| 435 | const whereExpressions: string[] = []; |
| 436 | |
| 437 | for (const predicate of predicates) { |
| 438 | whereExpressions.push(`${predicate[0]} ${predicate[1]} ?`); |
| 439 | args.push(predicate[2]); |
| 440 | } |
| 441 | |
| 442 | if (options.afterID) { |
| 443 | whereExpressions.push( |
| 444 | `${orderKey} > (SELECT ${orderKey} FROM ${tableExpression} WHERE ${idKey}=?)`, |
| 445 | ); |
| 446 | args.push(options.afterID); |
| 447 | } |
| 448 | |
| 449 | const whereClause = |
| 450 | whereExpressions.length > 0 |
| 451 | ? `WHERE ${whereExpressions.join(" AND ")}` |
| 452 | : ""; |
| 453 | const limitClause = |
| 454 | options.limit === undefined ? "" : `LIMIT ${options.limit}`; |
| 455 | |
| 456 | const query = `SELECT ${columns.join( |
| 457 | ",", |
| 458 | )} FROM ${tableExpression} ${whereClause} ${limitClause}`; |
| 459 | return { statement: query, args }; |
| 460 | } |
| 461 | |
| 462 | export function constructGetByIDSQLQuery<Column, ID>( |
| 463 | tableName: SQLTableName, |
no outgoing calls
no test coverage detected