mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-04 06:28:53 +00:00
feat: provide additional compatibility exports
This commit is contained in:
1 parent
e31d84019e
commit
779ecca76f
3 files changed
+43
-19
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
query: 'execute',
|
||||||
|
scalar: 'scalar',
|
||||||
|
transaction: 'transaction',
|
||||||
|
store: 'store',
|
||||||
|
};
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export default {
|
||||||
|
update: 'mysql_execute',
|
||||||
|
insert: 'mysql_insert',
|
||||||
|
query: 'mysql_fetch_all',
|
||||||
|
scalar: 'mysql_fetch_scalar',
|
||||||
|
transaction: 'mysql_transaction',
|
||||||
|
store: 'mysql_store',
|
||||||
|
};
|
||||||
+29
-19
@@ -93,30 +93,26 @@ MySQL.rawExecute = (
|
|||||||
rawExecute(invokingResource, query, parameters, cb, isPromise);
|
rawExecute(invokingResource, query, parameters, cb, isPromise);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// provide the store export for compatibility (ghmatti/mysql-async); simply returns the query as-is
|
||||||
|
MySQL.store = (query: string, cb: Function) => {
|
||||||
|
cb(query);
|
||||||
|
};
|
||||||
|
|
||||||
|
// deprecated export names
|
||||||
MySQL.execute = MySQL.query;
|
MySQL.execute = MySQL.query;
|
||||||
MySQL.fetch = MySQL.query;
|
MySQL.fetch = MySQL.query;
|
||||||
|
|
||||||
function provide(name: string, cb: Function, sync: Function) {
|
function provide(resourceName: string, method: string, cb: Function) {
|
||||||
on(`__cfx_export_ghmattimysql_${name}`, (setCb: Function) => setCb(cb));
|
on(`__cfx_export_${resourceName}_${method}`, (setCb: Function) => setCb(cb));
|
||||||
on(`__cfx_export_ghmattimysql_${name}Sync`, (setCb: Function) => setCb(sync));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// provide the "store" and "storeSync" exports, to provide compatibility for ghmattimysql
|
import ghmatti from './compatibility/ghmattimysql';
|
||||||
// these are not actually used to do anything, simply returning the query as-is
|
import mysqlAsync from './compatibility/mysql-async';
|
||||||
provide(
|
|
||||||
'store',
|
|
||||||
(query: string, cb: Function) => {
|
|
||||||
cb(query);
|
|
||||||
},
|
|
||||||
(query: string) => {
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const key in MySQL) {
|
for (const key in MySQL) {
|
||||||
global.exports(key, MySQL[key]);
|
const exp = MySQL[key];
|
||||||
|
|
||||||
const exp = (query: string, parameters: CFXParameters, invokingResource = GetInvokingResource()) => {
|
const async_exp = (query: string, parameters: CFXParameters, invokingResource = GetInvokingResource()) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
MySQL[key](
|
MySQL[key](
|
||||||
query,
|
query,
|
||||||
@@ -131,8 +127,22 @@ for (const key in MySQL) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
global.exports(`${key}_async`, exp);
|
global.exports(key, exp);
|
||||||
global.exports(`${key}Sync`, exp);
|
// async_retval
|
||||||
|
global.exports(`${key}_async`, async_exp);
|
||||||
|
// deprecated aliases for async_retval
|
||||||
|
global.exports(`${key}Sync`, async_exp);
|
||||||
|
|
||||||
if (key === 'execute' || key === 'scalar' || key === 'transaction') provide(key, MySQL[key], exp);
|
let alias = (ghmatti as any)[key];
|
||||||
|
|
||||||
|
if (alias) {
|
||||||
|
provide('ghmattimysql', alias, exp);
|
||||||
|
provide('ghmattimysql', `${alias}Sync`, async_exp);
|
||||||
|
}
|
||||||
|
|
||||||
|
alias = (mysqlAsync as any)[key];
|
||||||
|
|
||||||
|
if (alias) {
|
||||||
|
provide('mysql-async', alias, exp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user