Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

table.find should allow selecting specific columns #59

Open
will123195 opened this issue Jan 19, 2017 · 4 comments
Open

table.find should allow selecting specific columns #59

will123195 opened this issue Jan 19, 2017 · 4 comments

Comments

@will123195
Copy link
Owner

will123195 commented Jan 19, 2017

Like mongo projections

db.authors.find({
  columns: ['name', 'city'], // or maybe { name: 1, city: true }
  where: { name: 'Will' }
})
@rneilson
Copy link

It seems like .hydrate() would be the place to implement this, since .find() uses it under the hood (if I'm reading things right)?

@will123195
Copy link
Owner Author

will123195 commented Mar 12, 2017

.find() and .hydrate() both use .get() under the hood. So we could add a columns option like this:

movies.get(123, { 
  columns: { title: 'myTitle' }
})
.then(movie => {
  // { id: 123, myTitle: 'Office Space' }
})

I guess hydrate could be supported like this:

movies.get(123, { 
  hydrate: { director: { columns: { name: true } } }
})
.then(movie => {
  // { id: 123, title: 'Office Space', year: 1999, director: { id: 1, name: 'Mike Judge' } }
})

I'm thinking the primary key should be automatically included. Otherwise movie.director.save() will not work.

@rneilson
Copy link

I think I know how I'd put this in, but there are the questions of instantiation and caching:

  • If a subset of fields are retrieved, will that interfere with instantiating the Row object? (Or just return a plain object instead?)
  • Should updating the cache be skipped? (I'm presuming so, since I don't think it'd make sense. Unless there's room for some kind of qualifier in the cache to specify the field subset.)

@will123195
Copy link
Owner Author

  • I think partial Row instantiation and partialRow.save() should work fine.
  • I agree let's not cache partial rows

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants