Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fxjs/db-driver

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fxjs/db-driver - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

2

lib/built-ins/base.class.js

@@ -50,3 +50,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

get uri() {
return url.format(Object.assign({}, this.config, { slashes: this.config.protocol === 'sqlite:' ? false : this.config.slashes }));
return url.format(Object.assign({}, this.config, { slashes: this.config.protocol === 'sqlite:' ? false : this.config.slashes, query: this.config.protocol === 'sqlite:' ? {} : this.config.query }));
}

@@ -53,0 +53,0 @@ get isPool() {

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

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var db=_interopDefault(require("db")),url=_interopDefault(require("url")),assert=_interopDefault(require("assert")),coroutine=_interopDefault(require("coroutine")),util=_interopDefault(require("util")),net=_interopDefault(require("net")),uuid=_interopDefault(require("uuid")),querystring=_interopDefault(require("querystring")),timers=_interopDefault(require("timers"));function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}function setPropertyByPath(e,t,n,r="."){if("string"==typeof t)t=t.split(r);else if(!Array.isArray(t))return;let o,i=t.shift();if(0==t.length)return void(e[i]=n);"object"!=typeof e[i]&&(e[i]={});let s=e[i]=e[i]||{};for(;t.length>0;)s[o=t.shift()]=s[o]||{},t.length>0?s=s[o]:s[o]!==n&&(s[o]=n)}function transformStringValue(e,{arrayFormat:t="comma"}={}){return"comma"===t&&"string"==typeof e&&e.indexOf(",")>-1&&(e=e.split(",")),e}var lib=function(e,{arrayFormat:t="comma"}={}){e||(e={});const n={};let r=e;if("string"==typeof r)r=querystring.parse(r).toJSON();else{if("object"!=typeof r)return n;"function"==typeof r.toJSON&&(r=r.toJSON())}return Object.keys(r).sort().forEach(e=>{const o=transformStringValue(r[e],{arrayFormat:t});e.indexOf(".")>-1?setPropertyByPath(n,e,o):n[e]=o}),n};const Pool=function(e,t,n){var r=e;util.isFunction(e)&&(r={create:e,maxsize:t,timeout:n});var o=r.create,i=r.destroy||(e=>{util.isFunction(e.close)&&e.close(),util.isFunction(e.destroy)&&e.destroy(),util.isFunction(e.dispose)&&e.dispose()});t=r.maxsize||10;var s=(n=r.timeout||6e4)/10;s<10&&(s=10);var u,c=r.retry||1,l=[],a=[],p=0,f=0,h=new coroutine.Semaphore(t);function m(){for(var e,t=(new Date).getTime();p&&t-(e=l[0]).time.getTime()>n;)l=l.slice(1),p--,void 0!==e.o&&coroutine.start(i,e.o);p?u||(u=timers.setInterval(m,s)):u&&(u.clear(),u=null)}function d(e,t,n){for(var r=0;r<a.length;r++){var o=a[r];if(o.name===e)return a.splice(r,1),o.o=t,o.e=n,void o.ev.set()}void 0===n&&(l[p++]={o:t,name:e,time:new Date})}function g(e){for(var t,n,r=0;;)try{t=o(e);break}catch(e){if(++r>=c){n=e;break}}d(e,t,n)}var y=(...e)=>{var t,n,r=e[0],o=e[1],s=r;util.isFunction(r)&&(o=r,s="");var u=!1;if(m(),h.acquire(),p)for(var c=p-1;c>=0;c--)if(l[c].name===s){u=!0,n=l[c].o,l.splice(c,1),p--;break}if(!u){coroutine.start(g,s);var y={name:s,ev:new coroutine.Event};if(a.push(y),y.ev.wait(),y.e)throw h.post(),y.e;n=y.o}f++;try{t=o(n),d(s,n)}catch(e){throw void 0!==n&&coroutine.start(i,n),e}finally{f--,h.post(),m()}return t};return y.connections=(()=>p),y.info=(()=>({maxsize:t,count:p,running:f,wait:h.count(),timeout:n})),y.clear=(()=>{n=-1,m()}),y};var lib$1=Pool,utils=createCommonjsModule(function(e,t){function n(e,t){try{e=parseInt(e)}catch(t){e=null}return(null===e||isNaN(e))&&(e=t),e}function r(e){if(!e||!0===e)return{};if("object"!=typeof e)return{};const{maxsize:t,timeout:n,retry:r}=e||{};return{maxsize:t,timeout:n,retry:r}}Object.defineProperty(t,"__esModule",{value:!0}),t.driverUUid=function(){return uuid.node().hex()},t.filterDriverType=function(e){switch(e){case"sqlite:":return"sqlite";case"mysql:":return"mysql";case"redis:":return"redis";case"mongodb:":return"mongodb";default:return"unknown"}},t.forceInteger=n,t.castQueryStringToBoolean=function(e){switch(e){case"1":case"true":case"y":return!0;case"0":case"false":case"no":case"n":case"":return!1;default:return!!e}},t.ensureSuffix=function(e="",t="//"){if(!e||"string"!=typeof e)return"";const n=e.lastIndexOf(t);return e.slice(n)!==t&&(e+=t),e},t.parseConnectionString=function(e){let t=(e=e||{})instanceof net.Url?e:null;return"string"==typeof e?e={protocol:(t=url.parse(e)).protocol||null,slashes:t.slashes||!1,query:t.query||null,username:t.username||null,password:t.password||null,host:t.host||null,hostname:t.hostname||null,port:t.port||null,href:t.href||null,database:function(e="",t="/"){return e&&"string"==typeof e?(e.slice(0,t.length)===t&&(e=e.slice(t.length)),e):""}(t.pathname,"/")||null,pathname:t.pathname||null}:"object"!=typeof e&&(e={}),e.user&&!e.username&&(e.username=e.user),delete e.user,"string"==typeof e.query&&(e.query=lib(e.query)),e.query=Object.assign({},e.query),e=Object.assign({},e),(e=util.pick(e,["protocol","slashes","query","database","username","password","host","hostname","port","href","pathname"])).slashes=!!e.slashes,e.port=n(e.port,null),e},t.parsePoolConfig=r,t.mountPoolToDriver=function(e,t=e.config.pool){!e.pool&&t&&(e.pool=lib$1(Object.assign({create:()=>e.getConnection(),destroy:e=>e.close()},r(t))))},t.arraify=function(e){return Array.isArray(e)?e:[e]}});unwrapExports(utils);var utils_1=utils.driverUUid,utils_2=utils.filterDriverType,utils_3=utils.forceInteger,utils_4=utils.castQueryStringToBoolean,utils_5=utils.ensureSuffix,utils_6=utils.parseConnectionString,utils_7=utils.parsePoolConfig,utils_8=utils.mountPoolToDriver,utils_9=utils.arraify,base_class=createCommonjsModule(function(e,t){Object.defineProperty(t,"__esModule",{value:!0});class n{constructor(e){this.extend_config={pool:!1,debug:!1},e=utils.parseConnectionString(e),Object.defineProperty(this,"config",{get:()=>e}),assert.ok(!!this.config.protocol,"[driver.config] invalid protocol"),this.type=utils.filterDriverType(this.config.protocol);const t={};Object.defineProperty(this,"extend_config",{get:()=>t}),function(e){let t=!1;Object.defineProperty(e.extend_config,"pool",{set(n){"string"==typeof n&&(n=utils.castQueryStringToBoolean(n)),n?((t=utils.parsePoolConfig(n)).maxsize=utils.forceInteger(t.maxsize,100),t.timeout=utils.forceInteger(t.timeout,1e3),utils.mountPoolToDriver(e,t)):t=!1},get:()=>t})}(this),t.pool=e.query.pool,t.debug=utils.castQueryStringToBoolean(e.query.debug),Object.defineProperty(this,"uid",{value:utils.driverUUid(),writable:!1,configurable:!1})}static create(e){return new(n.getDriver("object"==typeof e?e.protocol:e))(e)}get uri(){return url.format(Object.assign({},this.config,{slashes:"sqlite:"!==this.config.protocol&&this.config.slashes}))}get isPool(){return!!this.extend_config.pool}get isSql(){const e=this.config.protocol||"";return"mysql:"===e||e.startsWith("sqlite:")}get isNoSql(){return"mongodb:"===(this.config.protocol||"")}get isCommand(){const e=this.config.protocol||"";return"mongodb:"===e||"redis:"===e}reopen(){try{this.close()}catch(e){}return this.open()}open(){return this.connection=this.getConnection()}close(){}ping(){}getConnection(){return null}connectionPool(e){return this.isPool?this.pool(t=>e(t)):e(this.open())}}n.getDriver=function e(t){switch(t){case"mysql":return o;case"sqlite":return i;case"redis":return s;case"mongodb":return u;default:if(t){const n=utils.filterDriverType(url.parse(t).protocol);if("unknown"!==n)return e(n)}return n}},t.Driver=n;class r extends n{constructor(){super(...arguments),this.currentDb=null}switchDb(e){}begin(){}commit(){}trans(e){return!0}rollback(){}execute(e){}}t.SQLDriver=r;class o extends r{constructor(e){super(e),this.connection=null}switchDb(e){this.execute(db.formatMySQL("use `"+db.escape(e)+"`"))}open(){return super.open()}close(){this.connection&&this.connection.close()}ping(){}begin(){return this.connection.begin()}commit(){return this.connection.commit()}trans(e){return this.connection.trans(e)}rollback(){return this.connection.rollback()}getConnection(){return db.openMySQL(this.uri)}execute(e){return this.isPool?this.pool(t=>t.execute(e)):(this.connection||this.open(),this.connection.execute(e))}}class i extends r{constructor(e){super(e),this.connection=null}open(){return super.open()}close(){this.connection&&this.connection.close()}ping(){}begin(){return this.connection.begin()}commit(){return this.connection.commit()}trans(e){return this.connection.trans(e)}rollback(){return this.connection.rollback()}getConnection(){return db.openSQLite(this.uri)}execute(e){return this.isPool?this.pool(t=>t.execute(e)):(this.connection||this.open(),this.connection.execute(e))}}class s extends n{constructor(e){super(e),this.connection=null}open(){return super.open()}close(){this.connection&&this.connection.close()}ping(){}command(e,...t){return this.isPool?this.pool(n=>n.command(e,...t)):(this.connection||this.open(),this.connection.command(e,...t))}commands(e,t){const{parallel:n=!1}=t||{},r=Object.keys(e);return n?coroutine.parallel(r,t=>({cmd:t,result:this.command(t,...utils.arraify(e[t]))})):Object.keys(e).map(t=>({cmd:t,result:this.command(t,...utils.arraify(e[t]))}))}getConnection(){return db.openRedis(this.uri)}}class u extends n{constructor(e){super(e),this.connection=null}reopen(){try{this.close()}catch(e){}return this.open()}open(){return super.open()}close(){this.connection&&this.connection.close()}ping(){}command(e,t){return this.commands({[e]:t})}commands(e,t){return this.isPool?this.pool(t=>t.runCommand(e)):(this.connection||this.open(),this.connection.runCommand(e))}getConnection(){return db.openMongoDB(this.uri)}}});unwrapExports(base_class);var base_class_1=base_class.Driver,base_class_2=base_class.SQLDriver,lib$2=base_class.Driver;module.exports=lib$2;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var db=_interopDefault(require("db")),url=_interopDefault(require("url")),assert=_interopDefault(require("assert")),coroutine=_interopDefault(require("coroutine")),util=_interopDefault(require("util")),net=_interopDefault(require("net")),uuid=_interopDefault(require("uuid")),querystring=_interopDefault(require("querystring")),timers=_interopDefault(require("timers"));function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}function setPropertyByPath(e,t,n,o="."){if("string"==typeof t)t=t.split(o);else if(!Array.isArray(t))return;let r,i=t.shift();if(0==t.length)return void(e[i]=n);"object"!=typeof e[i]&&(e[i]={});let s=e[i]=e[i]||{};for(;t.length>0;)s[r=t.shift()]=s[r]||{},t.length>0?s=s[r]:s[r]!==n&&(s[r]=n)}function transformStringValue(e,{arrayFormat:t="comma"}={}){return"comma"===t&&"string"==typeof e&&e.indexOf(",")>-1&&(e=e.split(",")),e}var lib=function(e,{arrayFormat:t="comma"}={}){e||(e={});const n={};let o=e;if("string"==typeof o)o=querystring.parse(o).toJSON();else{if("object"!=typeof o)return n;"function"==typeof o.toJSON&&(o=o.toJSON())}return Object.keys(o).sort().forEach(e=>{const r=transformStringValue(o[e],{arrayFormat:t});e.indexOf(".")>-1?setPropertyByPath(n,e,r):n[e]=r}),n};const Pool=function(e,t,n){var o=e;util.isFunction(e)&&(o={create:e,maxsize:t,timeout:n});var r=o.create,i=o.destroy||(e=>{util.isFunction(e.close)&&e.close(),util.isFunction(e.destroy)&&e.destroy(),util.isFunction(e.dispose)&&e.dispose()});t=o.maxsize||10;var s=(n=o.timeout||6e4)/10;s<10&&(s=10);var u,c=o.retry||1,l=[],a=[],p=0,f=0,h=new coroutine.Semaphore(t);function m(){for(var e,t=(new Date).getTime();p&&t-(e=l[0]).time.getTime()>n;)l=l.slice(1),p--,void 0!==e.o&&coroutine.start(i,e.o);p?u||(u=timers.setInterval(m,s)):u&&(u.clear(),u=null)}function d(e,t,n){for(var o=0;o<a.length;o++){var r=a[o];if(r.name===e)return a.splice(o,1),r.o=t,r.e=n,void r.ev.set()}void 0===n&&(l[p++]={o:t,name:e,time:new Date})}function g(e){for(var t,n,o=0;;)try{t=r(e);break}catch(e){if(++o>=c){n=e;break}}d(e,t,n)}var y=(...e)=>{var t,n,o=e[0],r=e[1],s=o;util.isFunction(o)&&(r=o,s="");var u=!1;if(m(),h.acquire(),p)for(var c=p-1;c>=0;c--)if(l[c].name===s){u=!0,n=l[c].o,l.splice(c,1),p--;break}if(!u){coroutine.start(g,s);var y={name:s,ev:new coroutine.Event};if(a.push(y),y.ev.wait(),y.e)throw h.post(),y.e;n=y.o}f++;try{t=r(n),d(s,n)}catch(e){throw void 0!==n&&coroutine.start(i,n),e}finally{f--,h.post(),m()}return t};return y.connections=(()=>p),y.info=(()=>({maxsize:t,count:p,running:f,wait:h.count(),timeout:n})),y.clear=(()=>{n=-1,m()}),y};var lib$1=Pool,utils=createCommonjsModule(function(e,t){function n(e,t){try{e=parseInt(e)}catch(t){e=null}return(null===e||isNaN(e))&&(e=t),e}function o(e){if(!e||!0===e)return{};if("object"!=typeof e)return{};const{maxsize:t,timeout:n,retry:o}=e||{};return{maxsize:t,timeout:n,retry:o}}Object.defineProperty(t,"__esModule",{value:!0}),t.driverUUid=function(){return uuid.node().hex()},t.filterDriverType=function(e){switch(e){case"sqlite:":return"sqlite";case"mysql:":return"mysql";case"redis:":return"redis";case"mongodb:":return"mongodb";default:return"unknown"}},t.forceInteger=n,t.castQueryStringToBoolean=function(e){switch(e){case"1":case"true":case"y":return!0;case"0":case"false":case"no":case"n":case"":return!1;default:return!!e}},t.ensureSuffix=function(e="",t="//"){if(!e||"string"!=typeof e)return"";const n=e.lastIndexOf(t);return e.slice(n)!==t&&(e+=t),e},t.parseConnectionString=function(e){let t=(e=e||{})instanceof net.Url?e:null;return"string"==typeof e?e={protocol:(t=url.parse(e)).protocol||null,slashes:t.slashes||!1,query:t.query||null,username:t.username||null,password:t.password||null,host:t.host||null,hostname:t.hostname||null,port:t.port||null,href:t.href||null,database:function(e="",t="/"){return e&&"string"==typeof e?(e.slice(0,t.length)===t&&(e=e.slice(t.length)),e):""}(t.pathname,"/")||null,pathname:t.pathname||null}:"object"!=typeof e&&(e={}),e.user&&!e.username&&(e.username=e.user),delete e.user,"string"==typeof e.query&&(e.query=lib(e.query)),e.query=Object.assign({},e.query),e=Object.assign({},e),(e=util.pick(e,["protocol","slashes","query","database","username","password","host","hostname","port","href","pathname"])).slashes=!!e.slashes,e.port=n(e.port,null),e},t.parsePoolConfig=o,t.mountPoolToDriver=function(e,t=e.config.pool){!e.pool&&t&&(e.pool=lib$1(Object.assign({create:()=>e.getConnection(),destroy:e=>e.close()},o(t))))},t.arraify=function(e){return Array.isArray(e)?e:[e]}});unwrapExports(utils);var utils_1=utils.driverUUid,utils_2=utils.filterDriverType,utils_3=utils.forceInteger,utils_4=utils.castQueryStringToBoolean,utils_5=utils.ensureSuffix,utils_6=utils.parseConnectionString,utils_7=utils.parsePoolConfig,utils_8=utils.mountPoolToDriver,utils_9=utils.arraify,base_class=createCommonjsModule(function(e,t){Object.defineProperty(t,"__esModule",{value:!0});class n{constructor(e){this.extend_config={pool:!1,debug:!1},e=utils.parseConnectionString(e),Object.defineProperty(this,"config",{get:()=>e}),assert.ok(!!this.config.protocol,"[driver.config] invalid protocol"),this.type=utils.filterDriverType(this.config.protocol);const t={};Object.defineProperty(this,"extend_config",{get:()=>t}),function(e){let t=!1;Object.defineProperty(e.extend_config,"pool",{set(n){"string"==typeof n&&(n=utils.castQueryStringToBoolean(n)),n?((t=utils.parsePoolConfig(n)).maxsize=utils.forceInteger(t.maxsize,100),t.timeout=utils.forceInteger(t.timeout,1e3),utils.mountPoolToDriver(e,t)):t=!1},get:()=>t})}(this),t.pool=e.query.pool,t.debug=utils.castQueryStringToBoolean(e.query.debug),Object.defineProperty(this,"uid",{value:utils.driverUUid(),writable:!1,configurable:!1})}static create(e){return new(n.getDriver("object"==typeof e?e.protocol:e))(e)}get uri(){return url.format(Object.assign({},this.config,{slashes:"sqlite:"!==this.config.protocol&&this.config.slashes,query:"sqlite:"===this.config.protocol?{}:this.config.query}))}get isPool(){return!!this.extend_config.pool}get isSql(){const e=this.config.protocol||"";return"mysql:"===e||e.startsWith("sqlite:")}get isNoSql(){return"mongodb:"===(this.config.protocol||"")}get isCommand(){const e=this.config.protocol||"";return"mongodb:"===e||"redis:"===e}reopen(){try{this.close()}catch(e){}return this.open()}open(){return this.connection=this.getConnection()}close(){}ping(){}getConnection(){return null}connectionPool(e){return this.isPool?this.pool(t=>e(t)):e(this.open())}}n.getDriver=function e(t){switch(t){case"mysql":return r;case"sqlite":return i;case"redis":return s;case"mongodb":return u;default:if(t){const n=utils.filterDriverType(url.parse(t).protocol);if("unknown"!==n)return e(n)}return n}},t.Driver=n;class o extends n{constructor(){super(...arguments),this.currentDb=null}switchDb(e){}begin(){}commit(){}trans(e){return!0}rollback(){}execute(e){}}t.SQLDriver=o;class r extends o{constructor(e){super(e),this.connection=null}switchDb(e){this.execute(db.formatMySQL("use `"+db.escape(e)+"`"))}open(){return super.open()}close(){this.connection&&this.connection.close()}ping(){}begin(){return this.connection.begin()}commit(){return this.connection.commit()}trans(e){return this.connection.trans(e)}rollback(){return this.connection.rollback()}getConnection(){return db.openMySQL(this.uri)}execute(e){return this.isPool?this.pool(t=>t.execute(e)):(this.connection||this.open(),this.connection.execute(e))}}class i extends o{constructor(e){super(e),this.connection=null}open(){return super.open()}close(){this.connection&&this.connection.close()}ping(){}begin(){return this.connection.begin()}commit(){return this.connection.commit()}trans(e){return this.connection.trans(e)}rollback(){return this.connection.rollback()}getConnection(){return db.openSQLite(this.uri)}execute(e){return this.isPool?this.pool(t=>t.execute(e)):(this.connection||this.open(),this.connection.execute(e))}}class s extends n{constructor(e){super(e),this.connection=null}open(){return super.open()}close(){this.connection&&this.connection.close()}ping(){}command(e,...t){return this.isPool?this.pool(n=>n.command(e,...t)):(this.connection||this.open(),this.connection.command(e,...t))}commands(e,t){const{parallel:n=!1}=t||{},o=Object.keys(e);return n?coroutine.parallel(o,t=>({cmd:t,result:this.command(t,...utils.arraify(e[t]))})):Object.keys(e).map(t=>({cmd:t,result:this.command(t,...utils.arraify(e[t]))}))}getConnection(){return db.openRedis(this.uri)}}class u extends n{constructor(e){super(e),this.connection=null}reopen(){try{this.close()}catch(e){}return this.open()}open(){return super.open()}close(){this.connection&&this.connection.close()}ping(){}command(e,t){return this.commands({[e]:t})}commands(e,t){return this.isPool?this.pool(t=>t.runCommand(e)):(this.connection||this.open(),this.connection.runCommand(e))}getConnection(){return db.openMongoDB(this.uri)}}});unwrapExports(base_class);var base_class_1=base_class.Driver,base_class_2=base_class.SQLDriver,lib$2=base_class.Driver;module.exports=lib$2;
{
"name": "@fxjs/db-driver",
"version": "0.0.5",
"version": "0.0.6",
"description": "Fibjs Db Driver",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc