jelly-db-query-parser
v0.1.0
Published
Query parser for SQL scripts
Downloads
8
Maintainers
Readme
db-query-parser
Helper to parse and manage string sql queries
Instalation
install with npm
npm install jelly-db-query-parser
install with yarn
yarn add jelly-db-query-parser
Documentation
Parse script using position 0 of cursor
import { ParserController } from '../index';
const query: string = 'select * from mytable; insert into mytable ("col1") VALUES("blablabla") select * from mytable2;table2;';
const q: string = ParserController.getInstance().getQuery(query, 0, 0);
console.log(q); // select * from mytable
Parse script using position of cursor from 0 until 22 (selected text with mouse)
const q: string = ParserController.getInstance().getQuery(query, 0, 22);
console.log(q); // select * from mytable;
Parse script using position 23 of cursor
const q: string = ParserController.getInstance().getQuery(query, 23, 23);
console.log(q); // insert into mytable ("col1") VALUES("blablabla") select * from mytable2
Search table
const tables: string[] = [];
tables.push('table_1');
tables.push('table_2');
tables.push('table_3');
HelperController.getInstance().setTables(tables);
HelperController.getInstance().setColumns([]);
const result: string[] = HelperController.getInstance().searchTables('able');
console.log(result); // ['table_1', 'table_2', 'table_3']
result = HelperController.getInstance().searchTables('_2');
console.log(result); // ['table_2']
Search snippet
const result: string[] = HelperController.getInstance().searchSnippet('select');
console.log(result); // ['select * from $1']
result = HelperController.getInstance().searchSnippet('select', ['tablexpto']);
console.log(result); // ['select * from tablexpto']
Identify tags and get colors
const result: any = IdentifierController.getInstance().search('select');
console.log(result); // {tag: 'select', color: 'blue'}
const color: string = IdentifierController.getInstance().colorize('select');
console.log(color); // 'blue'
Roadmap
- Add query parser to identify selected query block (Done)
- Add tables, columns quick search (Done)
- Add snippets with quick search (Done)
- Snippets with properties replace (Done)
- Identify tags, and assign properties, like color (Done)
- SQL validator (Backlog)
About
Created with ♥️ by @pedroladeira in Portugal, thanks to other contributors