Skip to content

Instantly share code, notes, and snippets.

@meeuw
Created February 6, 2018 20:39
Show Gist options
  • Save meeuw/cf211b391f3bb6e18e8fe772fc30d8a6 to your computer and use it in GitHub Desktop.
Save meeuw/cf211b391f3bb6e18e8fe772fc30d8a6 to your computer and use it in GitHub Desktop.

New sqlcomplete library

Design Principles

  • Easily extendable for different SQL dialects (PostgreSQL/MySQL/MS-SQL/SQLLite)
  • Completion should always work, also with invalid/incomplete SQL
  • Use sqlparse and prompt_toolkit as much as possible, don't try to abstract either
  • Prioritize suggestions, the top suggestions always should complete to valid SQL. Tab-tab-tab-tab should complete to something like select * from firsttable

Design

SQLComplete will provide an implementation of prompt_toolkit.completion.Completer. For this completer specific SQL completers can be registered (like SelectComplete, InsertComplete, UpdateComplete etc). These SQL completers can make use of each other (for queries like INSERT INTO table SELECT * FROM table). SQLComplete also provides partial completers like WhereComplete for completing for example the WHERE part of a SQL query.

The purpose of these completers is to return prioritized completions which would pull the current query to valid SQL. For example: SelectComplete would suggest table names for the following query SELECT | FROM table (| = cursor). Or more complex, SelectComplete would suggest WHERE for SELECT abc FROM table | SELECT.

To make SQL specific dialect changes these SQL completers should be subclassed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment