From 613570167c8cee0776ecd85966571ea52c2fed25 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Thu, 28 Jul 2022 14:48:23 +1000 Subject: [PATCH] feat: provide exports for ghmattimysql Rather than people weirdly renaming the resource, just provide event handlers for ghmattimysql exports. --- fxmanifest.lua | 1 + src/index.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/fxmanifest.lua b/fxmanifest.lua index 2c0e40a..cabe2a6 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -22,6 +22,7 @@ files { ui_page 'ui/build/index.html' provide 'mysql-async' +provide 'ghmattimysql' convar_category 'OxMySQL' { 'Configuration', diff --git a/src/index.ts b/src/index.ts index 3719e62..f58d916 100644 --- a/src/index.ts +++ b/src/index.ts @@ -78,6 +78,23 @@ MySQL.prepare = ( MySQL.execute = MySQL.query; MySQL.fetch = MySQL.query; +function provide(name: string, cb: Function, sync: Function) { + on(`__cfx_export_ghmattimysql_${name}`, (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 +// these are not actually used to do anything, simply returning the query as-is +provide( + 'store', + (query: string, cb: Function) => { + cb(query); + }, + (query: string) => { + return query; + } +); + for (const key in MySQL) { global.exports(key, MySQL[key]); @@ -98,4 +115,6 @@ for (const key in MySQL) { global.exports(`${key}_async`, exp); global.exports(`${key}Sync`, exp); + + if (key === 'execute' || key === 'scalar' || key === 'transaction') provide(key, MySQL[key], exp); }