Giter VIP home page Giter VIP logo

Comments (5)

PhilWaldmann avatar PhilWaldmann commented on June 12, 2024 1

You're right. My mistake!
Fixed in 2.9.2

from openrecord.

PhilWaldmann avatar PhilWaldmann commented on June 12, 2024

This is normal SQL behavior. OFFSET and LIMIT will be applied to the result set.
So a SELECT COUNT(*) FROM your_table will return one row. With an offset of 1 you will skip the result and get nothing... This is the behaviour of postgres an sqlite. MySql will ignore the offset and return the count.

regarding updateAll: Yes, that's not implemented. It's not very precise to updated your records this way. It's better to use a where clause to limit the number of affected rows.
e.g.

await Model.where({id_between: [1, 5]}).updateAll({ updatedAt: new Date() })

from openrecord.

arthurfranca avatar arthurfranca commented on June 12, 2024

Yes the count part was more of a wish the framework could bend the query and make it work as length but you are right.

About updateAll, in my app i was already filtering with where but wanted to do something like: where userId = ... and ..., after ordering by updatedAt desc, offset 5 and update the rest removing a premium flag feature as the user will only be able to keep 5 records with the flag after losing the premium status.

I could fetch the records first and then update them but tried to use updateAll to update them with only one trip do database.

from openrecord.

PhilWaldmann avatar PhilWaldmann commented on June 12, 2024

ahhh, okay!

UPDATE your_table SET foo = 'bar' LIMIT 2

is also no valid SQL. But we could imitate it via

UPDATE your_table SET foo = 'bar' WHERE id IN (SELECT id FROM your_table ORDER BY id LIMIT 2)

I've added the possibility to do this kind of subqueries in UPDATE and DELETE queries.
Checkout the latest version!

from openrecord.

arthurfranca avatar arthurfranca commented on June 12, 2024

Thx that is great! I was about to do it using a mix of .toSql and .raw but now it's way easier.

But i'm getting error at this line if i use .delete or .deleteAll without any filter (where or limit etc), like await Model.deleteAll() to help clear DB on tests

Similarly, also here if using await Model.updateAll({ ... })

TypeError: this.getInternal is not a function

from openrecord.

Related Issues (20)

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.