Skip to main content

motherduck@1.0.0

execute(...operations)
insert(table, records, [options])
query(sqlQuery, [options])

This adaptor exports the following namespaced functions:

util.escapeSqlString(value)
util.formatSqlValue(value)
util.validateSqlIdentifier(identifier)

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.

ParamTypeDescription
...operationsOperationOperations to be performed.

This operation writes the following keys to state:

State KeyDescription
referencesArray of previous operation results
dataData 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.

ParamTypeDefaultDescription
tablestringTarget table name
recordsobject | ArrayA single record object or array of records
[options]objectInsert options
[options.batchSize]number1000Number of records per batch

This operation writes the following keys to state:

State KeyDescription
dataMetadata 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.

ParamTypeDefaultDescription
sqlQuerystringSQL query string
[options]objectQuery execution options
[options.writeSql]booleanfalseInclude full SQL in response.query (default: false, hides query for security)

This operation writes the following keys to state:

State KeyDescription
dataQuery results as array of row objects
responseMetadata 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

ParamTypeDescription
valuestringString value to escape

util.formatSqlValue

formatSqlValue(value) ⇒ string

Format a value for SQL insertion

Returns: string - - Formatted SQL value

ParamTypeDescription
valueanyValue 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
ParamTypeDescription
identifierstringSQL identifier to validate