Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 < params.length; i++) {
params[i] = "<span class="param">" + params[i] + "</span>";
const formatSql = (rawSql: string) => {
return sqlFormatter.format(rawSql, { indent: ' '});
}
? (sql: string) => sqlformatter.format(sql)
: (sql: string) => sql;
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)
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 < params0 && 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>
formatting(code: string): string {
return this.data.type === 'SQL' ? sqlFormatter.format(code) : js_beautify(code);
}
}
const ObjInspect = (obj, lang) => {
if (lang === "sql") {
let sql = Array.isArray(obj)
? obj.map(x => 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
}
}
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 < params0 && 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) > 0) && }
<div></div>
<div>[{this.props.row.step.param}]</div>
</div>)
}
}
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)));`);
}
export const formatSql = (query: string) => new SqlFormatter().format(query);