EvanBurchard / barnacle

Easier query interface for sails console
6 stars 1 forks source link

[FEATURE_REQUEST] Merge into Sails core? #1

Open mikermcneil opened 10 years ago

mikermcneil commented 10 years ago

This is great, man! How do you feel about bringing this into core?

EvanBurchard commented 10 years ago

I like the idea, and I'd be honored.

What do you have in mind? Do you like the _ conventions for the interface? Do you like it as a console only/non-production tool, without the benefit of something like fibers, or do you actually want usable, synchronous code for production?

If you just want it as is for the easy console interface, the only bit of cleanup I'd want to do first is around the discovery for database functions. With the associations branch moving into core, some of the database functions have changed, so this won't work out of the box.

mikermcneil commented 10 years ago

console only/non-production tool

That's what I was thinking-- this is something I always wished we could add, but I never got around to it. Saw this and thought "hot damn! there it is".

Here are the usages I reckon most people would take advantage of the most (at least from my experience):

It would be nice to have .add(), .remove(), and .save() support, but realistically, those will be accessible through update() in a future 0.10.x release, so I think as long as the crud methods + populate are covered, it'd be a dream come true.

Obviously, populate does bring up some questions around chaining syntax... One option would be to add an alternative to .exec() - e.g. ._() that would trigger exec and bind a console.log() to the callback. Or perhaps a hack for the console that, when applied, runs any un-execed (or "fulfilled" if you're using promises) query after one cycle of the event loop. Really, whatever makes sense for you sounds good to me- those are just some rough ideas off the cuff.

EvanBurchard commented 10 years ago

It has support for the basics right now (plus dynamic methods) except for populate. What code or docs can I look at to get up to speed on populate? The chained options like .skip, .limit, etc. don't work though.

I like the idea of having chaining possibilities. node-fibers might be good to pull off the synchronous .exec alias. I tried to work this out, but it was a good bit harder than just aliasing the methods. Right now, fibers and the console api are both pretty foreign, to me, but I can give it a shot at some point.

I'm not sure how practical it is, but I think my ideal api is:

whateverArbitraryAsyncCall().orChain().gimme()

or .now() or something like that.

And if beforehand, it requires some kind of registering of what is "nowable" or something, so be it.