Skip to main content
Database

PostgreSQL

PostgreSQL

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

Methods

connection

Method responsible for creating a connection with a PostgreSQL database.

js
const connection = await Database.PostreSQL.connection["v1_0_0"]({
connectionString: `postgres://userRoberty:robertyBD123@localhost:5432/robertyBD`,
})

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 PostgreSQL database.

js
await Database.PostreSQL.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 PostgreSQL DBMS.

js
const transaction = await Database.PostreSQL.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.PostreSQL.transactionCommit["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.

transactionRollBack

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

js
await Database.PostreSQL.transactionRollBack["v1_0_0"]({
connection: connection,
})

Required parameters

  • connection: Return of the connection action - 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.PostreSQL.query["v1_0_0"]({
query: `SELECT * FROM tabela;`,
connection: connection,
timeout: 120
})

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

  • timeout: Number - expects a value in milliseconds to wait for the execution of the query.

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.