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
Suggest objects from schemas not in search_path #649
Conversation
No changes in function.
And schema-qualifying them, of course, so that for `SELECT * FROM bar` we might suggest `buildings.barns` and for `select dopi` we might suggest `maintenance.delete_old_personal_info()`, for example. Controlled by a config setting, `search_path_filter`, in case anyone prefers the old behaviour.
Sorry I'm on vacation right now, I'll definitely have a look when I get
back next week
|
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.
This is nice. I left some requests for additional comments in the review.
I wonder how this interacts with the priorization? E.g. in test_smart_completion_multiple_schemata
, select * from u
should suggest both 'users' and 'custom.users'. Should we ensure that users
is ranked ahead of the schema qualified one?
pgcli/pgcompleter.py
Outdated
|
||
def _maybe_schema(self, schema, parent): | ||
return None if parent or schema in self.search_path else schema | ||
|
||
def populate_schema_objects(self, schema, obj_type): | ||
"""Returns list of tables or functions for a (optional) schema""" |
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.
should be changed to Returns a list of SchemaObjects...
pgcli/pgcompleter.py
Outdated
cased_tbl = self.case(tbl) | ||
alias = self.alias(cased_tbl, suggestion.table_refs) | ||
def _make_cand(self, tbl, do_alias, suggestion): | ||
cased_tbl = self.case(tbl.name) |
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.
Add a comment here that tbl
is a SchemaObject?
pgcli/pgcompleter.py
Outdated
@@ -747,22 +753,28 @@ def addcols(schema, rel, alias, reltype, cols): | |||
|
|||
return columns | |||
|
|||
def _get_schemas(self, obj_typ, schema): | |||
metadata = self.dbmetadata[obj_typ] |
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.
A docstring here would be nice. like "Return a list of schemas from which SchemaObject
s can be suggested", and note that schema
is the optional user-specified schema qualification?
Pushed some changes. |
Looks good! |
I keep typing e.g.
SELECT mff
and getting annoyed whensomeschema.my_fancy_function()
isn't suggested because I forgot to type the schema first. So this fixes that, for tables, views functions and datatypes.There's a config option for getting the old behaviour.
I added some rudimentary tests. I'm working on another branch where I'll make it more convenient to run the same test for different completer configs, which will add some more test cases for this feature as well.
Sending this to you @darikg, as it's related to a bunch of my other stuff you've reviewed.