New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dbnx/mysql

Package Overview
Dependencies
Maintainers
0
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dbnx/mysql - npm Package Compare versions

Comparing version

to
1.0.21

dist/utilities/condition.js

2

dist/handler.js

@@ -1,1 +0,1 @@

"use strict";var _DBnx_instances,_DBnx_pool,_DBnx_connection,_DBnx_query,_DBnx_dbConfig,_DBnx_usePool,_DBnx_logger,_DBnx_argumentExecuteParse,__awaiter=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{a(i.next(e))}catch(e){s(e)}}function l(e){try{a(i.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,l)}a((i=i.apply(e,t||[])).next())}))},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,n):r?r.value=n:t.set(e,n),n},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DBnx=void 0;const mysql2_1=require("mysql2"),model_1=require("./model"),query_1=require("./query"),utilities_1=require("./utilities");class DBnx{constructor(...e){_DBnx_instances.add(this),_DBnx_pool.set(this,null),_DBnx_connection.set(this,null),_DBnx_query.set(this,""),_DBnx_dbConfig.set(this,null),_DBnx_usePool.set(this,!1),_DBnx_logger.set(this,void 0),__classPrivateFieldSet(this,_DBnx_logger,"function"==typeof e[1]?e[1]:e[2],"f"),__classPrivateFieldSet(this,_DBnx_usePool,"boolean"==typeof e[1]&&e[1],"f"),__classPrivateFieldSet(this,_DBnx_dbConfig,e[0],"f")}connect(e){try{__classPrivateFieldGet(this,_DBnx_usePool,"f")?__classPrivateFieldSet(this,_DBnx_pool,(0,mysql2_1.createPool)(__classPrivateFieldGet(this,_DBnx_dbConfig,"f")).promise(),"f"):__classPrivateFieldSet(this,_DBnx_connection,(0,mysql2_1.createConnection)(__classPrivateFieldGet(this,_DBnx_dbConfig,"f")).promise(),"f"),e&&(this.logger_function("✅ Connection has been established successfully."),e(void 0,"Connection has been established successfully."))}catch(t){this.logger_function(`❌ Error: ${t}`),e&&e(t,void 0)}return this}execute(...e){return __awaiter(this,void 0,void 0,(function*(){var t;const{sql:n,additional:i,params:r,responseFn:s}=__classPrivateFieldGet(this,_DBnx_instances,"m",_DBnx_argumentExecuteParse).call(this,...e),o=n||__classPrivateFieldGet(this,_DBnx_query,"f");if(this.logger_function(`🔍 Execute: ${o}`),!o)throw new Error("No query to execute.");let l;if(__classPrivateFieldGet(this,_DBnx_pool,"f"))l=yield null===(t=__classPrivateFieldGet(this,_DBnx_pool,"f"))||void 0===t?void 0:t.getConnection();else{if(!__classPrivateFieldGet(this,_DBnx_connection,"f"))throw new Error("Database connection is not initialized.");l=__classPrivateFieldGet(this,_DBnx_connection,"f")}try{const[e,t]=yield null==l?void 0:l.execute(o,r),n=Object.assign({success:!0,result:e},i);return s?s(n):n}catch(e){const t={result:[],errno:null==e?void 0:e.errno,success:!1,error:e instanceof Error?e.message:String(e)};return s?s(t):t}finally{__classPrivateFieldSet(this,_DBnx_query,"","f"),__classPrivateFieldGet(this,_DBnx_pool,"f")&&l!==__classPrivateFieldGet(this,_DBnx_connection,"f")&&l&&(yield l.release())}}))}executeQuery(...e){return __awaiter(this,void 0,void 0,(function*(){var t;const{sql:n,additional:i,params:r,responseFn:s}=__classPrivateFieldGet(this,_DBnx_instances,"m",_DBnx_argumentExecuteParse).call(this,...e),o=n||__classPrivateFieldGet(this,_DBnx_query,"f");if(this.logger_function(`📜 Execute: ${o}`),!o)throw new Error("No query to execute.");let l;if(__classPrivateFieldGet(this,_DBnx_pool,"f"))l=yield null===(t=__classPrivateFieldGet(this,_DBnx_pool,"f"))||void 0===t?void 0:t.getConnection();else{if(!__classPrivateFieldGet(this,_DBnx_connection,"f"))throw new Error("Database connection is not initialized.");l=__classPrivateFieldGet(this,_DBnx_connection,"f")}try{const[e,t]=yield null==l?void 0:l.query(o,r),n=Object.assign({success:!0,result:e},i);return s?s(n):n}catch(e){const t={result:[],errno:null==e?void 0:e.errno,success:!1,error:e instanceof Error?e.message:String(e)};return s?s(t):t}finally{__classPrivateFieldSet(this,_DBnx_query,"","f"),__classPrivateFieldGet(this,_DBnx_pool,"f")&&l!==__classPrivateFieldGet(this,_DBnx_connection,"f")&&l&&(yield l.release())}}))}define(e,t,n){const i=class extends model_1.Model{};return Object.defineProperty(i,"name",{value:e}),i.init(e,t,this,n),i}create(...e){var t;if((null==e?void 0:e.length)<2)throw new Error("No arguments provided to 'findFrom'. Expected a table name and/or values.");const n=e[1],i=null!==(t=e[2])&&void 0!==t?t:{};if("function"==typeof e[0]&&"tableName"in e[0])return e[0].create(n,i);let r="string"==typeof e[0]?e[0]:"";if(!r)throw new Error("Expected a table name and/or values.");return __classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.insertInto)(r,n,i),"f"),this.logger_function(`🆕 Create into: \`${r}\``),this}findAll(...e){var t;if(0===e.length)throw new Error("No arguments provided to 'findAll'. Expected a table name or model.");let n="",i=null!==(t=e[1])&&void 0!==t?t:{};if("function"==typeof e[0]&&"tableName"in e[0])return n=e[0].model,e[0].findAll(i);if("string"!=typeof e[0])throw new Error("Invalid first argument: must be a table name or a Model class.");return n=e[0],__classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.findingQuery)(n,i),"f"),this.logger_function(`📋 Find all from: \`${n}\``),this}findOne(...e){var t;if(0===e.length)throw new Error("No arguments provided to 'findOne'. Expected a table name or model.");let n="",i=null!==(t=e[1])&&void 0!==t?t:{};if(i.limitSkip={limit:1},"function"==typeof e[0]&&"tableName"in e[0])return n=e[0].model,e[0].findOne(i);if("string"!=typeof e[0])throw new Error("Invalid first argument: must be a table name or a Model class.");return n=e[0],__classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.findingQuery)(n,i),"f"),this.logger_function(`🔎 Find one from: \`${n}\``),this}update(...e){if(0===e.length)throw new Error("No arguments provided to 'update'. Expected a table name or model.");let t="",n=e[1];if("function"==typeof e[0]&&"tableName"in e[0])return t=e[0].model,e[0].update(n);if("string"!=typeof e[0])throw new Error("Invalid first argument: must be a table name or a Model class.");return t=e[0],__classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.update)(t,n),"f"),this.logger_function(`✏️ Update from: \`${t}\``),this}delete(...e){var t;if(0===e.length)throw new Error("No arguments provided to 'delete'. Expected a table name or model.");let n="",i=null!==(t=e[1])&&void 0!==t?t:{};if("function"==typeof e[0]&&"tableName"in e[0])return n=e[0].model,e[0].delete(i);if("string"!=typeof e[0])throw new Error("Invalid first argument: must be a table name or a Model class.");return n=e[0],__classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.destroy)(n,i),"f"),this.logger_function(`🗑️ Delete from: \`${n}\``),this}logger_function(e){__classPrivateFieldGet(this,_DBnx_logger,"f")&&__classPrivateFieldGet(this,_DBnx_logger,"f").call(this,e)}getConfig(){var e;let t;return __classPrivateFieldGet(this,_DBnx_pool,"f")?t=(null===(e=__classPrivateFieldGet(this,_DBnx_pool,"f"))||void 0===e?void 0:e.pool.config).connectionConfig:__classPrivateFieldGet(this,_DBnx_connection,"f")&&(t=__classPrivateFieldGet(this,_DBnx_connection,"f").config),t||("string"==typeof __classPrivateFieldGet(this,_DBnx_dbConfig,"f")?(0,utilities_1.parseMySQLUrl)(__classPrivateFieldGet(this,_DBnx_dbConfig,"f")):__classPrivateFieldGet(this,_DBnx_dbConfig,"f"))}setQuery(e){return this.logger_function(`⚙️ Query set: ${e}`),__classPrivateFieldSet(this,_DBnx_query,e,"f"),this}build(){const e=__classPrivateFieldGet(this,_DBnx_query,"f");return __classPrivateFieldSet(this,_DBnx_query,"","f"),e}close(){return __awaiter(this,void 0,void 0,(function*(){__classPrivateFieldGet(this,_DBnx_pool,"f")?(this.logger_function("⏳ Closing connection pool..."),yield __classPrivateFieldGet(this,_DBnx_pool,"f").end(),this.logger_function("✅ Connection pool closed successfully.")):__classPrivateFieldGet(this,_DBnx_connection,"f")?(this.logger_function("⏳ Closing database connection..."),yield __classPrivateFieldGet(this,_DBnx_connection,"f").end(),this.logger_function("✅ Database connection closed successfully.")):this.logger_function("⚠️ No active connection or pool to close.")}))}}exports.DBnx=DBnx,_DBnx_pool=new WeakMap,_DBnx_connection=new WeakMap,_DBnx_query=new WeakMap,_DBnx_dbConfig=new WeakMap,_DBnx_usePool=new WeakMap,_DBnx_logger=new WeakMap,_DBnx_instances=new WeakSet,_DBnx_argumentExecuteParse=function(...e){let t,n,i,r;return 4===e.length?[t,n,i,r]=e:3===e.length?"string"==typeof e[0]&&Array.isArray(e[1])?[t,n,i]=e:[t,i,r]=e:2===e.length?"string"==typeof e[0]?(t=e[0],Array.isArray(e[1])?n=e[1]:"object"==typeof e[1]?i=e[1]:"function"==typeof e[1]&&(r=e[1])):(i=e[0],r=e[1]):1===e.length&&("string"==typeof e[0]?t=e[0]:"function"==typeof e[0]?r=e[0]:"object"==typeof e[0]&&(i=e[0])),{sql:t,params:n,additional:i,responseFn:r}},exports.default=DBnx;
"use strict";var _DBnx_instances,_DBnx_pool,_DBnx_connection,_DBnx_query,_DBnx_dbConfig,_DBnx_usePool,_DBnx_logger,_DBnx_argumentExecuteParse,__awaiter=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function l(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,l)}a((n=n.apply(e,t||[])).next())}))},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,t,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(e,i):r?r.value=i:t.set(e,i),i},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DBnx=void 0;const mysql2_1=require("mysql2"),model_1=require("./model"),query_1=require("./query"),utilities_1=require("./utilities"),condition_1=require("./utilities/condition");class DBnx{constructor(...e){_DBnx_instances.add(this),_DBnx_pool.set(this,null),_DBnx_connection.set(this,null),_DBnx_query.set(this,""),_DBnx_dbConfig.set(this,null),_DBnx_usePool.set(this,!1),_DBnx_logger.set(this,void 0),__classPrivateFieldSet(this,_DBnx_logger,"function"==typeof e[1]?e[1]:e[2],"f"),__classPrivateFieldSet(this,_DBnx_usePool,"boolean"==typeof e[1]&&e[1],"f"),__classPrivateFieldSet(this,_DBnx_dbConfig,e[0],"f")}connect(e){try{__classPrivateFieldGet(this,_DBnx_usePool,"f")?__classPrivateFieldSet(this,_DBnx_pool,(0,mysql2_1.createPool)(__classPrivateFieldGet(this,_DBnx_dbConfig,"f")).promise(),"f"):__classPrivateFieldSet(this,_DBnx_connection,(0,mysql2_1.createConnection)(__classPrivateFieldGet(this,_DBnx_dbConfig,"f")).promise(),"f"),e&&(this.logger_function("✅ Connection has been established successfully."),e(void 0,"Connection has been established successfully."))}catch(t){this.logger_function(`❌ Error: ${t}`),e&&e(t,void 0)}return this}execute(...e){return __awaiter(this,void 0,void 0,(function*(){var t;const{sql:i,additional:n,params:r,responseFn:o}=__classPrivateFieldGet(this,_DBnx_instances,"m",_DBnx_argumentExecuteParse).call(this,...e),s=i||__classPrivateFieldGet(this,_DBnx_query,"f");if(this.logger_function(`🔍 Execute: ${s}`),!s)throw new Error("No query to execute.");let l;if(__classPrivateFieldGet(this,_DBnx_pool,"f"))l=yield null===(t=__classPrivateFieldGet(this,_DBnx_pool,"f"))||void 0===t?void 0:t.getConnection();else{if(!__classPrivateFieldGet(this,_DBnx_connection,"f"))throw new Error("Database connection is not initialized.");l=__classPrivateFieldGet(this,_DBnx_connection,"f")}try{const[e,t]=yield null==l?void 0:l.execute(s,r),i=Object.assign({success:!0,result:e},n);return o?o(i):i}catch(e){const t={result:[],errno:null==e?void 0:e.errno,success:!1,error:e instanceof Error?e.message:String(e)};return o?o(t):t}finally{__classPrivateFieldSet(this,_DBnx_query,"","f"),__classPrivateFieldGet(this,_DBnx_pool,"f")&&l!==__classPrivateFieldGet(this,_DBnx_connection,"f")&&l&&(yield l.release())}}))}executeQuery(...e){return __awaiter(this,void 0,void 0,(function*(){var t;const{sql:i,additional:n,params:r,responseFn:o}=__classPrivateFieldGet(this,_DBnx_instances,"m",_DBnx_argumentExecuteParse).call(this,...e),s=i||__classPrivateFieldGet(this,_DBnx_query,"f");if(this.logger_function(`📜 Execute: ${s}`),!s)throw new Error("No query to execute.");let l;if(__classPrivateFieldGet(this,_DBnx_pool,"f"))l=yield null===(t=__classPrivateFieldGet(this,_DBnx_pool,"f"))||void 0===t?void 0:t.getConnection();else{if(!__classPrivateFieldGet(this,_DBnx_connection,"f"))throw new Error("Database connection is not initialized.");l=__classPrivateFieldGet(this,_DBnx_connection,"f")}try{const[e,t]=yield null==l?void 0:l.query(s,r),i=Object.assign({success:!0,result:e},n);return o?o(i):i}catch(e){const t={result:[],errno:null==e?void 0:e.errno,success:!1,error:e instanceof Error?e.message:String(e)};return o?o(t):t}finally{__classPrivateFieldSet(this,_DBnx_query,"","f"),__classPrivateFieldGet(this,_DBnx_pool,"f")&&l!==__classPrivateFieldGet(this,_DBnx_connection,"f")&&l&&(yield l.release())}}))}define(e,t,i){const n=class extends model_1.Model{};return Object.defineProperty(n,"name",{value:e}),n.init(e,t,this,i),n}create(...e){var t;if((null==e?void 0:e.length)<2)throw new Error("No arguments provided to 'findFrom'. Expected a table name and/or values.");const i=e[1],n=null!==(t=e[2])&&void 0!==t?t:{};if("function"==typeof e[0]&&"tableName"in e[0])return e[0].create(i,n);let r="string"==typeof e[0]?e[0]:"";if(!r)throw new Error("Expected a table name and/or values.");return __classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.insertInto)(r,i,n),"f"),this.logger_function(`🆕 Create into: \`${r}\``),this}findAll(...e){var t;if(0===e.length)throw new Error("No arguments provided to 'findAll'. Expected a table name or model.");let i="",n=null!==(t=e[1])&&void 0!==t?t:{};if("function"==typeof e[0]&&"tableName"in e[0])return i=e[0].model,e[0].findAll(n);if("string"!=typeof e[0])throw new Error("Invalid first argument: must be a table name or a Model class.");return i=e[0],__classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.findingQuery)(i,n),"f"),this.logger_function(`📋 Find all from: \`${i}\``),this}findOne(...e){var t;if(0===e.length)throw new Error("No arguments provided to 'findOne'. Expected a table name or model.");let i="",n=null!==(t=e[1])&&void 0!==t?t:{};if(n.limitSkip={limit:1},"function"==typeof e[0]&&"tableName"in e[0])return i=e[0].model,e[0].findOne(n);if("string"!=typeof e[0])throw new Error("Invalid first argument: must be a table name or a Model class.");return i=e[0],__classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.findingQuery)(i,n),"f"),this.logger_function(`🔎 Find one from: \`${i}\``),this}update(...e){if(0===e.length)throw new Error("No arguments provided to 'update'. Expected a table name or model.");let t="",i=e[1];if("function"==typeof e[0]&&"tableName"in e[0])return t=e[0].model,e[0].update(i);if("string"!=typeof e[0])throw new Error("Invalid first argument: must be a table name or a Model class.");return t=e[0],__classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.update)(t,i),"f"),this.logger_function(`✏️ Update from: \`${t}\``),this}delete(...e){var t;if(0===e.length)throw new Error("No arguments provided to 'delete'. Expected a table name or model.");let i="",n=null!==(t=e[1])&&void 0!==t?t:{};if("function"==typeof e[0]&&"tableName"in e[0])return i=e[0].model,e[0].delete(n);if("string"!=typeof e[0])throw new Error("Invalid first argument: must be a table name or a Model class.");return i=e[0],__classPrivateFieldSet(this,_DBnx_query,__classPrivateFieldGet(this,_DBnx_query,"f")+(0,query_1.destroy)(i,n),"f"),this.logger_function(`🗑️ Delete from: \`${i}\``),this}logger_function(e){__classPrivateFieldGet(this,_DBnx_logger,"f")&&__classPrivateFieldGet(this,_DBnx_logger,"f").call(this,e)}getConfig(){var e;let t;return __classPrivateFieldGet(this,_DBnx_pool,"f")?t=(null===(e=__classPrivateFieldGet(this,_DBnx_pool,"f"))||void 0===e?void 0:e.pool.config).connectionConfig:__classPrivateFieldGet(this,_DBnx_connection,"f")&&(t=__classPrivateFieldGet(this,_DBnx_connection,"f").config),t||("string"==typeof __classPrivateFieldGet(this,_DBnx_dbConfig,"f")?(0,utilities_1.parseMySQLUrl)(__classPrivateFieldGet(this,_DBnx_dbConfig,"f")):__classPrivateFieldGet(this,_DBnx_dbConfig,"f"))}setQuery(e){return this.logger_function(`⚙️ Query set: ${e}`),__classPrivateFieldSet(this,_DBnx_query,e,"f"),this}build(){const e=__classPrivateFieldGet(this,_DBnx_query,"f");return __classPrivateFieldSet(this,_DBnx_query,"","f"),e}condition(e,t="AND"){return(0,condition_1.dbnxCondition)(e,t)}close(){return __awaiter(this,void 0,void 0,(function*(){__classPrivateFieldGet(this,_DBnx_pool,"f")?(this.logger_function("⏳ Closing connection pool..."),yield __classPrivateFieldGet(this,_DBnx_pool,"f").end(),this.logger_function("✅ Connection pool closed successfully.")):__classPrivateFieldGet(this,_DBnx_connection,"f")?(this.logger_function("⏳ Closing database connection..."),yield __classPrivateFieldGet(this,_DBnx_connection,"f").end(),this.logger_function("✅ Database connection closed successfully.")):this.logger_function("⚠️ No active connection or pool to close.")}))}}exports.DBnx=DBnx,_DBnx_pool=new WeakMap,_DBnx_connection=new WeakMap,_DBnx_query=new WeakMap,_DBnx_dbConfig=new WeakMap,_DBnx_usePool=new WeakMap,_DBnx_logger=new WeakMap,_DBnx_instances=new WeakSet,_DBnx_argumentExecuteParse=function(...e){let t,i,n,r;return 4===e.length?[t,i,n,r]=e:3===e.length?"string"==typeof e[0]&&Array.isArray(e[1])?[t,i,n]=e:[t,n,r]=e:2===e.length?"string"==typeof e[0]?(t=e[0],Array.isArray(e[1])?i=e[1]:"object"==typeof e[1]?n=e[1]:"function"==typeof e[1]&&(r=e[1])):(n=e[0],r=e[1]):1===e.length&&("string"==typeof e[0]?t=e[0]:"function"==typeof e[0]?r=e[0]:"object"==typeof e[0]&&(n=e[0])),{sql:t,params:i,additional:n,responseFn:r}},exports.default=DBnx;

@@ -1,1 +0,1 @@

"use strict";function sanitize(e){return escape(e)}function escape(e){return null==e?"NULL":"number"==typeof e?e.toString():"boolean"==typeof e?e?"1":"0":"string"==typeof e?`'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\t/g,"\t").replace(/\r/g,"\\r").replace(/\f/g,"")}'`:"object"==typeof e?"[object Date]"===Object.prototype.toString.call(e)?`'${e.toISOString()}'`:Array.isArray(e)?`(${e.map((e=>escape(e))).join(", ")})`:Buffer.isBuffer(e)?`'${e.toString("hex")}'`:"function"==typeof e.toSqlString?String(e.toSqlString()):JSON.stringify(e):`${e}`}function format(e,r){let t=0;return e.replace(/\?/g,(()=>{if(t>=r.length)throw new Error("Insufficient values provided for placeholders.");const e=escape(r[t]);return t++,e}))}function parseMySQLUrl(e){const r=e.match(/^(mysql:\/\/)([^:]+):([^@]+)@([^:\/]+)(?::(\d+))?\/([^?]+)(?:\?(.*))?$/);if(!r)throw new Error("Invalid MySQL URL format");const[,,t,o,n,a,s,p]=r,c={};return p&&p.split("&").forEach((e=>{const[r,t]=e.split("=");r&&t&&(c[r]=decodeURIComponent(t))})),{user:t,password:o,host:n,port:a?parseInt(a,10):3306,database:s,params:c}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.sanitize=sanitize,exports.escape=escape,exports.format=format,exports.parseMySQLUrl=parseMySQLUrl;
"use strict";function sanitize(e){return escape(e)}function escape(e){return null==e?"NULL":"number"==typeof e?e.toString():"boolean"==typeof e?e?"1":"0":"string"==typeof e?`'${e.replace(/\0/g,"\\0").replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\t/g,"\t").replace(/\r/g,"\\r").replace(/\f/g,"")}'`:"object"==typeof e?"[object Date]"===Object.prototype.toString.call(e)?`'${e.toISOString()}'`:Array.isArray(e)?`(${e.map((e=>escape(e))).join(", ")})`:Buffer.isBuffer(e)?`'${e.toString("hex")}'`:"function"==typeof e.toSqlString?String(e.toSqlString()):JSON.stringify(e):`${e}`}function format(e,r){let t=0;return e.replace(/\?/g,(()=>{if(t>=r.length)throw new Error("Insufficient values provided for placeholders.");const e=escape(r[t]);return t++,e}))}function parseMySQLUrl(e){const r=e.match(/^(mysql:\/\/)([^:]+):([^@]+)@([^:\/]+)(?::(\d+))?\/([^?]+)(?:\?(.*))?$/);if(!r)throw new Error("Invalid MySQL URL format");const[,,t,o,n,a,p,s]=r,c={};return s&&s.split("&").forEach((e=>{const[r,t]=e.split("=");r&&t&&(c[r]=decodeURIComponent(t))})),{user:t,password:o,host:n,port:a?parseInt(a,10):3306,database:p,params:c}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.sanitize=sanitize,exports.escape=escape,exports.format=format,exports.parseMySQLUrl=parseMySQLUrl;
{
"name": "@dbnx/mysql",
"version": "1.0.20",
"version": "1.0.21",
"description": "A powerful and enhanced ORM library for MySQL, offering query execution, model creation, and full relational management.",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

import { Connection, Pool, ConnectionOptions, PoolOptions } from 'mysql2/promise';
import { Model } from './model';
import { ColumnOptions, ResponseType, TableOptions, CreateOptionsType, CreateParamsType, DeleteParamsType, FindAllParamsType, FindOneParamsType, UpdateParamsType, } from './index';
import { ColumnOptions, ResponseType, TableOptions, CreateOptionsType, CreateParamsType, DeleteParamsType, FindAllParamsType, FindOneParamsType, UpdateParamsType, Filters, } from './index';

@@ -238,2 +238,55 @@ export class DBnx {

/**
* Generates SQL conditions based on the filters object.
* It dynamically builds the WHERE clause for SQL based on the provided filters and logical operations.
*
* @param filters The filters object containing the conditions
* @param joinBy The logical operator to join conditions (default: 'AND', can be 'OR')
* @returns The generated SQL condition string
* @example
* // Example filters
const filters: Filters = {
status: "active", // Exact match
price: { between: [1000, 5000] }, // BETWEEN condition
tags: ["electronics", "home"], // IN condition
location: { not: ["New York", "California"] }, // NOT IN condition
stock: { inRange: [10, 50] }, // IN RANGE condition (BETWEEN)
updatedAt: { isNull: true }, // IS NULL condition
title: { like: "%phone%" }, // LIKE condition (pattern matching)
description: { notLike: "%old%" }, // NOT LIKE condition
color: {
$or: [
{ like: "red" },
{ like: "blue" },
],
}, // OR condition
$and: {
category: "electronics",
brand: { regexp: "^Samsung" }, // REGEXP condition
},
};
* @Output
```sql
SELECT * FROM products WHERE
`status` = 'active' AND
`price` BETWEEN 1000 AND 5000 AND
`tags` IN ('electronics', 'home') AND
`location` NOT IN ('New York', 'California') AND
`stock` BETWEEN 10 AND 50 AND
`updatedAt` IS NULL AND
`title` LIKE '%phone%' AND
`description` NOT LIKE '%old%' AND
(
`color` LIKE 'red' OR
`color` LIKE 'blue'
) AND
(
`category` = 'electronics' AND
`brand` REGEXP '^Samsung'
);
```
*/
public condition(filters: Filters, joinBy: 'AND' | 'OR' = 'AND'): string
/**
* Closes the connection or pool, ensuring all resources are freed.

@@ -240,0 +293,0 @@ * @returns {Promise<void>} - A promise that resolves when the connection or pool is closed.

@@ -11,2 +11,3 @@ import { Response } from 'express';

export * from "./engine options";
export * from "./condition";

@@ -13,0 +14,0 @@ export type Attributes = Record<string, ColumnOptions>;

@@ -0,1 +1,3 @@

import { Filters } from "./condition";
/**

@@ -40,2 +42,56 @@ * Converts a given date (or the current date if none is provided) to a MySQL-compatible

*/
export function format(query: string, values: any[]): string;
export function format(query: string, values: any[]): string;
/**
* Generates SQL conditions based on the filters object.
* It dynamically builds the WHERE clause for SQL based on the provided filters and logical operations.
*
* @param filters The filters object containing the conditions
* @param joinBy The logical operator to join conditions (default: 'AND', can be 'OR')
* @returns The generated SQL condition string
* @example
* // Example filters
const filters: Filters = {
status: "active", // Exact match
price: { between: [1000, 5000] }, // BETWEEN condition
tags: ["electronics", "home"], // IN condition
location: { not: ["New York", "California"] }, // NOT IN condition
stock: { inRange: [10, 50] }, // IN RANGE condition (BETWEEN)
updatedAt: { isNull: true }, // IS NULL condition
title: { like: "%phone%" }, // LIKE condition (pattern matching)
description: { notLike: "%old%" }, // NOT LIKE condition
color: {
$or: [
{ like: "red" },
{ like: "blue" },
],
}, // OR condition
$and: {
category: "electronics",
brand: { regexp: "^Samsung" }, // REGEXP condition
},
};
* @Output
```sql
SELECT * FROM products WHERE
`status` = 'active' AND
`price` BETWEEN 1000 AND 5000 AND
`tags` IN ('electronics', 'home') AND
`location` NOT IN ('New York', 'California') AND
`stock` BETWEEN 10 AND 50 AND
`updatedAt` IS NULL AND
`title` LIKE '%phone%' AND
`description` NOT LIKE '%old%' AND
(
`color` LIKE 'red' OR
`color` LIKE 'blue'
) AND
(
`category` = 'electronics' AND
`brand` REGEXP '^Samsung'
);
```
*/
export function dbnxCondition(filters: Filters, joinBy: 'AND' | 'OR' = 'AND'): string