kashav/fsql

How to show human readable file sizes?

applee opened this issue · 3 comments

It would be better to support some function to convert the size unit, e.g. kb/mb/gb. So the sql would be as below
fsql "select name, mb(size) from . where ...."

Great idea!

I'm thinking about introducing something called an attribute modifier, essentially used to modify attributes (this'll also be used for #3). I'll create an in-depth issue about this in the coming days.

I want the syntax to focus more on the actual attribute, so it doesn't feel like you're using a function. My preliminary thought is to do something like this --

SELECT name::upper, size::mb FROM . WHERE time::iso ...

This will also allow attributes to have more than one modifier. Of course attributes can be selected without any modifier as well. The only downside that I see in doing it like this is that we're kind of moving away from SQL syntax (I'm not really sure if this is a problem).

Would love to hear your thoughts on this!

It sounds so cool, as you said attribute modifier breaks SQL syntax, but functions not. I'm using another tool named osquery, it looks like fully matched SQL syntax.

@applee This is now implemented!

You can get a human-readable file size as follows:

$ fsql "SELECT name, FORMAT(size, MB) FROM . WHERE ..."