Code Monkey home page Code Monkey logo

spider-query-builder's Introduction

           _     _                                       _           _ _     _
          (_)   | |                                     | |         (_| |   | |
 ___ _ __  _  __| | ___ _ __  __ _ _   _  ___ _ __ _   _| |__  _   _ _| | __| | ___ _ __
/ __| '_ \| |/ _` |/ _ | '__ / _` | | | |/ _ | '__| | | | '_ \| | | | | |/ _` |/ _ | '__|
\__ | |_) | | (_| |  __| |  | (_| | |_| |  __| |  | |_| | |_) | |_| | | | (_| |  __| |
|___| .__/|_|\__,_|\___|_|   \__, |\__,_|\___|_|   \__, |_.__/ \__,_|_|_|\__,_|\___|_|
    | |                         | |                 __/
    |_|                         |_|                |___/

GitHub Release GitHub License test publish

Installation

$ npm i @sonicfury/spider-query-builder

What it does

This typescript library is designed to help you interact between your front end app and your backend based on API Platform. It can help you build your query from a filters form with typing etc.

License

This project is under AGPL 3 License

See license

How to

See docs

Example

Say you have a DomainService (domain.service.ts file) with the something like:

class DomainService extends AbstractService{
    
    getDomain(query: string): Observable<HttpResponse<Domain[]>> {
        const url = `${this.baseUrl}/domain?${query}`;

        return this.http.get<Domain[]>(url);
    }
}

API Platform has specific semantics for the built-in filters.

With this library, you have to build SpiderParams for each filter, like:

import {SpdrQueryBuilder} from "./SpdrQueryBuilder";

const qb = new SpdrQueryBuilder(); // initialize the builder

qb
    .exists('username', true) // wether the property 'username' exists
    .search('firstname', ['john']) // search for a 'john' firstname
    .search('lastname', ['doe']) // search for a 'doe' lastname
    .range('rank', 1, 200); // search for a result with rank between 1 and 200


this.domainService.getDomain(qb.query)
    .subscribe(
        // ...
    )

qb.query will be formatted as exists[username]=true&firstname=john&lastname=doe&rank[between]=1..200;

Issues

Feel free to submit an issue if you find something wrong or if you feel some important feature is missing. Be sure to note the version you're using, and provide minimum context and information (as if you were on SO).

Contributing

You're welcome to contribute if you want. Just be sure to check the guidelines

spider-query-builder's People

Contributors

sonicfury avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

spider-query-builder's Issues

handle multiple SpdrParam instances in query builder

Version

2.x

Issue

There's no handling of multiple declarations of a param on the same property

Suggestion

const p1 = new SpdrSearch('lastname', ['Belmondo']);
const p2 = new SpdrSearch('lastname', ['Delon']);

const qb = new SpdrQueryBuilder([p1,p2]);

Several solutions to this:

  • This could throw an exception
  • Or glue SpdrParam instances into a single SpdrParam with multiple values when possible. Here it could transform p1 and p2 into const p3 = new SpdrSearch('lastname', ['Belmondo', 'Delon']) , for example.
  • Keep only the last instance, that may be the best solution as it would be super handy to use.
  • All solutions, depending on an optional parameter, with the exception by default.

Split sort params, pagination params and others in queryBuilder

Version

3.0.0 and prior

Issue

This would be interesting to split these 3 types of params, as oftentimes you want to update pageIndex, but not the filters, nor the sorting.

Suggestion

const qb = new SpdrQueryBuilder()

qb.params.{whatever filter}()
qb.sort.{whatever sort}()
qb.pagination.{whatever pagination}()

With clearing methods like

qb.sort.clear()

qb.params.search('username', ['johnny'])
qb.params.remove('username')

This way we would be able to update the pagination without the rest and vice versa

commonjs dependencies to be replaced by ES6

{ {...} depends on '@sonicfury/spider-query-builder'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies" }

Probably some configuration issue in tsconfig.json to fix

Add page & itemsPerPage params

# ./config/packages/api_platform.yaml
collection:
        pagination:
            page_parameter_name: _page
            items_per_page_parameter_name: itemsPerPage

Add SpiderParams for pagination, with custom param name for both

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.