ujjwalguptaofficial / JsStore

A complete IndexedDB wrapper with SQL like syntax.
http://jsstore.net/
MIT License
849 stars 109 forks source link

The union query is used with an or query and is used with multiple conditions. The query data is incorrect #343

Closed xuyongweb closed 1 year ago

xuyongweb commented 1 year ago

Title

// Add your title here The union query is used with an or query and is used with multiple conditions. The query data is incorrect

Description

select({
    from: "Orders",
    order: {
        by: 'Orders.customerId',
        type: 'asc' //supprted sort type is - asc,desc
    },
    join: {
        with: "Customers",
        type: "left",
        on: "Orders.customerId=Customers.customerId",
        as: {
            customerId: 'cId'
        }
    },
    where: [
        {shipperId: 2,},
        [{employeeId: 4, customerId: 34,}, { or: { employeeId: 4,customerId: 76}}],
        { orderId: {'<': 1000000}}
    ]
})

// Add your description here The data less than 10000 cannot be queried. If the condition is less than 10000, the query is normal.

xuyongweb commented 1 year ago

https://ujjwalguptaofficial.github.io/idbstudio/?db=Demo&query=select(%7B%0A%20%20%20%20from%3A%20%22Orders%22%2C%0A%20%20%20%20order%3A%20%7B%0A%20%20%20%20%20%20%20%20by%3A%20'Orders.customerId'%2C%0A%20%20%20%20%20%20%20%20type%3A%20'asc'%20%2F%2Fsupprted%20sort%20type%20is%20-%20asc%2Cdesc%0A%20%20%20%20%7D%2C%0A%20%20%20%20join%3A%20%7B%0A%20%20%20%20%20%20%20%20with%3A%20%22Customers%22%2C%0A%20%20%20%20%20%20%20%20type%3A%20%22left%22%2C%0A%20%20%20%20%20%20%20%20on%3A%20%22Orders.customerId%3DCustomers.customerId%22%2C%0A%20%20%20%20%20%20%20%20as%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20customerId%3A%20'cId'%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%2C%0A%20%20%20%20where%3A%20%5B%0A%20%20%20%20%20%20%20%20%7BshipperId%3A%202%2C%7D%2C%0A%20%20%20%20%20%20%20%20%5B%7BemployeeId%3A%204%2C%20customerId%3A%2034%2C%7D%2C%20%7B%20or%3A%20%7B%20employeeId%3A%204%2CcustomerId%3A%2076%7D%7D%5D%2C%0A%20%20%20%20%20%20%20%20%7B%20orderId%3A%20%7B'%3C'%3A%201000000%7D%7D%0A%20%20%20%20%5D%0A%7D)

image

xuyongweb commented 1 year ago
select Orders.* , Customers.customerId as cId from Orders left join Customers on Orders.customerId=Customers.customerId where Orders.shipperId = 2 and((Orders.employeeId=4 and Orders.customerId=34) or (Orders.employeeId=4 and Orders.customerId=76)) and orderId < 1000000 order by Orders.customerId asc

image

xuyongweb commented 1 year ago
select({
    from: "Orders",
    order: {
        by: 'Orders.customerId',
        type: 'asc' //supprted sort type is - asc,desc
    },
    join: {
        with: "Customers",
        type: "left",
        on: "Orders.customerId=Customers.customerId",
        as: {
            customerId: 'cId'
        }
    },
    where: [
        {shipperId: 2,},
        [{employeeId: 4, customerId: 34}, { or: { employeeId: 4,customerId: 76}}, { orderId: {'<': 100000}}],

    ]
})

This way of writing can be found, but is this writing correct?

xuyongweb commented 1 year ago
select({
    from: "Orders",
    order: {
        by: 'Orders.customerId',
        type: 'asc' //supprted sort type is - asc,desc
    },
    join: {
        with: "Customers",
        type: "left",
        on: "Orders.customerId=Customers.customerId",
        as: {
            customerId: 'cId'
        }
    },
    where: [
        {shipperId: 2,},
        { orderId: {'<': 100000}},
        [{employeeId: 4, customerId: 34}, { or: { employeeId: 4,customerId: 76}}],

    ]
})

You can find them in a different order

ujjwalguptaofficial commented 1 year ago

OK, i will have a look.

ujjwalguptaofficial commented 1 year ago

If you will just change the order of query - it works

select({
    from: "Orders",
    order: {
        by: 'Orders.customerId',
        type: 'asc' //supprted sort type is - asc,desc
    },
    join: {
        with: "Customers",
        type: "left",
        on: "Orders.customerId=Customers.customerId",
        as: {
            customerId: 'cId'
        }
    },
    where: [{
            orderId: {
                '<': 1000000
            }
        }, {
            shipperId: 2,
        },
        [{
            employeeId: 4,
            customerId: 34,
        }, {
            or: {
                employeeId: 4,
                customerId: 76
            }
        }],

    ]
})

The above query works but when we will move the < query at end, it does not work. I will fix this.

ujjwalguptaofficial commented 1 year ago

fixed in v - 4.6.2, please update and try.

The issue was in promise chain, In longer query while the results was about to evaluate, the engine was returning result to caller.

ujjwalguptaofficial commented 1 year ago

idbstudio also updated

ujjwalguptaofficial commented 1 year ago

I hope this issue is fixed. Feel free to reopen if not.