DdlBuilder
Defined in: js-api/src/entities/data-connection.ts:558
Fluent builder for structured DDL against one connection, obtained via
grok.data.db.ddl(connectionId). Mirrors TableMutationBuilder; every
terminal returns a DdlCommand carrying exactly one operation.
Requires a provider with DDL support (Postgres, MySQL/MariaDB, MSSQL, Oracle —
there is no generic-JDBC DDL fallback; others reject with a structured capability
error) and the matching fine-grained saved-connection privilege
(DataConnection.CreateTable for createTable, DropTable for dropTable,
TruncateTable for truncateTable, AlterSchema for the rest), enforced
server-side.
Constructors
Constructor
new DdlBuilder(
connectionId):DdlBuilder
Defined in: js-api/src/entities/data-connection.ts:561
Parameters
| Parameter | Type |
|---|---|
connectionId | string |
Returns
DdlBuilder
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
connectionId | readonly | string | js-api/src/entities/data-connection.ts:561 |
Methods
addKey()
addKey(
tableName,spec):DdlCommand
Defined in: js-api/src/entities/data-connection.ts:598
Adds a primary- or foreign-key constraint; refTable/refColumns are foreign-only.
The constraint name is auto-generated (pk_<table> / fk_<table>_<col>) when absent.
Parameters
| Parameter | Type |
|---|---|
tableName | string |
spec | { columns: string[]; keyType: "primary" | "foreign"; name?: string; refColumns?: string[]; refTable?: string; } |
spec.columns | string[] |
spec.keyType | "primary" | "foreign" |
spec.name? | string |
spec.refColumns? | string[] |
spec.refTable? | string |
Returns
alterTable()
alterTable(
tableName):AlterTableBuilder
Defined in: js-api/src/entities/data-connection.ts:578
Single-action ALTER TABLE operations on [tableName].
Parameters
| Parameter | Type |
|---|---|
tableName | string |
Returns
createIndex()
createIndex(
tableName,columns,options?):DdlCommand
Defined in: js-api/src/entities/data-connection.ts:584
CREATE [UNIQUE] INDEX on [columns]; the name is auto-generated
(ix_<table>_<col>) when absent.
Parameters
| Parameter | Type |
|---|---|
tableName | string |
columns | string[] |
options? | { name?: string; unique?: boolean; } |
options.name? | string |
options.unique? | boolean |
Returns
createTable()
createTable(
tableName,columns,options?):DdlCommand
Defined in: js-api/src/entities/data-connection.ts:568
CREATE TABLE with optional primary key and indexes. Foreign keys are not part
of the create — create first, then addKey.
Parameters
| Parameter | Type |
|---|---|
tableName | string |
columns | DdlColumn[] |
options? | { ifNotExists?: boolean; indexes?: DdlIndex[]; primaryKey?: string[]; } |
options.ifNotExists? | boolean |
options.indexes? | DdlIndex[] |
options.primaryKey? | string[] |
Returns
dropIndex()
dropIndex(
tableName,indexName):DdlCommand
Defined in: js-api/src/entities/data-connection.ts:592
DROP INDEX by name.
Parameters
| Parameter | Type |
|---|---|
tableName | string |
indexName | string |
Returns
dropTable()
dropTable(
tableName):DdlCommand
Defined in: js-api/src/entities/data-connection.ts:609
DROP TABLE — destructive: requires execute({confirmDestructive: true}) (the
refusal carries the plan with the live row count).
Parameters
| Parameter | Type |
|---|---|
tableName | string |
Returns
schema()
schema(
schema):DdlBuilder
Defined in: js-api/src/entities/data-connection.ts:564
Sets the database schema for subsequently built operations.
Parameters
| Parameter | Type |
|---|---|
schema | string |
Returns
DdlBuilder
truncateTable()
truncateTable(
tableName):DdlCommand
Defined in: js-api/src/entities/data-connection.ts:612
TRUNCATE TABLE — destructive, same confirmation contract as dropTable.
Parameters
| Parameter | Type |
|---|---|
tableName | string |