motherduck@1.0.3
This adaptor exports the following namespaced functions:
This adaptor exports the following from common:
- alterState
- arrayToString()
- as()
- combine()
- cursor()
- dataPath()
- dataValue()
- dateFns
- each()
- field()
- fields()
- fn()
- fnIf()
- group()
- lastReferenceValue()
- map()
- merge()
- sourceValue()
Functions
execute
execute(...operations) ⇒ Operation
Execute a sequence of operations against MotherDuck cloud database.
Wraps @openfn/language-common/execute, and prepends initial state for MotherDuck.
| Param | Type | Description |
|---|---|---|
| ...operations | Operation | Operations to be performed. |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| references | Array of previous operation results |
| data | Data from the last operation |
Example
execute(
query('SELECT * FROM my_table'),
insert('users', { name: 'John', age: 30 })
)(state)
insert
insert(table, records, [options]) ⇒ Operation
Insert one or more records into a MotherDuck table with automatic batching. Large datasets are automatically split into batches for optimal performance.
| Param | Type | Default | Description |
|---|---|---|---|
| table | string | Target table name | |
| records | object | Array | A single record object or array of records | |
| [options] | object | Insert options | |
| [options.batchSize] | number | 1000 | Number of records per batch |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | Metadata including recordsInserted and batches |
Example: Insert a single record
insert('users', { name: 'John', age: 30, email: 'john@example.com' })
Example: Insert multiple records
insert('users', [
{ name: 'John', age: 30 },
{ name: 'Jane', age: 25 }
])
Example: Insert with custom batch size
insert('users', records, { batchSize: 500 })
query
query(sqlQuery, [options]) ⇒ Operation
Execute a SQL query against the MotherDuck database.
| Param | Type | Default | Description |
|---|---|---|---|
| sqlQuery | string | SQL query string | |
| [options] | object | Query execution options | |
| [options.writeSql] | boolean | false | Include full SQL in response.query (default: false, hides query for security) |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | Query results as array of row objects |
| response | Metadata including rowCount, command, and query |
Example: Simple query
query('SELECT * FROM users WHERE age > 18')
Example: Query with SQL logging
query('SELECT * FROM orders', { writeSql: true })
util
These functions belong to the util namespace.
util.escapeSqlString
escapeSqlString(value) ⇒ string
Escape SQL string values to prevent SQL injection
Returns: string - - Escaped string value
| Param | Type | Description |
|---|---|---|
| value | string | String value to escape |
util.formatSqlValue
formatSqlValue(value) ⇒ string
Format a value for SQL insertion
Returns: string - - Formatted SQL value
| Param | Type | Description |
|---|---|---|
| value | any | Value to format |
util.validateSqlIdentifier
validateSqlIdentifier(identifier) ⇒ string
Validate SQL identifier (table names, column names, etc.)
Returns: string - - Validated identifier
Throws:
Error- If identifier contains dangerous characters
| Param | Type | Description |
|---|---|---|
| identifier | string | SQL identifier to validate |