Git Product home page Git Product logo

query.dart's Introduction

query.dart

A Django inspired query library.


Example

 Query get_ids = new Query({ 'id__lt': 5 });
 List<Map> ids = [{'id': 2}, {'id': 6}, {'id': 4}];
 get_ids.filter(ids); // {id: 2}, {id: 4}
 get_ids.map(ids); // [true, false, true]

Filter Options

Filter comparison Example
lt a < b id__lt: 3
gt a > b id__gt: 4
lte a <= b id__lte: 3
gte a >= b id__gte: 5
eq a === b id__eq: 2
not a !== b title__not: "Hello"
startswith a.match(/^b/) title__startswith: "hello"
endswith a.match(/b$/) title__endswith: "goodbye"
istartswith a.toLowerCase().match(/^b/) title__istartswith: "hello"
iendswith a.toLowerCase().match(/b$/) title__iendswith: "goodbye"
contain a.indexOf(b) > -1 title__contain: "hello"
icontain a.toLowerCase().indexOf(b) > -1 title__icontain: /[hello]/g
rgx a.match(b) title__rgx: /[hello]/g
irgx a.toLowerCase().match(b) title__irgx: /[hello]/g
in b.indexOf(a) > -1 id__in: [1,2,3]

Supports Nested Maps and methods

List<Map> sample_data = [
    {
     id: 2,
     time: new Date(),
     user: {
        username: "kameron"
     }
    },
    {
     id: 3,
     time: new Date(),
     user: {
        username: "bradley"
     }
    },
];


Query get_user = new Query({
    "time__getFullYear__eq": 2016, // method
    "user__username__icontain": "ron"// object
});

get_user.filter(sample_data);
// [{id: 2...}]

aggregate.dart


A Django inspired aggregation library.

Example

List<Map> scores = [{user: {score: 25}}, {user: {score: 50}}, {user: {score: 60}}, {user: {score: 70}}];
Aggregate stats = new Aggregate('user__score');
stats.avg("user__score", scores); // averAggregatee: 51.25
stats.max("user__score", scores); // max: 70
stats.min("user__score", scores); // min: 25
stats.sum("user__score", scores); // summation: 205
stats.count("user__score", scores); // all objs with field: 4

query.dart's People

Contributors

kamerontanseli avatar

Watchers

James Cloos 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.