Socket
Socket
Sign inDemoInstall

fastquery-builder

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

66

handleQueries.js

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

export function transformFilter(col, value) {
if (Array.isArray(value)) return `${col} IN (${value})`;
return `${col} = ${value}`;
}
/**
* @params {[{ col, value: Array | String |Number}]} list
*/
export function where(list) {
return list.reduce((acc, filter, index) => {
if (index === 0) return `WHERE ${filter}`;
return `${acc} AND ${filter}`;
}, "");
}
export function having(list) {
return list.reduce((acc, filter, index) => {
if (index === 0) return `HAVING ${filter}`;
return `${acc} AND ${filter}`;
}, "");
}
export function join(list) {
return list.reduce((acc, filter) => `${acc} AND ${filter}`, "");
}
function conditionalInArrayExists(col, value, not) {

@@ -39,3 +65,3 @@ if (Array.isArray(value) && value.length > 0) {

if (value || value === 0) {
const fvalue = typeof value === 'string' ? `'${value}'` : value;
const fvalue = typeof value === "string" ? `'${value}'` : value;
if (not) return `${col} != ${fvalue}`;

@@ -49,3 +75,3 @@ return `${col} = ${fvalue}`;

if (value || value === 0) {
const fvalue = typeof value === 'string' ? `'${value}'` : value;
const fvalue = typeof value === "string" ? `'${value}'` : value;
return `${col} ${operator} ${fvalue}`;

@@ -65,8 +91,11 @@ }

function conditionalWhereBetween(col, value, not) {
if (Array.isArray(value) && value.length === 2) {
const [init, end] = value;
function conditionalWhereBetween(col, values, not, isSorted) {
if (Array.isArray(values) && values.length === 2) {
const [init, end] = isSorted
? values.sort((a, b) => parseInt(a, 10) - parseInt(b, 10))
: values;
if (not) return `${col} NOT BETWEEN ${init} AND ${end}`;
return `${col} BETWEEN ${init} AND ${end}`;
}
return null;

@@ -76,4 +105,4 @@ }

function conditionalWhereLike(col, value) {
if (value && typeof value === 'string') {
const fvalue = value.replace(/\s/g, '%');
if (value && typeof value === "string") {
const fvalue = value.replace(/\s/g, "%");
return `${col} LIKE '%${fvalue}%'`;

@@ -85,3 +114,4 @@ }

function conditionalWhereCaseInsensitive(col, value) {
if (value && typeof value === 'string') return `positionCaseInsensitive(${col}, '${value}') > 0`;
if (value && typeof value === "string")
return `positionCaseInsensitive(${col}, '${value}') > 0`;

@@ -92,24 +122,6 @@ return null;

function conditionalWhereIsNot(col, value) {
const fvalue = typeof value === 'string' ? `'${value}'` : value;
const fvalue = typeof value === "string" ? `'${value}'` : value;
return `${col} IS NOT ${fvalue}`;
}
export function transformFilter(col, value) {
if (Array.isArray(value)) return `${col} IN (${value})`;
return `${col} = ${value}`;
}
export function joinWhere(list) {
const listFiltered = list.filter(Boolean)
return listFiltered.reduce((where, filter, index) => {
if (index === 0) return `WHERE ${filter}`;
return `${where} AND ${filter}`;
}, '');
}
export function join(list) {
const listFiltered = list.filter(Boolean)
return listFiltered.reduce((where, filter) => `${where} AND ${filter}`, '');
}
export const conditionalWhere = {

@@ -116,0 +128,0 @@ equal: conditionalWhereEqual,

{
"name": "fastquery-builder",
"version": "1.0.2",
"version": "1.0.3",
"description": "Make your query fast and build it easly",

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

@@ -9,2 +9,3 @@ # Fastquery Builder

### Help is always welcome, feel free to clone and make pull requests to improve our library
### Help is always welcome, feel free to clone and make pull requests to improve our library
Githup Repo: https://github.com/3fydev/fastquery-builder
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc