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

@talend/daikon-tql-client

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@talend/daikon-tql-client

The goal of this library is to provide a NPM package that helps to convert javascript-style filters to TQL queries.

  • 0.19.2-SNAPSHOT
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
179
decreased by-48.12%
Maintainers
1
Weekly downloads
 
Created
Source

The goal of this library is to provide a NPM package that helps to convert javascript-style filters to TQL queries.

Operator

An Operator inherits from the Operator class (which implements the ISerializable interface). All operators are simple Javascript classes which has the Value and HasOperand properties exported.

The following operators are supported :

  • complies
  • contains
  • is empty
  • is invalid
  • is valid
  • between
  • quality
  • =
  • >
  • <

Compositor

A Compositor is the only way to join operators in a query.

The following compositors are supported :

  • and
  • or

They can be used as the same way as an operator in a query :

query.equal('f1', 666).or().equal('f2', 777);

Modifier

A Modifier changes the meaning of an operator or a query.

The following modifiers are supported :

  • not

They can be part of a query :

query.equal('f1', 666).or().not(new Equal('f2', 777));

Query

A Query is a serializable set of operators :

const query = new Query();

query
	.greaterThan('f2', 42)
	.and()
	.lessThan('f2', 76)
	.or()
	.equal('f2', 777);

Queries can be nested thanks to the nest() method :

const query = new Query();
const query2 = new Query();

query2
	.equal('q2f1', 76)
	.or()
	.equal('q2f2', 77);

query
	.greaterThan('f2', 42)
	.and()
	.nest(query2) // <- !
	.and()
	.lessThan('f2', 666);

There is no depth limit.

Serialization

Operators can be serialized to TQL expressions :

const operator = new GreaterThan('col1', 42);

operator.serialize(); // -> 'col1 > 42'

And queries too :

const query = new Query();

query
	.greaterThan('f2', 42)
	.and()
	.lessThan('f2', 76)
	.or()
	.equal('f2', 777);

query.serialize(); // -> '(f2 > 42) and (f2 < 76)  or  (f2 = 777)'

Obviously, priority is conserved on nested queries :

const query1 = new Query();
const query2 = new Query();
const query3 = new Query();

query2
	.equal('q2f1', 76)
	.or()
	.equal('q2f2', 77);

query3
	.equal('q3f1', 78)
	.and()
	.equal('q3f2', 79);

query1
	.greaterThan('f2', 42)
	.and()
	.nest(query2)
	.and()
	.lessThan('f2', 666)
	.or()
	.nest(query3)
	.or()
	.equal('f2', 777);

query1.serialize();

Will produce :

(f2 > 42)  and (
	(q2f1 = 76)  or  (q2f2 = 77)
) and (f2 < 666)  or  (
	(q3f1 = 78) and (q3f2 = 79)
)  or  (f2 = 777)

How to create an operator ?

To add your own operator, you just have to create a new class under src/converter/operators/.

For example, to create a new toto operator, create src/converter/operators/toto.js :

import Operator from './operator';

export default class Toto extends Operator {
	static value = 'is toto';
	static hasOperand = false;
}

And export it in src/converter/operators/index.js :

import Toto from './toto';
// ...

export {
	// ...,
	Toto,
};

Don't forget the associated tests ;)

Your new toto operator will be automatically available under Query :

const query = new Query();

query
	.greaterThan('f1', 42)
	.and()
	.toto('f2');

query.serialize(); // -> '(f1 > 42) and (f2 is toto)'

Parser

The Parser class helps to transform a Javascript-style filters tree to a serializable query :

const query = Parser.parse(myTree);
query.serialize();

FAQs

Package last updated on 30 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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