Skip to main content
Database

SQL Server

SQL Server

The SQL Server module is responsible for connecting to a SQL Server DBMS, performing queries and handling the results inside the robot.

Methods

connection

Method responsible for creating a connection with a SQL Server database.

js
const connection = await Database.SQLServer.connection["v1_0_0"]({
connectionString: `Server=localhost;1433;Database=master;User Id=admin;password=123;TrustServerCertificate=True;`,
})

Required parameters

  • connectionString: String - expects a string with the connection parameters. The standard must be followed as in the example shown earlier.

Optional parameters

This action has no optional parameters.

Return

This action has no returns.

close

Method responsible for closing an open connection with a SQL Server database.

js
await Database.SQLServer.close["v1_0_0"]({
connection: connection,
})

Required parameters

  • connection: Return of the connection action - expects the connection obtained through the connection action.

Optional parameters

This action has no optional parameters.

Return

This action has no returns.

transactionBegin

Method responsible for creating a transaction with the SQL Server DBMS.

js
const transaction = await Database.SQLServer.transactionBegin["v1_0_0"]({
connection: connection,
})

Required parameters

  • connection: Return of the connection action - expects the connection obtained through the connection action.

Optional parameters

This action has no optional parameters.

Return

This action has no returns.

transactionCommit

Method responsible for committing a transaction opened by the transactionBegin action.

js
await Database.SQLServer.transactionCommit["v1_0_0"]({
transaction: transaction,
})

Required parameters

  • transaction: Return of the action that begins a transaction - expects the transaction obtained through the transactionBegin action.

Optional parameters

This action has no optional parameters.

Return

This action has no returns.

transactionRollBack

Method responsible for rolling back a transaction opened by the transactionBegin action.

js
await Database.SQLServer.transactionRollBack["v1_0_0"]({
transaction: transaction,
})

Required parameters

  • transaction: Return of the action that begins a transaction - expects the transaction obtained through the transactionBegin action.

Optional parameters

This action has no optional parameters.

Return

This action has no returns.

query

Method responsible for performing a query directly in the database through the connection obtained by the connection action.

js
const query = await Database.SQLServer.query["v1_0_0"]({
query: `SELECT * FROM tabela;`,
connection: connection,
transaction: transaction
})

Required parameters

  • connection: Return of the connection action - expects the connection obtained through the connection action.
  • query: String - expects a string with the query to be performed.

Optional parameters

  • transaction: Return of the transactionBegin action - expects the transaction obtained through the transactionBegin action.

Return

The constant or variable created, such as the query of the example shown earlier, receives a value of the Object type. The object returned has the following properties:

  • query.query: String - returns the query that was used.
  • query.results: Array - returns every result obtained with the query.
  • query.resultsCount: Number - returns the number of rows obtained in the result.