feat(mysql): setup execute export

- also setup test.lua for testing
This commit is contained in:
dunak-debug committed 2021-08-16 00:12:28 +02:00
1 parent 7afd440931
commit b2ade77589
8 files changed
+139 -10

No files matched your search

+32 -6
View File
@@ -1,7 +1,33 @@
const mysql2 = require("mysql2");
import { QueryError } from "mysql2/promise";
import { pool } from "./pool";
const pool = mysql2.createPool({
host: "localhost",
user: "root",
database: "es_extended",
});
const execute = (
query: string,
callback: (result: any) => void,
parameters?: { [key: string]: any }
) => {
const startTime = process.hrtime.bigint();
pool
.execute(query, parameters)
.then((result) => {
const end = process.hrtime.bigint();
console.log(`Query took ${Number(end - startTime) / 1000000} ms!`);
callback(result[0]);
})
.catch((error) => {
callback(false);
console.log(error);
});
};
global.exports(
"execute",
(
query: string,
parameters: { [key: string]: any },
callback: (result: any) => void
) => {
execute(query, callback, parameters);
}
);
+9
View File
@@ -0,0 +1,9 @@
import { createPool } from "mysql2/promise";
const pool = createPool({
host: "localhost",
user: "root",
database: "es_extended",
});
export { pool };