forked from tsai/budibase
8 changed files with 129 additions and 27 deletions
@ -1,22 +1,30 @@ |
|||||
import { QueryJson } from "../../definitions/datasource" |
import { QueryJson } from "../../definitions/datasource" |
||||
import { Datasource } from "../../definitions/common" |
import { Datasource } from "../../definitions/common" |
||||
|
const { integrations } = require("../index") |
||||
|
|
||||
module DatasourceUtils { |
const QUERY_START_REGEX = /\d[0-9]*:/g |
||||
const { integrations } = require("../index") |
|
||||
|
|
||||
export async function makeExternalQuery( |
export async function makeExternalQuery( |
||||
datasource: Datasource, |
datasource: Datasource, |
||||
json: QueryJson |
json: QueryJson |
||||
) { |
) { |
||||
const Integration = integrations[datasource.source] |
const Integration = integrations[datasource.source] |
||||
// query is the opinionated function
|
// query is the opinionated function
|
||||
if (Integration.prototype.query) { |
if (Integration.prototype.query) { |
||||
const integration = new Integration(datasource.config) |
const integration = new Integration(datasource.config) |
||||
return integration.query(json) |
return integration.query(json) |
||||
} else { |
} else { |
||||
throw "Datasource does not support query." |
throw "Datasource does not support query." |
||||
} |
|
||||
} |
} |
||||
|
} |
||||
|
|
||||
module.exports.makeExternalQuery = makeExternalQuery |
export function removeKeyNumbering(key: any): string { |
||||
|
if (typeof key === "string" && key.match(QUERY_START_REGEX) != null) { |
||||
|
const parts = key.split(":") |
||||
|
// remove the number
|
||||
|
parts.shift() |
||||
|
return parts.join(":") |
||||
|
} else { |
||||
|
return key |
||||
|
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue