npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@talend/daikon-tql-client

v1.3.1

Published

Daikon TQL client

Downloads

961

Readme

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.

Installation

# yarn
yarn add @talend/daikon-tql-client

or

# npm
npm install @talend/daikon-tql-client --save

Usage

The package exposes a Query class used to create an instance on which you can chain operators and compositors in the wanted order before serialize it.

Basic example :

import { Query } from '@talend/daikon-tql-client';

const query = new Query();

query
	.equal('f1', 76)
	.or()
	.greaterThan('f2', 77);

query.serialize(); // -> '(f1 = 76) or (f2 > 77)'

Query

A Query is a serializable set of operators.
It lets you stack operators and compositors one after an other by constantly returning the query reference.

import { Query } from '@talend/daikon-tql-client';

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)'

Hint: All the operators are accessible via the query instance in lower camel case.


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

import { Query } from '@talend/daikon-tql-client';

const query = new Query();
const subQuery1 = new Query();
const subQuery2 = new Query();

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

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

query
	.greaterThan('f2', 42)
	.and()
	.nest(subQuery1) // <- !
	.and()
	.lessThan('f2', 666)
	.or()
	.nest(subQuery2) // <- !
	.or()
	.equal('f2', 777);

query.serialize();

Will produce :

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

Hint: Obviously, priority is conserved on nested queries


Queries can hold the negation of other queries or operators with the help of the not() method :

// query negation
import { Query } from '@talend/daikon-tql-client';

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

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

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

query.serialize(); // -> '(f2 > 42) and not((q2f1 = 76) or (q2f2 = 77)) and (f2 < 666)'
// operator negation
import { Query, Operators } from '@talend/daikon-tql-client';

const query = new Query();

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

query.serialize(); // -> '(f1 = 666) or not((f2 = 777))'

Operator

The following operators are supported :

TQL symbol |Client class -------------------------|------------------ contains |Contains containsIgnoreCase |ContainsIgnoreCase complies |Complies wordComplies |WordComplies is empty |Empty is invalid |Invalid is valid |Valid between |Between quality |Quality = |Equal != |Unequal > |GreaterThan >= |GreaterThanOrEqual < |LessThan <= |LessThanOrEqual in |In

They are accessible via the Operators named export and can be serialized to TQL expressions :

import { Operators } from '@talend/daikon-tql-client';

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

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

Compositor

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

The following compositors are supported :

  • and
  • or

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

import { Query } from '@talend/daikon-tql-client';

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

query.serialize(); // -> '(f1 = 666) or (f2 = 777)'

Parser

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

import { Parser } from '@talend/daikon-tql-client';

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

An example of tree can be found in the tests.

How to create an operator ?

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

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 :

import { Query } from '@talend/daikon-tql-client';

const query = new Query();

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

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