How to use the pg-sql2.value 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 / QueryBuilder.ts View on Github external
parentQueryBuilder.beforeLock("select", () => {
        const id = this.rootValue.liveConditions.push(checkerGenerator) - 1;
        // BEWARE: it's easy to override others' conditions, and that will cause issues. Be sensible.
        const allRequirements = this.data.liveConditions.reduce(
          (memo, [_checkerGenerator, requirements]) =>
            requirements ? Object.assign(memo, requirements) : memo,
          {}
        );

        parentQueryBuilder.select(
          sql.fragment`\
json_build_object('__id', ${sql.value(id)}::int
${sql.join(
  Object.keys(allRequirements).map(
    key => sql.fragment`, ${sql.literal(key)}::text, ${allRequirements[key]}`
  ),

  ""
)})`,
          "__live"
        );
      });
    } else if (cb) {
github graphile / graphile-engine / packages / graphile-build-pg / src / plugins / viaTemporaryTable.ts View on Github external
// According to https://www.postgresql.org/docs/10/static/sql-createfunction.html,
                // "If you omit the name for an output argument, the system will choose a default column name."
                // In PG 9.x and 10, the column names appear to be assigned with a `column` prefix.
                outputArgName !== "" ? outputArgName : `column${idx + 1}`
              )}`
          ),

          ", "
        )}
from (values ${sql.join(
          values.map(value => sql.query`(${sql.value(value)}::text[])`),
          ", "
        )}) as ${sqlValuesAlias}(output_value_list)`
      : sql.query`\
select str::${sqlTypeIdentifier} as ${sqlResultSourceAlias}
from unnest((${sql.value(values)})::text[]) str`;
    const { rows: filteredValuesResults } =
      values.length > 0
        ? await performQuery(
            pgClient,
            sql.query`with ${sqlResultSourceAlias} as (${convertFieldBack}) ${sqlResultQuery}`
          )
        : { rows: [] };
    const finalRows = rawValues.map(rawValue =>
      /*
       * We can't simply return 'null' here because this is expected to have
       * come from PG, and that would never return 'null' for a row - only
       * the fields within said row. Using `__isNull` here is a simple
       * workaround to this, that's caught by `pg2gql`.
       */
      rawValue === null ? { __isNull: true } : filteredValuesResults.shift()
    );
github graphile / graphile-engine / packages / graphile-build-pg / src / queryFromResolveDataFactory.ts View on Github external
        const sqlCursors = rawCursors.map(val => sql.value(val));
        for (let i = orderByExpressionsAndDirections.length - 1; i >= 0; i--) {

pg-sql2

Generate safe Postgres-compliant SQL with tagged template literals

MIT
Latest version published 2 years ago

Package Health Score

64 / 100
Full package analysis