How to use sql-formatter - 10 common examples

To help you get started, we’ve selected a few sql-formatter 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 scouter-contrib / scouter-paper / src / components / Paper / XLog / Profiler / FrameProfile / FrameStepDetail / FrameStepDetail.js View on Github external
getSqlMainValue = (info) => {
        let sql = "";
        if (info.step.stepType === "16") {
            if (this.state.bind) {
                let params = divideParams(info.step.param);
                let {sql: sql0, params: params0} = literalBind(info.mainValue, params);

                for (let i = 0; i < params0 && params0.length; i++) {
                    params0[i] = "<span class="param">" + params0[i] + "</span>";
                }
                sql = sqlFormatter.format(sql0, {
                    params: params0,
                    indent: "  "
                });

            } else {
                sql = sqlFormatter.format(info.mainValue, {
                    indent: "  "
                });
            }

            sql = '<span class="prefix">' + info.step.xtypePrefix + '</span>' + sql;
        } else {
            if (this.state.bind) {
                let params = info.step.param.split(",");
                for (let i = 0; i &lt; params.length; i++) {
                    params[i] = "<span class="param">" + params[i] + "</span>";
github uwrit / leaf / src / ui-client / src / utils / formatSql.ts View on Github external
const formatSql = (rawSql: string) => {
    return sqlFormatter.format(rawSql, { indent: '    '});
}
github bradzacher / mysqldump / src / getDataDump.ts View on Github external
        ? (sql: string) => sqlformatter.format(sql)
        : (sql: string) => sql;
github firebase / extensions / firestore-bigquery-export / firestore-bigquery-change-tracker / src / bigquery / snapshot.ts View on Github external
export function buildLatestSnapshotViewQuery(
  datasetId: string,
  tableName: string,
  timestampColumnName: string,
  groupByColumns: string[]
): string {
  if (datasetId === "" || tableName === "" || timestampColumnName === "") {
    throw Error(`Missing some query parameters!`);
  }
  for (let columnName in groupByColumns) {
    if (columnName === "") {
      throw Error(`Found empty group by column!`);
    }
  }
  const query = sqlFormatter.format(
    ` -- Retrieves the latest document change events for all live documents.
    --   timestamp: The Firestore timestamp at which the event took place.
    --   operation: One of INSERT, UPDATE, DELETE, IMPORT.
    --   event_id: The id of the event that triggered the cloud function mirrored the event.
    --   data: A raw JSON payload of the current state of the document.
    SELECT
      document_name${groupByColumns.length > 0 ? `,` : ``}
      ${groupByColumns.join(",")}
     FROM (
      SELECT
        document_name,
        ${groupByColumns
          .map(
            (columnName) =>
              `FIRST_VALUE(${columnName})
            OVER(PARTITION BY document_name ORDER BY ${timestampColumnName} DESC)
github scouter-contrib / scouter-paper / src / components / Paper / XLog / Profiler / SingleProfile / Sql3Step / Sql3Step.js View on Github external
render() {

        let sql = "";

        if (this.props.bind) {
            let params = divideParams(this.props.row.step.param);
            let {sql: sql0, params: params0} = literalBind(this.props.row.mainValue, params);

            for (let i = 0; i &lt; params0 &amp;&amp; params0.length; i++) {
                params0[i] = "<span class="param">" + params0[i] + "</span>";
            }
            sql = sqlFormatter.format(sql0, {
                params: params0,
                indent: "  "
            });

        } else {
            sql = sqlFormatter.format(this.props.row.mainValue, {
                indent: "  "
            });
        }

        sql = '<span class="prefix">' + this.props.row.step.xtypePrefix + '</span>' + sql;

        return (
            <div>
                
                
</div>
github naver / pinpoint / web / src / main / webapp / v2 / src / app / core / components / syntax-highlight-popup / syntax-highlight-popup.component.ts View on Github external
formatting(code: string): string {
        return this.data.type === 'SQL' ? sqlFormatter.format(code) : js_beautify(code);
    }
}
github rod-stuchi / JS-inspect / react-log / src / Inspect.js View on Github external
const ObjInspect = (obj, lang) =&gt; {
  if (lang === "sql") {
    let sql = Array.isArray(obj) 
              ? obj.map(x =&gt; sqlFormatter.format(x, {indent: "    "})).join("----")
              : sqlFormatter.format(obj, {indent: "    "});

    sql = sql.replace(/----/g, "\n---------------------------------------------\n");
    return {sql}

  } else if (Array.isArray(obj)) {
    return 

  } else if (typeof(obj) === "string") {
    return <pre>{obj}</pre>

  } else {
    return 

  }
}
github scouter-contrib / scouter-paper / src / components / Paper / XLog / Profiler / SingleProfile / Sql3Step / Sql3Step.js View on Github external
let sql = "";

        if (this.props.bind) {
            let params = divideParams(this.props.row.step.param);
            let {sql: sql0, params: params0} = literalBind(this.props.row.mainValue, params);

            for (let i = 0; i &lt; params0 &amp;&amp; params0.length; i++) {
                params0[i] = "<span class="param">" + params0[i] + "</span>";
            }
            sql = sqlFormatter.format(sql0, {
                params: params0,
                indent: "  "
            });

        } else {
            sql = sqlFormatter.format(this.props.row.mainValue, {
                indent: "  "
            });
        }

        sql = '<span class="prefix">' + this.props.row.step.xtypePrefix + '</span>' + sql;

        return (
            <div>
                
                
                {(isNaN(this.props.row.step.error) || Number(this.props.row.step.error) &gt; 0) &amp;&amp; }
                <div></div>
                <div>[{this.props.row.step.param}]</div>
            </div>)
    }
}
github firebase / extensions / firestore-bigquery-export / scripts / gen-schema-view / src / udf.ts View on Github external
function firestoreGeopointDefinition(datasetId: string): string {
  return sqlFormatter.format(`
    CREATE FUNCTION \`${
      process.env.PROJECT_ID
    }.${datasetId}.firestoreGeopoint\`(json STRING)
    RETURNS GEOGRAPHY AS
    (ST_GEOGPOINT(SAFE_CAST(JSON_EXTRACT(json, '$._latitude') AS NUMERIC), SAFE_CAST(JSON_EXTRACT(json, '$._longitude') AS NUMERIC)));`);
}

sql-formatter

Format whitespace in a SQL query to make it more readable

MIT
Latest version published 13 days ago

Package Health Score

86 / 100
Full package analysis