Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More comprehensive query options #47

Open
cinnamon-bun opened this issue Aug 15, 2020 · 0 comments
Open

More comprehensive query options #47

cinnamon-bun opened this issue Aug 15, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@cinnamon-bun
Copy link
Member

cinnamon-bun commented Aug 15, 2020

What's the problem you want solved?

The query object specification only has limited ways to match against document fields.

For example, we have lowPath which does <= and highPath which does >. What if we want to do < or >=?

We need to add timestamp range queries too. Do we need a combinatorial explosion of query parameters?

Generalized query options for matching document fields

A more systematic way to do this is to combine a field and an operation:

let query = {
    timestamp_lte: 15000000000,  // timestamp less than or equal to
    path_prefix: "/wiki/",  // path has prefix
    author_in: ["@suzy.bxxxx", "@matt.bxxxxx"],  // author in list
    content_neq: "",   // content !== ""
}

Operations:

< lt
<= lte
> gt
>= gte
== === eq     // this is the default if no operation is specified
!= !== <> neq
prefix or startsWith
suffix or endsWith
in

Symbols or letters? Spaces or underscores?

{
    // which style is better?
    timestamp_lte: 15000000,
    "timestamp <=", 15000000,
}

This would make for quite a large Query type. Luckily the code doing the query could handle this in a generalized way by splitting the properties at _ instead of hardcoding each combination.

type Query = {
    path?: string,
    path_lt?: string,
    path_lte?: string,
    path_gt?: string,
    path_gte?: string,
    path_eq?: string,
    path_neq?: string,
    // etc
}

let doQuery = (query: Query) => {
    for (let [property, value] of Object.entries(query)) {
        let [fieldToQuery, operation] = property.split('_');
        // etc
    }
}

Other query options stay the same

Some query options are not about matching specific fields. These would continue to work in the old way, without an operation in the property name:

limit
includeHistory  (pending issue #44 )
now

Queryable metadata

If we implement #9 we would also need to query the metadata keys and values. Maybe like this?

The metadata we want to search for:

let doc = {
    path: "/posts/blah/blah",
    author: "@suzy.bxxxxxxx",
    ...etc...,
    metadata: {
        category: "gardening",
        createdTimestamp: 1500000077,
    }
}

The query:

let query = {
    metadata_category: "gardening",
    metadata_createdTimestamp_gt: 1500000000,
}
@cinnamon-bun cinnamon-bun added the enhancement New feature or request label Aug 15, 2020
@cinnamon-bun cinnamon-bun added this to the bananaslug milestone Aug 15, 2020
@sgwilym sgwilym removed this from the Bananaslug milestone May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants