@phytest/debbie v1.0.4
Debbie
A node module designed to interface with Phytest databases
Debbie is designed to be lightweight and easy to use.
She is outfitted with a series of useful utilities:
- Automatic deadlock handling and configurable tolerance
- Debbie will recognize when a deadlock occurs and attempt the call again
- Deadlock tolerance is configurable, by default Debbie attempts a call up to 3 times in 1 second intervals if a deadlock is detected
- Database Error Handling
- Debbie is equipped with a custom DatabaseError class that translates errors from the database into objects better suited for node handling
- Result Set Grouping
- Debbie is configured to collect results from a stored procedure in result sets; if a procedure were to return multiple different result sets, they are grouped separately for easier identification
- Automatic JSON Parsing
- Debbie is capable of identifying JSON strings returned from the database and converting them from a string into JSON objects!
USAGE :
CONFIGURATION :
Debbie requires a specific configuration object upon instantiation to establish a relationship with a particular database. That configuration object looks like this:
const config = {
server: "<NAME OF SERVER", // REQUIRED STRING
authentication: { // REQUIRED OBJECT
type: "default", // REQUIRED STRING
options: { // REQUIRED OBJECT
userName: "<NAME OF USER CONNECTING TO DATABASE>", // REQUIRED STRING
password: "<PASSWORD OF USER CONNECTING TO DATABASE>" // REQUIRED STRING
}
},
options: { // REQUIRED OBJECT
database: "<NAME OF DATABASE TO CONNECT TO>", // REQUIRED STRING
requestTimeout: 1800000, // REQUIRED INT
rowCollectionOnDone: true, // REQUIRED BOOLEAN
trustServerCertificate: true, // REQUIRED BOOLEAN
deadlockTolerance: 3, // OPTIONAL INT
deadlockTimeDelay: 1000 // OPTIONAL INT
}
};
Note: deadlockTolerance is the value that dictates how many attempts Debbie will make to call a stored procedure when a deadlock is detected Note: deadlockTimeDelay is the time in milliseconds Debbie will wait before trying a stored procedure again when a deadlock is detected
INSTANTIATION :
Once configuration is complete, simply instantiate Debbie and apply the configuration:
const example_dbi = new Debbie(config);
Congratulations! If your code didn't crash, it means you supplied the bare minimum required to create a Debbie.
USE :
Debbie only has one public method. Debbie only needs one public method.
.call(stored procedure name, payload)
const test = async () => {
try {
let results = await example_dbi.call("TestStoredProcedure", { UserName: "Test!" });
// successful results available here
} catch(err) {
// if Debbie throws an error, be it from the database or within herself, it will end up here!
console.log(err);
}
}
Note: It is important to wrap calls Debbie makes in try/catch blocks to ensure proper handling of the errors she may encounter