API Reference

DB API Reference

Detailed reference for the DB interface in Wayvo.


The DB interface in Wayvo provides a comprehensive set of methods for interacting with data sources. This reference outlines each method available in the DB interface, including its purpose, parameters, and return types.

Methods

find

find: <T>(dataSourceId: string, query: Query<T>) => Promise<DBRow<T>[]>

Finds rows in a data source that match the given query.

  • dataSourceId: The ID of the data source to search.
  • query: The query to use when searching for rows.
  • Returns: An array of rows that match the query.

findMany

findMany: <T>(dataSourceId: string, data: Record<string, unknown>, limit: number) => Promise<DBRow<T>[]>

Finds multiple rows in a data source that match the given data.

  • dataSourceId: The ID of the data source to search.
  • data: The data to use when searching for rows.
  • limit: The maximum number of rows to return.
  • Returns: An array of rows that match the data.

findOne

findOne: <T>(dataSourceId: string, data: Record<string, unknown>) => Promise<DBRow<T> | undefined>

Finds a single row in a data source that matches the given data.

  • dataSourceId: The ID of the data source to search.
  • data: The data to use when searching for the row.
  • Returns: The row that matches the data, or undefined if no row was found.

insertOne

insertOne: <T>(dataSourceId: string, row: Row<T>) => Promise<DBRow<T>>

Inserts a single row into a data source.

  • dataSourceId: The ID of the data source to insert the row into.
  • row: The row to insert into the data source.
  • Returns: The inserted row.

updateOne

updateOne: <T>(dataSourceId: string, row: DBRow<T>) => Promise<DBRow<T>>

Updates a single row in a data source.

  • dataSourceId: The ID of the data source to update the row in.
  • row: The row to update in the data source.
  • Returns: The updated row.

deleteOne

deleteOne: <T>(dataSourceId: string, row: DBRow<T>) => Promise<DBRow<T>>

Deletes a single row from a data source.

  • dataSourceId: The ID of the data source to delete the row from.
  • row: The row to delete from the data source.
  • Returns: The deleted row.

insertMany

insertMany: <T>(dataSourceId: string, rows: Row<T>[]) => Promise<DBRow<T>[]>

Inserts multiple rows into a data source.

  • dataSourceId: The ID of the data source to insert the rows into.
  • rows: The rows to insert into the data source.
  • Returns: The inserted rows.

updateMany

updateMany: <T>(dataSourceId: string, rows: DBRow<T>[]) => Promise<DBRow<T>[]>

Updates multiple rows in a data source.

  • dataSourceId: The ID of the data source to update the rows in.
  • rows: The rows to update in the data source.
  • Returns: The updated rows.

deleteMany

deleteMany: <T>(dataSourceId: string, rows: DBRow<T>[]) => Promise<DBRow<T>[]>

Deletes multiple rows from a data source.

  • dataSourceId: The ID of the data source to delete the rows from.
  • rows: The rows to delete from the data source.
  • Returns: The deleted rows.

validateRow

validateRow: <T>(dataSourceId: string, row: Row<T>) => Promise<Row<T>>

Validates a row of data against a data source's schema.

  • dataSourceId: The ID of the data source to validate the row against.
  • row: The row of data to validate.
  • Returns: The validated row of data.

executeQuery

executeQuery: (
  sql: string,
  params?: unknown[],
  options?: { workspaceId?: string; commit?: boolean },
) => Promise<Record<string, unknown>[]>

Executes a SQL query and returns the result as an array of objects.

  • sql: The SQL query to execute.
  • params: Optional parameters to pass to the query.
  • Returns: The result of the query as an array of objects, or an empty array if there was an error.

executeUpdate

executeUpdate: (sql: string, params?: unknown[]) => Promise<number>

Executes a SQL query that modifies the database and returns the number of rows affected.

  • sql: The SQL query to execute.
  • params: Optional parameters to pass to the query.
  • Returns: The number of rows affected by the query.

queryString

queryString: (sql: string, params?: unknown[]) => Promise<string | undefined>

Executes a SQL query and returns the result as a string.

  • sql: The SQL query to execute.
  • params: Optional parameters to pass to the query.
  • Returns: The result of the query as a string, or undefined if there was no value.

queryNumber

queryNumber: (sql: string, params?: unknown[]) => Promise<number | undefined>

Executes a SQL query and returns the result as a number.

  • sql: The SQL query to execute.
  • params: Optional parameters to pass to the query.
  • Returns: The result of the query as a number, or undefined if there was no value.

publish

publish: (msg: Publish) => Promise<void>

Publishes a message to a message queue.

  • msg: The message to publish.
  • Returns: A Promise that resolves when the message has been published.

startFlow

startFlow: (props: {
  title: string;
  flowId: string;
  version: number;
  input: Record<string, unknown>;
}) => Promise<string>

Starts a flow.

  • title: The title to be used for this flow instance.
  • flowId: The ID of the flow to start.
  • version: The version of the flow to start.
  • input: The input data to pass to the flow.
  • Returns: A Promise that resolves with the ID of the started flow.

encrypt

encrypt: (value: string) => string

Encrypts a string of data.

  • data: The data to encrypt.
  • Returns: The encrypted data.

decrypt

decrypt: (value: string) => string

Decrypts a string of data.

  • data: The data to decrypt.
  • Returns: The decrypted data.

hash

hash: (value: string) => string

Hashes a string.

  • data: The string to hash.
  • Returns: The hash string.

verifyHash

verifyHash: (hash: string, raw: string) => boolean

Checks if the hash matches the raw data.

  • hash: The hash to check.
  • raw: The raw data to check.
  • Returns: The result of the check.

completeWaitForFlowNode

completeWaitForFlowNode: (info: FlowWaitForInfo) => Promise<void>

Completes a wait for flow node.

  • info: The info about the wait for flow node.
  • Returns: A Promise that resolves when the wait for flow node has been completed.

submitApprovalResponse

submitApprovalResponse: (resp: ApprovalResponse) => Promise<void>

Submits an approval response.

  • resp: The info about the approval flow node.
  • Returns: A Promise that resolves when the approval response has been submitted.

submitIntakeResponse

submitIntakeResponse: (resp: IntakeResponse) => Promise<void>

Submits an intake response.

  • resp: The info about the intake flow node.
  • Returns: A Promise that resolves when the intake response has been submitted.

sleep

sleep(ms: number): Promise<void>

Sleeps for the specified number of milliseconds.

userOrg

userOrg(): string

Gets the current user's Org ID.

  • Returns: The current user's Org ID.

userName

userName(): string

Gets the current user's username.

  • Returns: The current user's username.

userWorkSpace

userWorkSpace(): string

Gets the current user's Workspace ID.

  • Returns: The current user's Workspace ID.

userEmail

userEmail(): string

Gets the current user's email.

  • Returns: The current user's email.

userRoles

userRoles(): string[]

Gets the current user's roles.

  • Returns: The current user's roles.

ulid

ulid(): string

Generates a ULID (Universally Unique Lexicographically Sortable Identifier).

  • Returns: A ULID.

getResource

getResource: <T>(resourceId: string) => Promise<T | undefined>

Gets a resource.

  • resourceId: The ID of the resource.
  • Returns: A Promise that resolves to the resource, or undefined if the resource does not exist or the current user doesn't have access.

getVariable

getVariable: (name: string) => Promise<string | undefined>

Gets the value of a variable.

  • name: The name of the variable.
  • Returns: A Promise that resolves to the value of the variable, or undefined if the variable does not exist.

isKafkaTopicExists

isKafkaTopicExists: (props: { resource: string; topic: string }) => Promise<boolean>

Checks if a Kafka topic exists.

  • resource: The resource to check.
  • topic: The topic to check.
  • Returns: A Promise that resolves to true if the topic exists, or false if it does not.

createKafkaTopic

createKafkaTopic: (props: {
  resource: string;
  topic: string;
  partitions: number;
  replicationFactor: number;
}) => Promise<void>

Creates a Kafka topic.

  • resource: The resource to create the topic for.
  • topic: The name of the topic to create.
  • partitions: The number of partitions for the topic.
  • replicationFactor: The replication factor for the topic.
  • Returns: A Promise that resolves when the topic has been created.

publishToKafkaTopic

publishToKafkaTopic: (props: { resource: string; topic: string; key: string; message: string }) => Promise<void>

Publishes a message to a Kafka topic.

  • resource: The resource to publish the message to.
  • topic: The topic to publish the message to.
  • key: The key of the message.
  • message: The message to publish.
  • Returns: A Promise that resolves when the message has been published.

sendEmail

sendEmail: (props: EmailProps) => Promise<void>

Sends an email.

  • props: The properties of the email to send.
  • Returns: A Promise that resolves when the email has been sent.

setVariable

setVariable: (name: string, value: string) => Promise<void>

Sets the value of a variable.

  • name: The name of the variable.
  • value: The value to set the variable to.
  • Returns: A Promise that resolves when the variable has been set.

uploadFile

uploadFile: (local_path: string, remote_path: string) => Promise<void>

Uploads a file to a remote storage using the provided path.

  • local_path: The path to the local file to upload.
  • remote_path: The path to the remote location to upload the file to.
  • Returns: A Promise that resolves when the file has been uploaded.

downloadFile

downloadFile: (remote_path: string, local_path: string) => Promise<void>

Downloads a file from a remote storage using the provided path.

  • remote_path: The path to the remote file to download.
  • local_path: The path to the local location to download the file to.
  • Returns: A Promise that resolves when the file has been downloaded.

deleteFile

deleteFile: (remote_path: string) => Promise<void>

Deletes a file from a remote storage using the provided path.

  • remote_path: The path to the remote file to delete.
  • Returns: A Promise that resolves when the file has been deleted.

fileExists

fileExists: (remote_path: string) => Promise<boolean>

Checks if a file exists in a remote storage using the provided path.

  • remote_path: The path to the remote file to check.
  • Returns: A Promise that resolves to true if the file exists, or false if it does not.
Previous
Integration Guides
Next
FLOW