SenseNet / sn-client-js

A JavaScript client for sensenet ECM that makes it easy to use the REST API of the Content Repository.
https://www.sensenet.com/
GNU General Public License v2.0
11 stars 2 forks source link

Client side Query API #38

Closed borsi closed 7 years ago

borsi commented 7 years ago

On client side, we have the fields and the means of querying. So instead of building query strings, we should have an Query API.

ToDo:

gallayl commented 7 years ago

Syntax example:

const query = new Query(q =>
    q.TypeIs<ContentTypes.Task>(ContentTypes.Task)   // adds '+TypeIs:Document' and Typescript type cast
    .And
    .Equals('DisplayName', 'Unicorn')   // adds +Title:Unicorn (TBD: fuzzy/Proximity)
    .And
    .Between('ModificationDate', '2017-01-01T00:00:00', '2017-02-01T00:00:00')
    .Or
    .Query(sub => sub //Grouping
        .NotEquals('Approvable', true)
        .And
        .NotEquals('Description', '*alma*') //Contains with wildcards
    )
    .Sort('DisplayName')
    .Top(5)         // adds .TOP:5
    .Skip(10)       // adds .SKIP:10
);

// fires the request
query.Exec(repository, path, {
    select: ['Id', 'Path', 'Name', 'DisplayName'],
    expand: 'Owner'
})
.subscribe(docs => {
    console.log('Query result:', docs)
})

The query.toString() should return with the content query string:

TypeIs:Task AND DisplayName:'Unicorn' AND ModificationDate:{'2017-01-01T00\:00\:00' TO '2017-02-01T00\:00\:00'} OR (NOT(Approvable:'true') AND NOT(Description:'*alma*')) .SORT:'DisplayName' .TOP:5 .SKIP:10

Tasks