How to use the pgcli.packages.sqlcompletion.Keyword 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_col_comma_suggests_cols():
    suggestions = suggest_type("SELECT a, b, FROM tbl", "SELECT a, b,")
    assert set(suggestions) == set(
        [
            Column(table_refs=((None, "tbl", None, False),), qualifiable=True),
            Function(schema=None),
            Keyword("SELECT"),
        ]
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
                Keyword("SELECT"),
            ],
        ),
        ("\\ns abc SELECT foo ", "SELECT foo ", (Keyword(),)),
        (
            "\\ns abc SELECT t1. FROM tabl1 t1",
            "SELECT t1.",
            [
                Table(schema="t1"),
                View(schema="t1"),
                Column(table_refs=((None, "tabl1", "t1", False),)),
                Function(schema="t1"),
            ],
        ),
    ],
)
def test_named_query_completion(text, before, expected):
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_lparen_suggests_cols_and_funcs():
    suggestion = suggest_type("SELECT MAX( FROM tbl", "SELECT MAX(")
    assert set(suggestion) == set(
        [
            Column(table_refs=((None, "tbl", None, False),), qualifiable=True),
            Function(schema=None),
            Keyword("("),
        ]
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_sub_select_col_name_completion():
    suggestions = suggest_type(
        "SELECT * FROM (SELECT  FROM abc", "SELECT * FROM (SELECT "
    )
    assert set(suggestions) == set(
        [
            Column(table_refs=((None, "abc", None, False),), qualifiable=True),
            Function(schema=None),
            Keyword("SELECT"),
        ]
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def cols_etc(
    table, schema=None, alias=None, is_function=False, parent=None, last_keyword=None
):
    """Returns the expected select-clause suggestions for a single-table
    select."""
    return set(
        [
            Column(
                table_refs=(TableReference(schema, table, alias, is_function),),
                qualifiable=True,
            ),
            Function(schema=parent),
            Keyword(last_keyword),
        ]
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_statements_with_cursor_before_function_body(text):
    suggestions = suggest_type(text, "")
    assert set(suggestions) == set([Keyword(), Special()])
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_distinct_suggests_cols(text):
    suggestions = suggest_type(text, text)
    assert set(suggestions) == set(
        [
            Column(table_refs=(), local_tables=(), qualifiable=True),
            Function(schema=None),
            Keyword("DISTINCT"),
        ]
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_alias_suggests_keywords(text):
    suggestions = suggest_type(text, text)
    assert suggestions == (Keyword(),)
github dbcli / pgcli / tests / test_sqlcompletion.py View on Github external
def test_invalid_sql():
    # issue 317
    text = "selt *"
    suggestions = suggest_type(text, text)
    assert suggestions == (Keyword(),)
github dbcli / pgcli / pgcli / pgcompleter.py View on Github external
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,
    }

    def populate_scoped_cols(self, scoped_tbls, local_tbls=()):
        """Find all columns in a set of scoped_tables.

        :param scoped_tbls: list of TableReference namedtuples
        :param local_tbls: tuple(TableMetadata)
        :return: {TableReference:{colname:ColumnMetaData}}

        """
        ctes = dict((normalize_ref(t.name), t.columns) for t in local_tbls)
        columns = OrderedDict()