From 8431b3216637a369a034a06d1344e490305d8044 Mon Sep 17 00:00:00 2001 From: koljonen Date: Thu, 12 May 2016 19:09:07 +0200 Subject: 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()", 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. --- tests/test_pgexecute.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'tests/test_pgexecute.py') 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): -- cgit v1.2.3