lolopinto / ent

MIT License
51 stars 6 forks source link

EdgeQuery querying enhancements #685

Open lolopinto opened 2 years ago

lolopinto commented 2 years ago

map(), filter() etc added to queries

e.g. https://github.com/lolopinto/ent/blob/fix-476-part2/examples/simple/src/ent/user.ts#L50-L53 from https://github.com/lolopinto/ent/pull/683 should be doable in the same query

e.g.

// async function
const contactInfos = await  this.queryContacts().queryEnts().asyncMap((contact)=> queryPlusEmails()));

vs

// non async function
const contactInfos = await  this.queryContacts().queryEnts().map((contact)=> doFoo()));

queryEnts() right now just performs the query so may need this to be a breaking change or come up with a new method that just returns something chainable

Swahvay commented 2 years ago

A case I have that would be great to be covered:

Ents:

I want to have an EntQuery on the Horse ent that will get all progeny (all horses that have set their breeding info's damID to this horse if this horse is a mare, or sireID otherwise). So something like:

async queryProgeny() {
  return this.queryHorseInfos().queryEnts()
    .map((info) => info.gender === HorseGender.Mare ? this.queryDamOf() : this.querySireOf())
    .asyncMap((breedingInfo) => breedingInfo.loadHorseX());
}

I want this somehow to return a queryEnt so I can do horse.queryProgeny().first(10).queryEnts()