-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add cb psql
query menu.
#153
Conversation
f073198
to
c47fa27
Compare
6223176
to
28cbab2
Compare
WHEN :'choice'::text = '<%= option %>' THEN | ||
'\i `echo <%= query.path %>`' | ||
'\echo' | ||
'\i <%= @path %>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, we want to loop after a successful query.
I find it that is burying the useful information.
Ideally, I would prefer to have :menu
display the options only once and if we do loop add the entry ?
,h
or help
to list possible entry.
Also, I would love if after entry I would be able to \e
to see the actual query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so I was on the fence about this one. Initially I had implemented it to only display the options once. I'll get some feedback and update accordingly.
# Metadata annoation for a query. | ||
# | ||
# A `Query` must have a `label` and `category` field defined using this | ||
# annotation. | ||
annotation Metadata; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm completely new to annotation. So, this is more a request to learn than a comment.
Could the Metadata be removed in favor of a standard Query
class stating that each instance should have a label
, category
and raw_sql_path
?
Query.all
would hold the list, and would then be something like :
[
Query.new(label: "Table sizes", category: CATEGORY_SIZE_INFORMATION), raw_sql_path("#{__DIR__}/sql/size_information_table_size.sql"),
…
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this was more of an experimental approach than anything else. This pattern was used in the scope
feature (which I believe might have been for the same purpose). Though, part of my purpose was to learn how we might be able to use annotations for looking up things dynamically without having to instantiate the class.
For instance, I could see where we might want to list the queries available and don't want to load them all into memory. Or maybe only load specific ones. Something like @type.annotation(Metadata)[:category] == CATEGORY_CACHE
.
Does the use case exist yet? Not really, but I was curious about it and that's part of what took me down this path. 🤷♂️
This is an initial phase of supporting a builtin menu of useful queries when using `cb psql`. Currently, it only supports predefined queries. To access this menu, simply enter `:menu` into psql and it will present the available query options. Example: ``` Example Team/example-cluster/postgres=> :menu Cache 1 – Cache and index hit rates Size Information 2 – Database sizes 3 – Table sizes Query Performance 4 – Queries consuming the most system time 5 – Queries running over 1 minute 6 – Slowest average queries Connection Management 7 – Connection count by state 8 – Connection count by user and application Indexes 9 – Duplicate indexes 10 – List of indexes 11 – Unused indexes Locks 12 – Blocking queries Extensions 13 – Available extensions 14 – Installed extensions Type choice and press <Enter> (q to quit): ```
28cbab2
to
3ddfe79
Compare
This is an initial phase of supporting a builtin menu of useful queries when using
cb psql
. Currently, it only supports predefined queries. To access this menu, simply enter:menu
into psql and it will present the available query options.Example: