ent icon indicating copy to clipboard operation
ent copied to clipboard

EdgeQuery querying enhancements

Open lolopinto opened this issue 3 years ago • 1 comments

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

lolopinto avatar Dec 27 '21 23:12 lolopinto

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

Ents:

  • Horse
  • HorseInfo (holds gender enum - foreignKey reference on horseID)
  • HorseBreedingInfo (holds damID and sireID - foreignKey reference on horseID)

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()

Swahvay avatar Feb 26 '22 15:02 Swahvay