mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 06:28:54 +00:00
feat(mysql): setup execute export
- also setup test.lua for testing
This commit is contained in:
8 files changed
+139
-10
No files matched your search
+32
-6
@@ -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);
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
import { createPool } from "mysql2/promise";
|
||||
|
||||
const pool = createPool({
|
||||
host: "localhost",
|
||||
user: "root",
|
||||
database: "es_extended",
|
||||
});
|
||||
|
||||
export { pool };
|
||||
Reference in new issue
Block a user