This class simplefies the use of working with the @sap/hana-client
- The connection will be created automatically, no need to set it up manually.
- All queries will be escaped automatically
- See the examples below and checkout the example/example-testrun.js file
const DB = require("scp-cf-database");
Exec a query
const a = await DB.query(`SELECT * FROM "table.Example" WHERE "foo" = ?`, ["bar"]);
Exec a batch query
const i = await DB.queryBatch('INSERT INTO "table.Example"("foo", "example") VALUES (?, ?)', [['bar', 'text'], ['bar 2', 'text 2']]);
console.log(i); // 2 // no affected rows
Inserting will return the created insert
const a = await DB.insert("table.Example", { foo: "bar"});
console.log(a); // { id: 1234, foo: "bar"}
A batch insert will return the no of affected rows
const i = await DB.insertBatch(
"table.Example",
[
{ "foo": "bar", "example": "text" },
{ "foo": "bar 2", "example": "text 2" }
]
);
console.log(i); // 2 // no affected rows
UPDATE "table.Example" set "foo" = 'bar', "example" = 'text' WHERE "id" = 1
await DB.update(
"table.Example", //tabel
{ foo: "bar", example: "text"}, // data
`"id" = ?`, //filter
[1] // filter waarden
);
DELETE FROM "table.Example" WHERE "id" = '1'
await DB.delete("table.Example", `"id" = ?`, [1]);
await DB.select("table.Example", "*", `"foo" = ?`, ["bar"]);
const aResult = await DB.callProcedure(
"createPerson", // Procedure naam
{ IM_FIRSTNAME: "Barry", IM_LASTNAME: "Dam" }, // Importing paams
["EX_FULLNAME"] // Exporting params
);
console.log(aResult.EX_FULLNAME);
await DB.callFunction("functionname", mImporting);