lib/knex-backend.js
function(transaction, bucket, key, values){
		contract(arguments)
			.params('array', 'string', 'string|number','string|array')
			.end()
		;
		
		var self = this;
		var table = '';
		values = Array.isArray(values) ? values : [values]; // we always want to have an array for values
		
		transaction.push(function(cb){
			
			if (bucket.indexOf('allows') != -1) {
				table = self.prefix + self.buckets.permissions;
				self.db
					.select('key', 'value')
					.from(table)
					.where({'key': bucket})
					.then(function(result) {
						if(result.length === 0) {return;}
						
						// update the permissions for the role by removing what was requested
						_.each(values, function(value) {
							result[0].value[key] = _.without(result[0].value[key], value);
						});
						
						//  if no more permissions in the role then remove the role
						if (!result[0].value[key].length) {
							result[0].value = _.omit(result[0].value, key);
						}
						
						return self.db(table)
							.where('key', bucket)
							.update({value: result[0].value})
						;
					})
					.then(function() {
						cb(undefined);
					})
				;
			} else {
				table = self.prefix + bucket;
				self.db
					.select('key', 'value')
					.from(table)
					.where({'key': key})
					.then(function(result) {
						if(result.length === 0) {return;}
						
						var resultValues = result[0].value;
						// if we have found the key in the table then lets remove the values from it
						_.each(values, function(value) {
							resultValues = _.without(resultValues, value);
						});
						return self.db(table)
							.where('key', key)
							.update({value: resultValues})
						;
					})
					.then(function() {
						cb(undefined);
					})
				;
			}
		});
	}
function(transaction, bucket, key, values){
		contract(arguments)
			.params('array', 'string', 'string|number','string|array')
			.end()
		;
		
		var self = this;
		var table = '';
		values = Array.isArray(values) ? values : [values]; // we always want to have an array for values
		
		transaction.push(function(cb){
			
			if (bucket.indexOf('allows') != -1) {
				table = self.prefix + self.buckets.permissions;
				self.db
					.select('key', 'value')
					.from(table)
					.where({'key': bucket})
					.then(function(result) {
						if(result.length === 0) {return;}
						
						// update the permissions for the role by removing what was requested
						_.each(values, function(value) {
							result[0].value[key] = _.without(result[0].value[key], value);
						});
						
						//  if no more permissions in the role then remove the role
						if (!result[0].value[key].length) {
							result[0].value = _.omit(result[0].value, key);
						}
						
						return self.db(table)
							.where('key', bucket)
							.update({value: result[0].value})
						;
					})
					.then(function() {
						cb(undefined);
					})
				;
			} else {
				table = self.prefix + bucket;
				self.db
					.select('key', 'value')
					.from(table)
					.where({'key': key})
					.then(function(result) {
						if(result.length === 0) {return;}
						
						var resultValues = result[0].value;
						// if we have found the key in the table then lets remove the values from it
						_.each(values, function(value) {
							resultValues = _.without(resultValues, value);
						});
						return self.db(table)
							.where('key', key)
							.update({value: resultValues})
						;
					})
					.then(function() {
						cb(undefined);
					})
				;
			}
		});
	}
function ( transaction , bucket , key , values ) { contract ( arguments ) . params ( 'array' , 'string' , 'string|number' , 'string|array' ) . end ( ) ; var self = this ; var table = '' ; values = Array . isArray ( values ) ? values : [ values ] ; // we always want to have an array for values transaction . push ( function ( cb ) { if ( bucket . indexOf ( 'allows' ) != - 1 ) { table = self . prefix + self . buckets . permissions ; self . db . select ( 'key' , 'value' ) . from ( table ) . where ( { 'key' : bucket } ) . then ( function ( result ) { if ( result . length === 0 ) { return ; } // update the permissions for the role by removing what was requested _ . each ( values , function ( value ) { result [ 0 ] . value [ key ] = _ . without ( result [ 0 ] . value [ key ] , value ) ; } ) ; //  if no more permissions in the role then remove the role if ( ! result [ 0 ] . value [ key ] . length ) { result [ 0 ] . value = _ . omit ( result [ 0 ] . value , key ) ; } return self . db ( table ) . where ( 'key' , bucket ) . update ( { value : result [ 0 ] . value } ) ; } ) . then ( function ( ) { cb ( undefined ) ; } ) ; } else { table = self . prefix + bucket ; self . db . select ( 'key' , 'value' ) . from ( table ) . where ( { 'key' : key } ) . then ( function ( result ) { if ( result . length === 0 ) { return ; } var resultValues = result [ 0 ] . value ; // if we have found the key in the table then lets remove the values from it _ . each ( values , function ( value ) { resultValues = _ . without ( resultValues , value ) ; } ) ; return self . db ( table ) . where ( 'key' , key ) . update ( { value : resultValues } ) ; } ) . then ( function ( ) { cb ( undefined ) ; } ) ; } } ) ; }
Removes values from a given key inside a bucket.
Removes values from a given key inside a bucket .