Overview

Overview

Generate valid autocomplete suggestions for keywords, tables, or columns.

Supports MySQL, T-SQL (SQL Server), PL/pgSQL (PostgreSQL) and PL/SQL (Oracle) dialects.

Install

npm install sql-autocomplete

Get Started

import { SQLAutocomplete, SQLDialect } from 'sql-autocomplete';

const sqlAutocomplete = new SQLAutocomplete(SQLDialect.MYSQL);
const sql1 = 'SELECT * FR';
const options1 = sqlAutocomplete.autocomplete(sql1);
console.dir(options1);

// [ AutocompleteOption { value: 'FROM', optionType: 'KEYWORD' } ]

const sqlAutocompleteWithNames = new SQLAutocomplete(SQLDialect.MYSQL, 
                                                        ['myDatabaseTableName'], // Optional
                                                        ['aColumnName']          // Optional
                                                    );
const sql2 = 'SELECT * FROM myDatabaseTableNa';
const options2 = sqlAutocompleteWithNames.autocomplete(sql2);
console.dir(options2);

// [ AutocompleteOption { value: 'myDatabaseTableName', optionType: 'TABLE' } ]

Created By

modelDBA logo

sql-autocomplete is a project created and maintained by modelDBA, a database IDE for modern developers. modelDBA lets you visualize SQL as you type and edit tables easily with a no-code table editor.

API

Full API documentation.

Private API

Documentation for private API methods. These are not intended for regular usage. It is not guaranteed that changes in functionality will be correctly reflected by changes in the module version numbers.