How to use the pgcli.packages.sqlcompletion.FromClauseItem function in pgcli

To help you get started, we’ve selected a few pgcli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_suggest_after_join_with_two_tables(expression):
    suggestions = suggest_type(expression, expression)
    tables = tuple([(None, "foo", None, False), (None, "bar", None, False)])
    assert set(suggestions) == set(
        [FromClauseItem(schema=None, table_refs=tables), Join(tables, None), Schema()]
    )
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_table_comma_suggests_tables_and_schemas():
    suggestions = suggest_type("SELECT a, b FROM tbl1, ", "SELECT a, b FROM tbl1, ")
    assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_left_join_with_comma():
    text = "select * from foo f left join bar b,"
    suggestions = suggest_type(text, text)
    # tbls should also include (None, 'bar', 'b', False)
    # but there's a bug with commas
    tbls = tuple([(None, "foo", "f", False)])
    assert set(suggestions) == set(
        [FromClauseItem(schema=None, table_refs=tbls), Schema()]
    )
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_sub_select_table_name_completion(expression):
    suggestion = suggest_type(expression, expression)
    assert set(suggestion) == set([FromClauseItem(schema=None), Schema()])
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_suggest_after_join_with_one_table(expression):
    suggestions = suggest_type(expression, expression)
    tables = ((None, "foo", None, False),)
    assert set(suggestions) == set(
        [
            FromClauseItem(schema=None, table_refs=tables),
            Join(((None, "foo", None, False),), None),
            Schema(),
        ]
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_join_suggests_tables_and_schemas(tbl_alias, join_type):
    text = "SELECT * FROM abc {0} {1} JOIN ".format(tbl_alias, join_type)
    suggestion = suggest_type(text, text)
    tbls = tuple([(None, "abc", tbl_alias or None, False)])
    assert set(suggestion) == set(
        [FromClauseItem(schema=None, table_refs=tbls), Schema(), Join(tbls, None)]
    )
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_2_statements_1st_current():
    suggestions = suggest_type("select * from ; select * from b", "select * from ")
    assert set(suggestions) == set([FromClauseItem(schema=None), Schema()])

    suggestions = suggest_type("select  from a; select * from b", "select ")
    assert set(suggestions) == cols_etc("a", last_keyword="SELECT")
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_suggest_qualified_tables_views_and_functions(expression):
    suggestions = suggest_type(expression, expression)
    assert set(suggestions) == set([FromClauseItem(schema="sch")])
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_ignore_leading_double_quotes(sql):
    suggestions = suggest_type(sql, sql)
    assert FromClauseItem(schema=None) in set(suggestions)
github dbcli / pgcli / pgcli / pgcompleter.py View on Github external
# Also suggest hardcoded types
            matches.extend(
                self.find_matches(
                    word_before_cursor, self.datatypes, mode="strict", meta="datatype"
                )
            )

        return matches

    def get_namedquery_matches(self, _, word_before_cursor):
        return self.find_matches(
            word_before_cursor, NamedQueries.instance.list(), meta="named query"
        )

    suggestion_matchers = {
        FromClauseItem: get_from_clause_item_matches,
        JoinCondition: get_join_condition_matches,
        Join: get_join_matches,
        Column: get_column_matches,
        Function: get_function_matches,
        Schema: get_schema_matches,
        Table: get_table_matches,
        TableFormat: get_table_formats,
        View: get_view_matches,
        Alias: get_alias_matches,
        Database: get_database_matches,
        Keyword: get_keyword_matches,
        Special: get_special_matches,
        Datatype: get_datatype_matches,
        NamedQuery: get_namedquery_matches,
        Path: get_path_matches,
    }