How to use the pgcli.packages.parseutils.utils.find_prev_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 / parseutils / test_parseutils.py View on Github external
def test_find_prev_keyword_where(sql):
    kw, stripped = find_prev_keyword(sql)
    assert kw.value == 'where' and stripped == 'select * from foo where'
github dbcli / pgcli / tests / parseutils / test_parseutils.py View on Github external
def test_find_prev_keyword_open_parens(sql):
    kw, _ = find_prev_keyword(sql)
    assert kw.value == "("
github dbcli / pgcli / tests / parseutils / test_parseutils.py View on Github external
def test_find_prev_keyword_using():
    q = "select * from tbl1 inner join tbl2 using (col1, "
    kw, q2 = find_prev_keyword(q)
    assert kw.value == "(" and q2 == "select * from tbl1 inner join tbl2 using ("
github dbcli / pgcli / tests / parseutils / test_parseutils.py View on Github external
def test_find_prev_keyword_where(sql):
    kw, stripped = find_prev_keyword(sql)
    assert kw.value == "where" and stripped == "select * from foo where"
github dbcli / pgcli / tests / parseutils / test_parseutils.py View on Github external
def test_find_prev_keyword_open_parens(sql):
    kw, _ = find_prev_keyword(sql)
    assert kw.value == '('
github dbcli / pgcli / tests / parseutils / test_parseutils.py View on Github external
def test_find_prev_keyword_using():
    q = 'select * from tbl1 inner join tbl2 using (col1, '
    kw, q2 = find_prev_keyword(q)
    assert kw.value == '(' and q2 == 'select * from tbl1 inner join tbl2 using ('
github dbcli / pgcli / pgcli / packages / sqlcompletion.py View on Github external
def reduce_to_prev_keyword(self, n_skip=0):
        prev_keyword, self.text_before_cursor = find_prev_keyword(
            self.text_before_cursor, n_skip=n_skip
        )
        return prev_keyword
github dbcli / pgcli / pgcli / packages / sqlcompletion.py View on Github external
# sqlparse groups all tokens from the where clause into a single token
        # list. This means that token.value may be something like
        # 'where foo > 5 and '. We need to look "inside" token.tokens to handle
        # suggestions in complicated where clauses correctly
        prev_keyword = stmt.reduce_to_prev_keyword()
        return suggest_based_on_last_token(prev_keyword, stmt)
    elif isinstance(token, Identifier):
        # If the previous token is an identifier, we can suggest datatypes if
        # we're in a parenthesized column/field list, e.g.:
        #       CREATE TABLE foo (Identifier 
        #       CREATE FUNCTION foo (Identifier 
        # If we're not in a parenthesized list, the most likely scenario is the
        # user is about to specify an alias, e.g.:
        #       SELECT Identifier 
        #       SELECT foo FROM Identifier 
        prev_keyword, _ = find_prev_keyword(stmt.text_before_cursor)
        if prev_keyword and prev_keyword.value == "(":
            # Suggest datatypes
            return suggest_based_on_last_token("type", stmt)
        else:
            return (Keyword(),)
    else:
        token_v = token.value.lower()

    if not token:
        return (Keyword(), Special())
    elif token_v.endswith("("):
        p = sqlparse.parse(stmt.text_before_cursor)[0]

        if p.tokens and isinstance(p.tokens[-1], Where):
            # Four possibilities:
            #  1 - Parenthesized clause like "WHERE foo AND ("