Skip to main content

Updating Database Actions

A Database Action in Ductape defines a reusable query or operation (such as create, read, update, or delete) that can be performed on your product's database. You may want to update a database action to change its logic, template, or parameters as your application evolves.

When to Update a Database Action

  • You need to change the query or operation performed by an action
  • You want to update the template or parameters for a specific environment or use case
  • You need to fix or enhance an existing action

Database Action Structure

FieldTypeRequiredDescriptionExample
namestringYesName of the actionCreate User
tagstringYesUnique identifier for this actioncreate-user
tableNamestringYesName of the database tableusers
typestring (enum)YesAction type (read, count, create, update, delete, aggregate)create
templatestring | objectYesQuery or operation template{"insertOne": {"username": "{{username}}"}} or SQL string
descriptionstringNoDescription of the actionCreate a new user
dataarrayNoSample input data
filterDataarrayNoSample filter data
filterTemplatestring | objectNoFilter template for the action

How to Update a Database Action

To update an existing database action, use the update function with the database tag and action tag (in the format database-tag:action-tag), along with the updated action object.

Example: Updating a MongoDB Action

import { IProductDatabaseAction, DatabaseActionTypes } from '@ductape/sdk/types';

const updateData: IProductDatabaseAction = {
name: 'Create User',
tag: 'create-user',
tableName: 'users',
type: DatabaseActionTypes.CREATE,
template: {
insertOne: {
username: '{{username}}',
firstname: '{{firstname}}',
middlename: '{{middlename}}',
lastname: '{{lastname}}',
dateOfBirth: '{{dateOfBirth}}',
address: '{{address}}',
occupation: '{{occupation}}'
}
},
description: 'Create a new user in MongoDB'
};

const action = await ductape.product.databases.actions.update('mongo-db-tag:create-user', updateData);

Example: Updating a MySQL Action

import { IProductDatabaseAction, DatabaseActionTypes } from '@ductape/sdk/types';

const updateData: IProductDatabaseAction = {
name: 'Create User',
tag: 'create-user',
tableName: 'users',
type: DatabaseActionTypes.CREATE,
template: `
INSERT INTO users (username, firstname, middlename, lastname, date_of_birth, address, occupation)
VALUES ('{{username}}', '{{firstname}}', '{{middlename}}', '{{lastname}}', '{{dateOfBirth}}', '{{address}}', '{{occupation}}')
`,
description: 'Create a new user in MySQL'
};

const action = await ductape.product.databases.actions.update('mysql-db-tag:create-user', updateData);

Example: Updating a PostgreSQL Action

import { IProductDatabaseAction, DatabaseActionTypes } from '@ductape/sdk/types';

const updateData: IProductDatabaseAction = {
name: 'Create User',
tag: 'create-user',
tableName: 'users',
type: DatabaseActionTypes.CREATE,
template: `
INSERT INTO users (username, firstname, middlename, lastname, date_of_birth, address, occupation)
VALUES ('{{username}}', '{{firstname}}', '{{middlename}}', '{{lastname}}', '{{dateOfBirth}}', '{{address}}', '{{occupation}}')
`,
description: 'Create a new user in PostgreSQL'
};

const action = await ductape.product.databases.actions.update('postgres-db-tag:create-user', updateData);

Tip: Always ensure your template matches the syntax and requirements of your target database.

Next Steps