feat(salesforce): add Salesforce SOQL data source
This commit is contained in:
125 files changed
+9999
-117
No files matched your search
@@ -14,6 +14,21 @@ describe("tableMetadataCapabilities", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("exposes only describe fields for Salesforce objects", () => {
|
||||
// An SObject has no index, foreign key, trigger or DDL metadata; only the
|
||||
// describe payload (fields) is real, so every other structure tab stays off
|
||||
// instead of rendering permanently empty.
|
||||
expect(getTableMetadataCapabilities("salesforce")).toEqual({
|
||||
columns: true,
|
||||
indexes: false,
|
||||
foreignKeys: false,
|
||||
constraints: false,
|
||||
triggers: false,
|
||||
partitions: false,
|
||||
ddl: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("exposes structured constraints only for dialects that implement list_constraints", () => {
|
||||
expect(getTableMetadataCapabilities("oracle").constraints).toBe(true);
|
||||
expect(getTableMetadataCapabilities("postgres").constraints).toBe(true);
|
||||
|
||||
@@ -143,3 +143,49 @@ export function isClickHouseExistingRowReadonlyColumn(databaseType: DatabaseType
|
||||
const columnInfo = columns.find((info) => info.name.toLowerCase() === column.toLowerCase());
|
||||
return /\bpartition_key\b/i.test(columnInfo?.extra ?? "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe flags the Salesforce driver packs into `ColumnInfo.extra`
|
||||
* (see `parse_describe_columns` in crates/dbx-drivers/src/db/salesforce_driver.rs).
|
||||
* `relationshipName` / `referenceTo` also live there but are consumed by SOQL
|
||||
* completion instead (`soqlFieldFromColumnInfo`).
|
||||
*/
|
||||
export interface SalesforceColumnFlags {
|
||||
updateable?: boolean;
|
||||
createable?: boolean;
|
||||
custom?: boolean;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export function parseSalesforceColumnExtra(extra?: string | null): SalesforceColumnFlags | null {
|
||||
if (!extra) return null;
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(extra);
|
||||
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? (parsed as SalesforceColumnFlags) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function findColumnInfoByName(columns: ColumnInfo[], column: string): ColumnInfo | undefined {
|
||||
return columns.find((info) => info.name.toLowerCase() === column.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Existing Salesforce rows: the record `Id` is the identity and never a write
|
||||
* target, and describe reports `updateable: false` for formula, rollup summary,
|
||||
* auto-number and system fields (CreatedDate, CreatedById, LastModifiedDate…).
|
||||
* Missing/unparseable metadata fails open — Salesforce enforces the real rules
|
||||
* server-side and returns a per-record error we surface on the row.
|
||||
*/
|
||||
export function isSalesforceExistingRowReadonlyColumn(databaseType: DatabaseType | undefined, column: string, primaryKeys: readonly string[], columns: ColumnInfo[] = []): boolean {
|
||||
if (databaseType !== "salesforce") return false;
|
||||
if (primaryKeys.some((key) => key.toLowerCase() === column.toLowerCase())) return true;
|
||||
return parseSalesforceColumnExtra(findColumnInfoByName(columns, column)?.extra)?.updateable === false;
|
||||
}
|
||||
|
||||
/** New Salesforce rows: fields describe reports as `createable: false` (Id, CreatedDate, …) cannot be set on insert. */
|
||||
export function isSalesforceNewRowReadonlyColumn(databaseType: DatabaseType | undefined, column: string, columns: ColumnInfo[] = []): boolean {
|
||||
if (databaseType !== "salesforce") return false;
|
||||
return parseSalesforceColumnExtra(findColumnInfoByName(columns, column)?.extra)?.createable === false;
|
||||
}
|
||||
@@ -90,6 +90,15 @@ const capabilityByType: Partial<Record<DatabaseType, Partial<TableMetadataCapabi
|
||||
triggers: false,
|
||||
ddl: false,
|
||||
},
|
||||
// A Salesforce object only has describe metadata: the driver lists fields, and
|
||||
// there is no index, foreign key, trigger or DDL surface behind an SObject, so
|
||||
// those structure tabs would render permanently empty.
|
||||
salesforce: {
|
||||
indexes: false,
|
||||
foreignKeys: false,
|
||||
triggers: false,
|
||||
ddl: false,
|
||||
},
|
||||
hbase: {
|
||||
indexes: false,
|
||||
foreignKeys: false,
|
||||
|
||||
@@ -89,6 +89,10 @@ function sqlStatementSpans(sql: string, dialectId: string): Array<{ start: numbe
|
||||
export function quoteTableIdentifier(databaseType: DatabaseType | undefined, name: string): string {
|
||||
if ((databaseType === "gaussdb" || databaseType === "opengauss") && isExplicitlyQuotedSqlIdentifier(name)) return name;
|
||||
if (databaseType === "iotdb") return name;
|
||||
// SOQL has no delimited identifiers — `"Account"` is a string literal there and
|
||||
// `SELECT * FROM "Account"` fails with MALFORMED_QUERY. Mirrors the Rust
|
||||
// `quote_table_identifier` so a grid ORDER BY / filter matches what the backend builds.
|
||||
if (databaseType === "salesforce") return name;
|
||||
// JDBC connections use the driver-reported identifier quote string
|
||||
// (DatabaseMetaData.getIdentifierQuoteString()) — pass through unquoted.
|
||||
if (databaseType === "jdbc") return name;
|
||||
@@ -427,6 +431,21 @@ export function normalizeWhereInput(whereInput?: string): string {
|
||||
return withoutSemicolon.replace(/^where\b/i, "").trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Database types whose data-preview SQL cannot be built without a column list,
|
||||
* so the columns must be awaited before the statement is generated rather than
|
||||
* refreshed in the background.
|
||||
*
|
||||
* * MySQL / PostgreSQL: the large-value preview projection is derived from the
|
||||
* column types and primary keys.
|
||||
* * Salesforce: SOQL has no `SELECT *`. With no known fields the backend builder
|
||||
* falls back to the `FIELDS(ALL)` selector, which the org only accepts with
|
||||
* `LIMIT 200` or less — awaiting the describe keeps every page size working.
|
||||
*/
|
||||
export function requiresEagerTableMetadataForDataOpen(databaseType: DatabaseType | undefined): boolean {
|
||||
return databaseType === "mysql" || databaseType === "postgres" || databaseType === "salesforce";
|
||||
}
|
||||
|
||||
export async function buildTableSelectSql(options: BuildTableSelectSqlOptions): Promise<string> {
|
||||
if (options.databaseType === "victoriametrics") return metricRangeQuery(options.tableName);
|
||||
return api.buildTableSelectSql(options);
|
||||
|
||||
Reference in new issue
Block a user