Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Human Readable Database Results #300

Closed
maedi opened this issue Sep 20, 2012 · 5 comments
Closed

Human Readable Database Results #300

maedi opened this issue Sep 20, 2012 · 5 comments

Comments

@maedi
Copy link

maedi commented Sep 20, 2012

When querying Mongo from the Controller we get back quite a big soup of variables, which e_dub mentioned in IRC are for Ember integration.

posts = App.Post.all()

As a new user I found this confusing, expecting to get the results themselves. I'm sure they're in there but I can't see them in the console as there are too many lines for the terminal window to keep track of.

e_dub suggested using this to get the first object:

posts.objectAt(0)

But for example, how would I loop through each result? Seeing a simple array of results would allow users to visualize the data set much easier. Do we need a "dataFilter()" function?

@lancejpollard
Copy link
Member

Not quite sure what you're asking, are you wondering about the terminal and how to see/inspect data there?

To do that there is a helper function _.stringify(App.Post.all(), which just calls JSON.stringify(records, null, 2), but that can be overwhelming.

What do you suggest? Should there be a more robust database-like (mysql-like perhaps) set of helpers for visualizing the data something like this:

MySQL Data
MySQL Record Data

Two things actually. First, there should probably be a tower database --mongodb or tower <database> command to directly startup the database. Some people seem to use this (though I never have). Second, we should provide a standard set of "data formatting" helpers in the console (and browser) for visualizing the data:

  • in table format (first image above)
  • show individual record (second image above)
  • in json
  • etc.

Twitter Command Line

@maedi
Copy link
Author

maedi commented Sep 22, 2012

_.stringify is the sort of thing I'm after, thanks. In a perfect world App.Post.all() would return this too. Even though it's overbearing, it's actually doing what the .all() implies, rather than an Ember object.

Regarding MySQL, I've found MongoHub (Mac) can help to visualize the data if you click the 'Query' icon.

With the database console idea, this sounds really useful. I'm currently using something like this to reset my DB, but not to inspect:

mongo
show dbs
use [databasename]
db.dropDatabase();

@maedi maedi closed this as completed Sep 22, 2012
@edubkendo
Copy link
Contributor

To loop through the results what I usually do is something like:

App.User.all (err, users) =>

  App.User.count (err, count) =>

    for num in [0...count]
      user = users.objectAt(num)
      console.log user.toJSON()  #this will show you just the user object and it's properties.
      # do something to user

It's slightly awkward, but a small price to pay for the conveniences Ember brings.

@lancejpollard
Copy link
Member

Started messing around with a cli to the database:

For now you can just quickly query data:

tower select posts --select id,createdAt --where 'createdAt: $gte: _(1).days().ago()' --order createdAt- --limit 10 --page 2

Tower select command

Eventually it could even be such that:

  • the printed table is an editable spreadsheet in the terminal, so you can actually modify the raw data directly. The hardest thing was figuring out how to get the position of the terminal's cursor and map it a line of text - then to a model. But ansi.js figured it out! Here is another hack I tried that works, but ansi.js is way better :) https://gist.github.com/3765464
  • you can quickly paginate the database (and queries) using keyboard shortcuts in the terminal.
  • when you edit data in there, it could autocomplete from the rest of the db data.
  • similar visualizations/functionality should be possible from within the tower console js/coffee environment somehow.

It's not that bad once it gets figured out how to scroll the terminal cursor up and down and map that to data. Theoretically you can even build a DOM in the terminal using cheerio. It looks like that's what he started here!

All we'd have to do is customize the cheerio.render method to generate ASCII / ANSI strings instead of HTML... Could easily be done in a day!

Here are some other links for learning about ANSI escape sequences (which give you crazy terminal powers):

Cheers.

@maedi
Copy link
Author

maedi commented Sep 22, 2012

Cool! This could be quite powerful...

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

No branches or pull requests

3 participants