diff options
author | koljonen <koljonen@outlook.com> | 2016-05-12 19:09:07 +0200 |
---|---|---|
committer | koljonen <koljonen@outlook.com> | 2016-05-24 14:18:19 +0200 |
commit | 8431b3216637a369a034a06d1344e490305d8044 (patch) | |
tree | 694d55c08d12db044a4f3b43036cb8d9265c204e /tests/test_pgexecute.py | |
parent | f1b60c2a411c4ae4dcb7377f088f64a99d43be99 (diff) |
Support for join-condition suggestions after ON
The user types 'SELECT * FROM parenttable p JOIN childtable c on '. We then suggest ['c.parenttableid = p.parenttableid', 'c.createdby = p.createdby', ...] as completions.
The suggestions are FK matches first, then name matches for int columns, then name matches for other columns, sorted by proximity from the cursor to the other table.
Some changes:
For "JOIN Foo USING(<cursor>)", now only columns present in Foo are suggested.
For all suggestions after 'ON', now only the tables before the cursor are considered.
meta[reltype]][relname] goes from being a list of columns to being an OrderedDict {column_name:ColumnMetadata}, where the ColumnMetaData contains the column's name, data type and a list of FKs involving the column. This entails modification of a number of functions dealing with columns.
Diffstat (limited to 'tests/test_pgexecute.py')
-rw-r--r-- | tests/test_pgexecute.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/tests/test_pgexecute.py b/tests/test_pgexecute.py index 9d04da85..c7ed1885 100644 --- a/tests/test_pgexecute.py +++ b/tests/test_pgexecute.py @@ -50,18 +50,28 @@ def test_schemata_table_views_and_columns_query(executor): # tables assert set(executor.tables()) >= set([ - ('public', 'a'), ('public', 'b'), ('schema1', 'c')]) + ('public', 'a'), ('public', 'b'), ('schema1', 'c')]) assert set(executor.table_columns()) >= set([ - ('public', 'a', 'x'), ('public', 'a', 'y'), - ('public', 'b', 'z'), ('schema1', 'c', 'w')]) + ('public', 'a', 'x', 'text'), ('public', 'a', 'y', 'text'), + ('public', 'b', 'z', 'text'), ('schema1', 'c', 'w', 'text')]) # views assert set(executor.views()) >= set([ ('public', 'd')]) assert set(executor.view_columns()) >= set([ - ('public', 'd', 'e')]) + ('public', 'd', 'e', 'int4')]) + +@dbtest +def test_foreign_key_query(executor): + run(executor, "create schema schema1") + run(executor, "create schema schema2") + run(executor, "create table schema1.parent(parentid int PRIMARY KEY)") + run(executor, "create table schema2.child(childid int PRIMARY KEY, motherid int REFERENCES schema1.parent)") + + assert set(executor.foreignkeys()) >= set([ + ('schema1', 'parent', 'parentid', 'schema2', 'child', 'motherid')]) @dbtest def test_functions_query(executor): |