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

minorm

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minorm - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

.nyc_output/896011ac207864c7e16b405b9ee44f47.json

35

lib/createManager.js

@@ -13,6 +13,2 @@ 'use strict';

var _promise = require('mysql2/promise');
var _promise2 = _interopRequireDefault(_promise);
var _squel = require('squel');

@@ -24,2 +20,4 @@

var _connectionManager = require('./connectionManager');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -30,3 +28,3 @@

const pool = _promise2.default.createPool(connectionConfig);
let pool;
/**

@@ -51,3 +49,15 @@ * {

function getPool() {
if (!pool) {
const msg = 'Please start connection before';
logger && logger.error(msg);
throw new Error(msg);
}
return pool;
}
return {
connect() {
pool = (0, _connectionManager.connect)(connectionConfig);
},
extendRepository(tableName, callback) {

@@ -63,6 +73,5 @@ repos[tableName] = callback(this.getRepository(tableName));

},
getPool() {
return pool;
},
getPool,
clear() {
pool = null;
repos = {};

@@ -72,3 +81,3 @@ associations = {};

getConnection() {
return pool.getConnection();
return getPool().getConnection();
},

@@ -79,7 +88,7 @@ query(sql, values) {

logger && logger.debug(`SQL query: ${ sql.text }`);
return pool.query(sql.text, sql.values);
return getPool().query(sql.text, sql.values);
}
// $FlowIgnore impossible situation
logger && logger.debug(`SQL query: ${ sql }`);
return pool.query(sql, values);
return getPool().query(sql, values);
},

@@ -91,5 +100,7 @@ nestQuery(sql) {

if (sql.text != null && sql.values != null) {
return pool.query({
return getPool().query({
// $FlowIgnore I've already check this
sql: sql.text,
nestTables: true
// $FlowIgnore I've already check this
}, sql.values);

@@ -96,0 +107,0 @@ } else {

@@ -7,2 +7,23 @@ 'use strict';

var _connectionManager = require('./connectionManager');
Object.defineProperty(exports, 'setProvider', {
enumerable: true,
get: function () {
return _connectionManager.setProvider;
}
});
Object.defineProperty(exports, 'resetProvider', {
enumerable: true,
get: function () {
return _connectionManager.resetProvider;
}
});
Object.defineProperty(exports, 'connect', {
enumerable: true,
get: function () {
return _connectionManager.connect;
}
});
var _createManager = require('./createManager');

@@ -9,0 +30,0 @@

{
"name": "minorm",
"version": "0.0.3",
"version": "0.0.4",
"description": "MinORM - minimal MySQL ORM with performance as the Goal",

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

@@ -26,2 +26,3 @@ # MinORM

})
manager.connect()

@@ -28,0 +29,0 @@ export const PostsRepo = {

/** @flow */
import MySQL from 'mysql2/promise'
import Squel from 'squel'
import {createRepository} from './createRepository'
import {connect} from './connectionManager'
import type {Manager, Relation} from './types'
export function createManager(connectionConfig: any, logger?: ?typeof console = null): Manager {
const pool = MySQL.createPool(connectionConfig)
let pool
/**

@@ -28,3 +28,15 @@ * {

function getPool() {
if (!pool) {
const msg = 'Please start connection before'
logger && logger.error(msg)
throw new Error(msg)
}
return pool
}
return {
connect() {
pool = connect(connectionConfig)
},
extendRepository(tableName, callback) {

@@ -40,6 +52,5 @@ repos[tableName] = callback(this.getRepository(tableName))

},
getPool() {
return pool
},
getPool,
clear() {
pool = null
repos = {}

@@ -49,3 +60,3 @@ associations = {}

getConnection() {
return pool.getConnection()
return getPool().getConnection()
},

@@ -56,7 +67,7 @@ query(sql, values) {

logger && logger.debug(`SQL query: ${sql.text}`)
return pool.query(sql.text, sql.values)
return getPool().query(sql.text, sql.values)
}
// $FlowIgnore impossible situation
logger && logger.debug(`SQL query: ${sql}`)
return pool.query(sql, values)
return getPool().query(sql, values)
},

@@ -68,5 +79,7 @@ nestQuery(sql) {

if (sql.text != null && sql.values != null) {
return pool.query({
return getPool().query({
// $FlowIgnore I've already check this
sql: sql.text,
nestTables: true
// $FlowIgnore I've already check this
}, sql.values)

@@ -73,0 +86,0 @@ } else {

/** @flow */
export {
setProvider,
resetProvider,
connect
} from './connectionManager'
export {
createManager
} from './createManager'
} from './createManager'
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