How to use the pg-sql2.null function in pg-sql2

To help you get started, we’ve selected a few pg-sql2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphile / graphile-engine / packages / graphile-build-pg / src / queryFromResolveDataFactory.ts View on Github external
for (let i = orderByExpressionsAndDirections.length - 1; i >= 0; i--) {
          const [sqlExpression, ascending] = orderByExpressionsAndDirections[i];
          // If ascending and isAfter then >
          // If ascending and isBefore then <
          const comparison =
            Number(ascending) ^ Number(!isAfter)
              ? sql.fragment`>`
              : sql.fragment`<`;

          const sqlOldFilter = sqlFilter;
          sqlFilter = sql.fragment`\
(\
  (${sqlExpression} ${comparison} ${sqlCursors[i] || sql.null})
OR\
  (\
    ${sqlExpression} = ${sqlCursors[i] || sql.null}\
  AND\
    ${sqlOldFilter}\
  )\
)`;
        }

        // Check the cursor prefixes apply
        // TODO:v5: we should be able to do this in JS-land rather than SQL-land
        sqlFilter = sql.fragment`(((${sql.join(
          getPgCursorPrefix(),
          ", "
        )}) = (${sql.join(
          rawPrefixes.map(val => sql.value(val)),
          ", "
        )})) AND (${sqlFilter}))`;
        queryBuilder.whereBound(sqlFilter, isAfter);
github graphile / graphile-engine / packages / graphile-build-pg / src / queryFromResolveDataFactory.ts View on Github external
}
        let sqlFilter = sql.fragment`false`;
        const sqlCursors = rawCursors.map(val => sql.value(val));
        for (let i = orderByExpressionsAndDirections.length - 1; i >= 0; i--) {
          const [sqlExpression, ascending] = orderByExpressionsAndDirections[i];
          // If ascending and isAfter then >
          // If ascending and isBefore then <
          const comparison =
            Number(ascending) ^ Number(!isAfter)
              ? sql.fragment`>`
              : sql.fragment`<`;

          const sqlOldFilter = sqlFilter;
          sqlFilter = sql.fragment`\
(\
  (${sqlExpression} ${comparison} ${sqlCursors[i] || sql.null})
OR\
  (\
    ${sqlExpression} = ${sqlCursors[i] || sql.null}\
  AND\
    ${sqlOldFilter}\
  )\
)`;
        }

        // Check the cursor prefixes apply
        // TODO:v5: we should be able to do this in JS-land rather than SQL-land
        sqlFilter = sql.fragment`(((${sql.join(
          getPgCursorPrefix(),
          ", "
        )}) = (${sql.join(
          rawPrefixes.map(val => sql.value(val)),

pg-sql2

Generate safe Postgres-compliant SQL with tagged template literals

MIT
Latest version published 2 years ago

Package Health Score

66 / 100
Full package analysis