Giter Club home page Giter Club logo

node-where-filter's Introduction

通过字符串生成查询条件语句

安装

npm install node-where-filter

示例

const wherefilter = require( 'node-where-filter' );

var exprTree = wherefilter.makeTree( '(name~Jack || name="Mike A") && age>10 && alias<10', { alias: 'other name' } );
console.log( exprTree );
// echo: [ '&&', [ '&&', [ '||', [Array], [Array] ], [ '>', 'age', 10 ] ], [ '<', 'other name', 10 ] ]

var dataTable = [
	{ name: 'Jack A', age: 20, 'other name': 6 },
	{ name: 'Jack B', age: 29, 'other name': 11 },
	{ name: 'Mike A', age: 20, 'other name': 6 },
	{ name: 'Jack',   age: 9 , 'other name': 6 },
];
console.log( dataTable.filter( wherefilter.where( exprTree ) ) );
// echo: [ { name: 'Jack A', age: 20, 'other name': 6 },
//         { name: 'Mike A', age: 20, 'other name': 6 } ]

console.log( wherefilter.whereSQL( exprTree ) );
// echo: ( ( ( `name` LIKE "%Jack%" ) OR ( `name` = "Mike A" ) ) AND ( `age` > 10 ) ) AND ( `other name` < 10 )

特别说明

字符串: "aaa\"bbb"

支持的操作符:
比较操作符: ~(regexp) !~(regexp) = != < > <= >=
规则: key operator value

逻辑操作符: && ||
规则: expr operator expr

node-where-filter's People

Contributors

list-git avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.