neumino / thinky

JavaScript ORM for RethinkDB
http://justonepixel.com/thinky/
Other
1.12k stars 128 forks source link

filter(...).delete()? #638

Closed YannisMarios closed 6 years ago

YannisMarios commented 6 years ago

Hi, I have a question

I have defined a static method like this:

accessTokens.defineStatic('removeExpired', async function() {
  let expired = await this.filter(token => token('expires_on').lt(new Date()));
  if(expired.length) {
    expired.forEach(token => async () => {
      await this.delete(token.id)
    })
  }
});

expired is an array of objects and I would like to delete them without having to loop over them by doing something like:

await this.filter(token => token('expires_on').lt(new Date())).delete()

is this possible? I tried this above and I get error: ThinkyError: Value for [id] must be defined.

in ReQL it is possible to do: r.db("auth_db").table("accessTokens").filter(token => token('expires_on').lt(new Date())).delete()

cur3n4 commented 6 years ago

Does await this.filter(token => token('expires_on').lt(new Date())).delete().execute() do the trick?

YannisMarios commented 6 years ago

@cur3n4 It works!!! Thank you!!

I can't believe I missed this!

cur3n4 commented 6 years ago

@YannisMarios My pleasure