Skip to content

SQL autocompletion library specific for subgraph sql data service

License

Notifications You must be signed in to change notification settings

semiotic-ai/graph-autocomplete

Repository files navigation

graph-autocomplete

SQL autcomplete for subgraph SQL data services

semantic-release Actions Status License

npm install version

Highlights

  • SQL autocomplete to be used with parsed db schema from a subgraph via graph-tables.
  • Supports incomplete SQL
  • Supports table and column aliases
  • All whitelisted SQL functions
  • Package include CommonJS, ES Modules, UMD version and TypeScript declaration files.

Planned

  • Support for enum type
  • Use relations for database joins
  • Support for function description (signature, example, etc.)
  • Support for column description (type, info, etc.)

Install

npm install @semiotic-labs/graph-autocomplete

Usage

import {AutoComplete, Suggestion, SuggestionType} from '@semiotic-labs/graph-autocomplete';
import {parse} from '@semiotic-labs/graph-tables';

const simple_schema = `
    type SomeComplexTableErc20Name  @entity {
        "Some description about a string field"
        id: ID!,
        nullableField:Boolean,
        booleanField:Boolean!,
        bigIntField:BigInt!,
        bytesField:Bytes!,
        bigDecimalField:BigDecimal!,
        intField:Int!,
        int8Field:Int8!,
        stringField:String!
    }
`;

const layout = parse(simple_schema);
const autocomplete = new AutoComplete({logErrors: false, throwErrors: false});
autocomplete.updateLayout(layout);

const suggestions = autocomplete.suggest('SELECT some');
assert.equal(suggestions.some((suggestion) => 
    suggestion.type === SuggestionType.TABLE 
    && suggestion.value === "some_complex_table_erc_20_name"
),true);

Development

The tool used to generate TypeScript code from an ANTLR 4 grammar is written in Java. To fully utilize the ANTLR 4 TypeScript target (including the ability to regenerate code from a grammar file after changes are made), a Java Runtime Environment (JRE) needs to be installed on the developer machine. The generated code itself uses several features new to TypeScript 2.0.

-Java Runtime Environment 1.6+ (1.8+ recommended)

See syntax folder for updating both supported functions and SQL lexicon.After changes run

npm run lang-build

About

SQL autocompletion library specific for subgraph sql data service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages