From 0b95171ec4f6120f18f6df40dbf1e11498c7397f Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 25 Aug 2016 10:32:09 +0200 Subject: [PATCH] Support long ids. --- src/connector.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/connector.js b/src/connector.js index d648feb..ce31b11 100644 --- a/src/connector.js +++ b/src/connector.js @@ -8,6 +8,7 @@ const TableManager = require( './table-manager' ) const dataTransform = require( './transform-data' ) const pckg = require( '../package.json' ) const PRIMARY_KEY = require( './primary-key') +const crypto = require( 'crypto' ) class Connector extends EventEmitter { @@ -157,12 +158,15 @@ class Connector extends EventEmitter { */ _getParams( key ) { const parts = key.split( this._splitChar ) + const params = parts.length === 2 + ? { table: parts[ 0 ], id: parts[ 1 ] } + : { table: this._defaultTable, id: key } - if( parts.length === 2 ) { - return { table: parts[ 0 ], id: parts[ 1 ] } - } else { - return { table: this._defaultTable, id: key } + if (params.id.length > 127) { + params.id = crypto.createHash('sha1').update(params.id).digest("hex") } + + return params } /** @@ -202,4 +206,4 @@ class Connector extends EventEmitter { } } } -module.exports = Connector \ No newline at end of file +module.exports = Connector