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

foxhound

Package Overview
Dependencies
Maintainers
3
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

foxhound - npm Package Compare versions

Comparing version 1.0.37 to 1.0.38

2

.config/configstore/update-notifier-npm.json
{
"optOut": false,
"lastUpdateCheck": 1648063932373
"lastUpdateCheck": 1653489092676
}

@@ -27,4 +27,6 @@ var libFable = require('fable').new({});

/*
var tmpQuery = libFoxHound.new(libFable)
.setDialect('MeadowEndpoints')
//.setDialect('MeadowEndpoints')
.setDialect('MySQL')
.setScope('Animal')

@@ -43,5 +45,16 @@ .setDataElements(['Name', 'Age', 'Cost'])

tmpQuery.buildReadQuery();
// This is the query generated by the MeadowEndpoints dialect
// This is the query generated by the set dialect
libFable.log.trace('Select Query', tmpQuery.query);
*/
var tmpQuery = libFoxHound.new(libFable)
//.setDialect('MeadowEndpoints')
.setDialect('MySQL')
.setScope('Animal')
.addFilter('IDAnimal', 10);
tmpQuery.query.schema = _AnimalSchema;
// Build the query
tmpQuery.buildUndeleteQuery();
// This is the query generated by the set dialect
libFable.log.trace('Query: ', tmpQuery.query);
console.log(tmpQuery.query.body);
{
"name": "foxhound",
"version": "1.0.37",
"version": "1.0.38",
"description": "A Database Query generation library.",

@@ -5,0 +5,0 @@ "main": "source/FoxHound.js",

@@ -23,12 +23,12 @@ /**

/**
* Generate a table name from the scope.
*
* Because ALASQL is all in-memory, and can be run in two modes (anonymous
* working on arrays or table-based) we are going to make this a programmable
* value. Then we can share the code across both providers.
*
* @method: generateTableName
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate a table name from the scope.
*
* Because ALASQL is all in-memory, and can be run in two modes (anonymous
* working on arrays or table-based) we are going to make this a programmable
* value. Then we can share the code across both providers.
*
* @method: generateTableName
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateTableName = function(pParameters)

@@ -40,4 +40,4 @@ {

/**
* Escape columns, because ALASQL has more reserved KWs than most SQL dialects
*/
* Escape columns, because ALASQL has more reserved KWs than most SQL dialects
*/
var escapeColumn = (pColumn, pParameters) =>

@@ -66,12 +66,12 @@ {

/**
* Generate a field list from the array of dataElements
*
* Each entry in the dataElements is a simple string
*
* @method: generateFieldList
* @param: {Object} pParameters SQL Query Parameters
* @param {Boolean} pIsForCountClause (optional) If true, generate fields for use within a count clause.
* @return: {String} Returns the field list clause, or empty string if explicit fields are requested but cannot be fulfilled
* due to missing schema.
*/
* Generate a field list from the array of dataElements
*
* Each entry in the dataElements is a simple string
*
* @method: generateFieldList
* @param: {Object} pParameters SQL Query Parameters
* @param {Boolean} pIsForCountClause (optional) If true, generate fields for use within a count clause.
* @return: {String} Returns the field list clause, or empty string if explicit fields are requested but cannot be fulfilled
* due to missing schema.
*/
var generateFieldList = function(pParameters, pIsForCountClause)

@@ -115,5 +115,5 @@ {

/**
* Generate a query from the array of where clauses
*
* Each clause is an object like:
* Generate a query from the array of where clauses
*
* Each clause is an object like:
{

@@ -126,7 +126,7 @@ Column:'Name',

}
*
* @method: generateWhere
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the WHERE clause prefixed with WHERE, or an empty string if unnecessary
*/
*
* @method: generateWhere
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the WHERE clause prefixed with WHERE, or an empty string if unnecessary
*/
var generateWhere = function(pParameters)

@@ -237,11 +237,11 @@ {

/**
* Generate an ORDER BY clause from the sort array
*
* Each entry in the sort is an object like:
* {Column:'Color',Direction:'Descending'}
*
* @method: generateOrderBy
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the field list clause
*/
* Generate an ORDER BY clause from the sort array
*
* Each entry in the sort is an object like:
* {Column:'Color',Direction:'Descending'}
*
* @method: generateOrderBy
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the field list clause
*/
var generateOrderBy = function(pParameters)

@@ -273,8 +273,8 @@ {

/**
* Generate the limit clause
*
* @method: generateLimit
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the limit clause
*
* @method: generateLimit
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateLimit = function(pParameters)

@@ -301,8 +301,8 @@ {

/**
* Generate the update SET clause
*
* @method: generateUpdateSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the update SET clause
*
* @method: generateUpdateSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateUpdateSetters = function(pParameters)

@@ -402,8 +402,8 @@ {

/**
* Generate the update-delete SET clause
*
* @method: generateUpdateDeleteSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the update-delete SET clause
*
* @method: generateUpdateDeleteSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateUpdateDeleteSetters = function(pParameters)

@@ -480,8 +480,82 @@ {

/**
* Generate the create SET clause
*
* @method: generateCreateSetList
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the update-delete SET clause
*
* @method: generateUpdateDeleteSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateUpdateUndeleteSetters = function(pParameters)
{
if (pParameters.query.disableDeleteTracking)
{
//Don't generate an UPDATE query if Delete tracking is disabled
return false;
}
// Check if there is a schema. If so, we will use it to decide if these are parameterized or not.
var tmpSchema = Array.isArray(pParameters.query.schema) ? pParameters.query.schema : [];
var tmpCurrentColumn = 0;
var tmpHasDeletedField = false;
var tmpUpdate = '';
// No hash table yet, so, we will just linear search it for now.
// This uses the schema to decide if we want to treat a column differently on insert
var tmpSchemaEntry = {Type:'Default'};
for (var i = 0; i < tmpSchema.length; i++)
{
// There is a schema entry for it. Process it accordingly.
tmpSchemaEntry = tmpSchema[i];
var tmpUpdateSql = null;
switch (tmpSchemaEntry.Type)
{
case 'Deleted':
tmpUpdateSql = ' '+escapeColumn(tmpSchemaEntry.Column, pParameters)+' = 0';
tmpHasDeletedField = true; //this field is required in order for query to be built
break;
case 'UpdateDate':
// Delete operation is an Update, so we should stamp the update time
tmpUpdateSql = ' '+escapeColumn(tmpSchemaEntry.Column, pParameters)+' = NOW()';
break;
case 'UpdateIDUser':
// This is the user ID, which we hope is in the query.
// This is how to deal with a normal column
var tmpColumnParameter = tmpSchemaEntry.Column+'_'+tmpCurrentColumn;
tmpUpdateSql = ' '+escapeColumn(tmpSchemaEntry.Column, pParameters)+' = :'+tmpColumnParameter;
// Set the query parameter
pParameters.query.parameters[tmpColumnParameter] = pParameters.query.IDUser;
break;
default:
//DON'T allow update of other fields in this query
continue;
}
if (tmpCurrentColumn > 0)
{
tmpUpdate += ',';
}
tmpUpdate += tmpUpdateSql;
// We use a number to make sure parameters are unique.
tmpCurrentColumn++;
}
// We need to tell the query not to generate improperly if there are no values set.
if (!tmpHasDeletedField ||
tmpUpdate === '')
{
return false;
}
return tmpUpdate;
};
/**
* Generate the create SET clause
*
* @method: generateCreateSetList
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateCreateSetValues = function(pParameters)

@@ -626,8 +700,8 @@ {

/**
* Generate the create SET clause
*
* @method: generateCreateSetList
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the create SET clause
*
* @method: generateCreateSetList
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateCreateSetList = function(pParameters)

@@ -769,2 +843,19 @@ {

var Undelete = function(pParameters)
{
var tmpTableName = generateTableName(pParameters);
var tmpWhere = generateWhere(pParameters);
var tmpUpdateUndeleteSetters = generateUpdateUndeleteSetters(pParameters);
if (tmpUpdateUndeleteSetters)
{
//If it has a deleted bit, update it instead of actually deleting the record
return 'UPDATE'+tmpTableName+' SET'+tmpUpdateUndeleteSetters+tmpWhere+';';
}
else
{
return 'SELECT NULL;';
}
};
var Count = function(pParameters)

@@ -805,2 +896,3 @@ {

Delete: Delete,
Undelete: Undelete,
Count: Count

@@ -810,7 +902,7 @@ });

/**
* Dialect Name
*
* @property name
* @type string
*/
* Dialect Name
*
* @property name
* @type string
*/
Object.defineProperty(tmpDialect, 'name',

@@ -817,0 +909,0 @@ {

@@ -57,2 +57,9 @@ /**

var Undelete = function(pParameters)
{
var tmpScope = pParameters.scope;
return 'I am undeleting your '+tmpScope+'.';
};
var Count = function(pParameters)

@@ -71,2 +78,3 @@ {

Delete: Delete,
Undelete: Undelete,
Count: Count

@@ -73,0 +81,0 @@ });

@@ -26,8 +26,8 @@ /**

/**
* Generate a table name from the scope
*
* @method: generateTableName
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate a table name from the scope
*
* @method: generateTableName
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateTableName = function(pParameters)

@@ -42,12 +42,12 @@ {

/**
* Generate a field list from the array of dataElements
*
* Each entry in the dataElements is a simple string
*
* @method: generateFieldList
* @param: {Object} pParameters SQL Query Parameters
* @param {Boolean} pIsForCountClause (optional) If true, generate fields for use within a count clause.
* @return: {String} Returns the field list clause, or empty string if explicit fields are requested but cannot be fulfilled
* due to missing schema.
*/
* Generate a field list from the array of dataElements
*
* Each entry in the dataElements is a simple string
*
* @method: generateFieldList
* @param: {Object} pParameters SQL Query Parameters
* @param {Boolean} pIsForCountClause (optional) If true, generate fields for use within a count clause.
* @return: {String} Returns the field list clause, or empty string if explicit fields are requested but cannot be fulfilled
* due to missing schema.
*/
var generateFieldList = function(pParameters, pIsForCountClause)

@@ -111,4 +111,4 @@ {

/**
* Ensure a field name is properly escaped.
*/
* Ensure a field name is properly escaped.
*/
var generateSafeFieldName = function(pFieldName)

@@ -128,5 +128,5 @@ {

/**
* Generate a query from the array of where clauses
*
* Each clause is an object like:
* Generate a query from the array of where clauses
*
* Each clause is an object like:
{

@@ -139,7 +139,7 @@ Column:'Name',

}
*
* @method: generateWhere
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the WHERE clause prefixed with WHERE, or an empty string if unnecessary
*/
*
* @method: generateWhere
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the WHERE clause prefixed with WHERE, or an empty string if unnecessary
*/
var generateWhere = function(pParameters)

@@ -255,11 +255,11 @@ {

/**
* Generate an ORDER BY clause from the sort array
*
* Each entry in the sort is an object like:
* {Column:'Color',Direction:'Descending'}
*
* @method: generateOrderBy
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the field list clause
*/
* Generate an ORDER BY clause from the sort array
*
* Each entry in the sort is an object like:
* {Column:'Color',Direction:'Descending'}
*
* @method: generateOrderBy
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the field list clause
*/
var generateOrderBy = function(pParameters)

@@ -291,8 +291,8 @@ {

/**
* Generate the limit clause
*
* @method: generateLimit
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the limit clause
*
* @method: generateLimit
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateLimit = function(pParameters)

@@ -318,8 +318,8 @@ {

/**
* Generate the join clause
*
* @method: generateJoins
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the join clause
*/
* Generate the join clause
*
* @method: generateJoins
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the join clause
*/
var generateJoins = function(pParameters)

@@ -348,8 +348,8 @@ {

/**
* Generate the update SET clause
*
* @method: generateUpdateSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the update SET clause
*
* @method: generateUpdateSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateUpdateSetters = function(pParameters)

@@ -449,8 +449,8 @@ {

/**
* Generate the update-delete SET clause
*
* @method: generateUpdateDeleteSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the update-delete SET clause
*
* @method: generateUpdateDeleteSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateUpdateDeleteSetters = function(pParameters)

@@ -465,3 +465,3 @@ {

var tmpSchema = Array.isArray(pParameters.query.schema) ? pParameters.query.schema : [];
var tmpCurrentColumn = 0;

@@ -477,5 +477,5 @@ var tmpHasDeletedField = false;

tmpSchemaEntry = tmpSchema[i];
var tmpUpdateSql = null;
switch (tmpSchemaEntry.Type)

@@ -506,3 +506,75 @@ {

}
if (tmpCurrentColumn > 0)
{
tmpUpdate += ',';
}
tmpUpdate += tmpUpdateSql;
// We use a number to make sure parameters are unique.
tmpCurrentColumn++;
}
// We need to tell the query not to generate improperly if there are no values set.
if (!tmpHasDeletedField ||
tmpUpdate === '')
{
return false;
}
return tmpUpdate;
};
/**
* Generate the update-undelete SET clause
*
* @method: generateUpdateUndeleteSetters
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateUpdateUndeleteSetters = function(pParameters)
{
// TODO: Eliminate this disableDeleteTracking stuff that was added
if (pParameters.query.disableDeleteTracking)
{
//Don't generate an UPDATE query if Delete tracking is disabled
return false;
}
// Check if there is a schema. If so, we will use it to decide if these are parameterized or not.
var tmpSchema = Array.isArray(pParameters.query.schema) ? pParameters.query.schema : [];
var tmpCurrentColumn = 0;
var tmpHasDeletedField = false;
var tmpUpdate = '';
// No hash table yet, so, we will just linear search it for now.
// This uses the schema to decide if we want to treat a column differently on insert
var tmpSchemaEntry = {Type:'Default'};
for (var i = 0; i < tmpSchema.length; i++)
{
// There is a schema entry for it. Process it accordingly.
tmpSchemaEntry = tmpSchema[i];
var tmpUpdateSql = null;
switch (tmpSchemaEntry.Type)
{
case 'Deleted':
tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = 0';
tmpHasDeletedField = true; //this field is required in order for query to be built
break;
case 'UpdateDate':
// The undelete operation is an Update, so we should stamp the update time
tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = ' + SQL_NOW;
break;
case 'UpdateIDUser':
var tmpColumnParameter = tmpSchemaEntry.Column+'_'+tmpCurrentColumn;
tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = :'+tmpColumnParameter;
pParameters.query.parameters[tmpColumnParameter] = pParameters.query.IDUser;
break;
default:
//DON'T allow update of other fields in this query
continue;
}
if (tmpCurrentColumn > 0)

@@ -530,8 +602,8 @@ {

/**
* Generate the create SET clause
*
* @method: generateCreateSetList
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the create SET clause
*
* @method: generateCreateSetList
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateCreateSetValues = function(pParameters)

@@ -676,8 +748,8 @@ {

/**
* Generate the create SET clause
*
* @method: generateCreateSetList
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
* Generate the create SET clause
*
* @method: generateCreateSetList
* @param: {Object} pParameters SQL Query Parameters
* @return: {String} Returns the table name clause
*/
var generateCreateSetList = function(pParameters)

@@ -820,2 +892,21 @@ {

var Undelete = function(pParameters)
{
var tmpTableName = generateTableName(pParameters);
var tmpWhere = generateWhere(pParameters);
var tmpUpdateUndeleteSetters = generateUpdateUndeleteSetters(pParameters);
if (tmpUpdateUndeleteSetters)
{
//If the table has a deleted bit, go forward with the update to change things.
return 'UPDATE'+tmpTableName+' SET'+tmpUpdateUndeleteSetters+tmpWhere+';';
}
else
{
// This is a no-op because the record can't be undeleted.
// TODO: Should it throw instead?
return 'SELECT NULL;';
}
};
var Count = function(pParameters)

@@ -857,2 +948,3 @@ {

Delete: Delete,
Undelete: Undelete,
Count: Count

@@ -862,7 +954,7 @@ });

/**
* Dialect Name
*
* @property name
* @type string
*/
* Dialect Name
*
* @property name
* @type string
*/
Object.defineProperty(tmpDialect, 'name',

@@ -869,0 +961,0 @@ {

@@ -797,2 +797,9 @@ /**

var buildUndeleteQuery = function()
{
checkDialect();
_Parameters.query.body = _Dialect.Undelete(_Parameters);
return this;
};
var buildCountQuery = function()

@@ -840,2 +847,3 @@ {

buildDeleteQuery: buildDeleteQuery,
buildUndeleteQuery: buildUndeleteQuery,
buildCountQuery: buildCountQuery,

@@ -842,0 +850,0 @@

@@ -663,2 +663,39 @@ /**

(
'Undelete Query with Deleted Bit',
function()
{
var tmpQuery = libFoxHound.new(libFable).setDialect('ALASQL')
.setScope('Animal')
.addFilter('IDAnimal', 10);
//Use a schema that already defines a deleted bit
tmpQuery.query.schema = _AnimalSchema;
// Build the query
tmpQuery.buildUndeleteQuery();
// This is the query generated by the ALASQL dialect
libFable.log.trace('Undelete Query', tmpQuery.query);
Expect(tmpQuery.query.body)
.to.equal('UPDATE Animal SET `UpdateDate` = NOW(), `UpdatingIDUser` = :UpdatingIDUser_1, `Deleted` = 0 WHERE `IDAnimal` = :IDAnimal_w0 AND `Deleted` = :Deleted_w1;');
}
);
test
(
'Undelete Query without Deleted Bit',
function()
{
var tmpQuery = libFoxHound.new(libFable).setDialect('ALASQL')
.setScope('Animal')
.addFilter('IDAnimal', 10);
// Build the query
tmpQuery.buildUndeleteQuery();
// This is the query generated by the ALASQL dialect
libFable.log.trace('Undelete Query', tmpQuery.query);
Expect(tmpQuery.query.body)
.to.equal('SELECT NULL;');
}
);
test
(
'Update Query -- without Deleted',

@@ -665,0 +702,0 @@ function()

@@ -209,2 +209,16 @@ /**

(
'Undelete Query',
function()
{
var tmpQuery = libFoxHound.new(libFable).setDialect('English').setScope('Animal');
// Build the query
tmpQuery.buildUndeleteQuery();
// This is the query generated by the English dialect
Expect(tmpQuery.query.body)
.to.equal('I am undeleting your Animal.');
}
);
test
(
'Count Query',

@@ -211,0 +225,0 @@ function()

@@ -775,2 +775,39 @@ /**

);
test
(
'Undelete Query with Deleted Bit',
function()
{
var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
.setScope('Animal')
.addFilter('IDAnimal', 10);
//Use a schema that already defines a deleted bit
tmpQuery.query.schema = _AnimalSchema;
// Build the query
tmpQuery.buildUndeleteQuery();
// This is the query generated by the MySQL dialect
libFable.log.trace('Undelete Query', tmpQuery.query);
Expect(tmpQuery.query.body)
.to.equal('UPDATE `Animal` SET UpdateDate = NOW(3), UpdatingIDUser = :UpdatingIDUser_1, Deleted = 0 WHERE IDAnimal = :IDAnimal_w0 AND `Animal`.Deleted = :Deleted_w1;');
}
);
test
(
'Undelete Query without Deleted Bit',
function()
{
var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
.setScope('Animal')
.addFilter('IDAnimal', 10);
// Build the query
tmpQuery.buildUndeleteQuery();
// This is the query generated by the MySQL dialect
libFable.log.trace('Undelete Query', tmpQuery.query);
Expect(tmpQuery.query.body)
.to.equal('SELECT NULL;');
}
);
}

@@ -777,0 +814,0 @@ );

Sorry, the diff of this file is not supported yet

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