-
Notifications
You must be signed in to change notification settings - Fork 1
1) Getting started
To instantiate the QueryTool, you can execute the code below:
// require
const QueryTool = require("query-tool");
const query = new QueryTool();
// import
import QueryTool from "query-tool";
const query = new QueryTool();
To use the QueryTool, you must specify how to connect to the database. To do that, you need to send to the config method an object containing the informations about the connection to be established. The only required field is the method, that must have the value client, in case of a client connection, or pool, in case of a pooled connection.
See the example below:
const config = {
method: "client",
host: "my.database-server.com",
port: 3324,
database: "database-name",
user: "database-user",
password: "secretpassword!!"
}
query.config(config);
For more configuration options, check this link. All options available in it are also valid on QueryTool.
See the example below:
const config = {
method: "pool",
host: "my.database-server.com",
port: 3324,
database: "database-name",
user: "database-user",
password: "secretpassword!!",
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
}
query.config(config);
For more configuration options, check this link. All options available in it are also valid on QueryTool.
To start the connection just call the startConnection() method. It will be responsible to make the connection as specified during setup.
The call to this method will return an object with the success and error keys. If the connection is successfully started, success will be true, and error will be false. Otherwise, success will be false and error will have the error connection message.
const connection = await query.startConnection();
{
success: true,
error: false
}
With the connection properly started, now it is possible to use the other methods of QueryTool.
© 2021-Ana Paula Oliveira de Lima
All rights reserved