How to use the pgspecial.export function in pgspecial

To help you get started, we’ve selected a few pgspecial 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 / pgspecial / pgspecial / iocommands.py View on Github external
@export
def open_external_editor(filename=None, sql=None):
    """
    Open external editor, wait for the user to type in his query,
    return the query.
    :return: list with one tuple, query as first element.
    """

    message = None
    filename = filename.strip().split(' ', 1)[0] if filename else None

    sql = sql or ''
    MARKER = '# Type your query above this line.\n'

    # Populate the editor buffer with the partial sql (if available) and a
    # placeholder comment.
    query = click.edit(u'{sql}\n\n{marker}'.format(sql=sql, marker=MARKER),
github dbcli / pgspecial / pgspecial / iocommands.py View on Github external
@export
def get_filename(sql):
    if sql.strip().startswith('\\e'):
        command, _, filename = sql.partition(' ')
        return filename.strip() or None
github dbcli / pgspecial / pgspecial / main.py View on Github external
@export
def content_exceeds_width(row, width):
    # Account for 3 characters between each column
    separator_space = (len(row)*3)
    # Add 2 columns for a bit of buffer
    line_len = sum([len(x) for x in row]) + separator_space + 2
    return line_len > width
github dbcli / pgspecial / pgspecial / iocommands.py View on Github external
@export
def get_watch_command(command):
    match = re.match("(.*?)[\s]*\\\\watch (\d+);?$", command)
    if match:
        groups = match.groups()
        return groups[0], int(groups[1])
    return None, None
github dbcli / pgspecial / pgspecial / iocommands.py View on Github external
@export
def editor_command(command):
    """
    Is this an external editor command?  (\e or \ev)

    :param command: string

    Returns the specific external editor command found.
    """
    # It is possible to have `\e filename` or `SELECT * FROM \e`. So we check
    # for both conditions.

    stripped = command.strip()
    for sought in ('\\e ', '\\ev ', '\\ef '):
        if stripped.startswith(sought):
            return sought.strip()
    for sought in ('\\e', ):
github dbcli / pgspecial / pgspecial / iocommands.py View on Github external
@export
def get_editor_query(sql):
    """Get the query part of an editor command."""
    sql = sql.strip()

    # The reason we can't simply do .strip('\e') is that it strips characters,
    # not a substring. So it'll strip "e" in the end of the sql also!
    # Ex: "select * from style\e" -> "select * from styl".
    pattern = re.compile('(^\\\e|\\\e$)')
    while pattern.search(sql):
        sql = pattern.sub('', sql)

    return sql
github dbcli / pgspecial / pgspecial / main.py View on Github external
@export
def parse_special_command(sql):
    command, _, arg = sql.partition(' ')
    verbose = '+' in command

    command = command.strip().replace('+', '')
    return (command, verbose, arg.strip())