npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kijin-monaco-sql-languages

v0.12.0-beta.11

Published

SQL languages for the Monaco Editor, based on monaco-languages.

Downloads

7

Readme

Monaco SQL Languages

NPM version NPM downloads

English | 简体中文

This project is based on the SQL language project of Monaco Editor, which was forked from the monaco-languages.

The difference is that Monaco SQL Languages has integrated with various SQL languages for the Big Data field, such as FlinkSQL, SparkSQL, HiveSQL, and others.

In addition, Monaco SQL Languages provides SQL syntax validation and CodeCompletion feature for these languages via dt-sql-parser.

Online Preview

Powered By molecule.

https://dtstack.github.io/monaco-sql-languages/

Supported SQL Languages

  • MySQL
  • FlinkSQL
  • SparkSQL
  • HiveSQL
  • TrinoSQL (PrestoSQL)
  • PostgreSQL
  • Impala SQL

Supported CodeCompletion SQL Languages

| SQL Type | Language Id | Code-Completion | | ---------- | ----------- | --------------- | | MySQL | mysql | ✅ | | Flink SQL | flinksql | ✅ | | Spark SQL | sparksql | ✅ | | Hive SQL | hivesql | ✅ | | Trino SQL | trinosql | ✅ | | PostgreSQL | pgsql | ✅ | | Impala SQL | impalasql | ✅ |

Monaco SQL Languages plan to support more types of SQL Languages in the future. If you need some SQL Languages that are not currently supported, you can contact us at github.

Installing

npm install monaco-sql-languages

Tips: Monaco SQL Languages is only guaranteed to work stably on [email protected] for now.

Integrating

Usage

  1. Import language contributions

    Tips: If integrated via MonacoEditorWebpackPlugin, it will help us to import contribution files automatically. Otherwise, you need to import the contribution files manually.

    import 'monaco-sql-languages/out/esm/mysql/mysql.contribution';
    import 'monaco-sql-languages/out/esm/flinksql/flinksql.contribution';
    import 'monaco-sql-languages/out/esm/sparksql/sparksql.contribution';
    import 'monaco-sql-languages/out/esm/hivesql/hivesql.contribution';
    import 'monaco-sql-languages/out/esm/trinosql/trinosql.contribution';
    import 'monaco-sql-languages/out/esm/impalasql/impalasql.contribution';
    import 'monaco-sql-languages/out/esm/pgsql/pgsql.contribution';
    
    // Or you can import all language contributions at once.
    // import 'monaco-sql-languages/out/esm/monaco.contribution';
  2. Setup language features

    You can setup language features via setupLanguageFeatures. For example, disable code completion feature of flinkSQL language.

    import {
        setupLanguageFeatures,
        LanguageIdEnum,
    } from 'monaco-sql-languages';
    
    setupLanguageFeatures({
        languageId: LanguageIdEnum.FLINK,
        completionItems: false
    })

    By default, Monaco SQL Languages only provides keyword autocompletion, and you can customize your completionItem list via completionService.

    import { languages } from 'monaco-editor/esm/vs/editor/editor.api';
    import {
        setupLanguageFeatures,
        LanguageIdEnum,
        CompletionService,
        ICompletionItem,
        SyntaxContextType
     } from 'monaco-sql-languages';
    
    const completionService: CompletionService = function (
        model,
        position,
        completionContext,
        suggestions
    ) {
        return new Promise((resolve, reject) => {
            if (!suggestions) {
                return Promise.resolve([]);
            }
            const { keywords, syntax } = suggestions;
            const keywordsCompletionItems: ICompletionItem[] = keywords.map((kw) => ({
                label: kw,
                kind: languages.CompletionItemKind.Keyword,
                detail: 'keyword',
                sortText: '2' + kw
            }));
    
            let syntaxCompletionItems: ICompletionItem[] = [];
    
            syntax.forEach((item) => {
                if (item.syntaxContextType === SyntaxContextType.DATABASE) {
                    const databaseCompletions: ICompletionItem[] = []; // some completions about databaseName
                    syntaxCompletionItems = [...syntaxCompletionItems, ...databaseCompletions];
                }
                if (item.syntaxContextType === SyntaxContextType.TABLE) {
                    const tableCompletions: ICompletionItem[] = []; // some completions about tableName
                    syntaxCompletionItems = [...syntaxCompletionItems, ...tableCompletions];
                }
            });
    
            resolve([...syntaxCompletionItems, ...keywordsCompletionItems]);
        });
    };
    
    setupLanguageFeatures({
        languageId: LanguageIdEnum.FLINK,
        completionService: completionService,
    })
  3. Create the Monaco Editor instance and specify the language you need

    monaco.editor.create(document.getElementById('container'), {
        value: 'select * from tb_test',
        language: 'flinksql' // you need
    });

Monaco Theme

Monaco SQL Languages plan to support more themes in the future.

Monaco SQL Languages provides built-in Monaco Theme that is named vsPlusTheme. vsPlusTheme inspired by vscode default plus colorTheme and it contains three styles of themes inside:

  • darkTheme: inherited from Monaco built-in Theme vs-dark;
  • lightTheme: inherited from Monaco built-in Theme vs;
  • hcBlackTheme: inherited from Monaco built-in Theme hc-black;

Use Monaco SQL Languages built-in vsPlusTheme

import { vsPlusTheme } from 'monaco-sql-languages';
import { editor } from 'monaco-editor';

// import themeData and defineTheme, you can customize the theme name, e.g. sql-dark
editor.defineTheme('sql-dark', vsPlusTheme.darkThemeData);
editor.defineTheme('sql-light', vsPlusTheme.lightThemeData);
editor.defineTheme('sql-hc', vsPlusTheme.hcBlackThemeData);

// specify the theme you have defined
editor.create(null as any, {
    theme: 'sql-dark',
    language: 'flinksql'
});

Customize your own Monaco theme

import { TokenClassConsts, postfixTokenClass } from 'monaco-sql-languages';

// Customize the various tokens style
const myThemeData: editor.IStandaloneThemeData = {
    base: 'vs-dark',
    inherit: true,
    rules: [
        { token: postfixTokenClass(TokenClassConsts.COMMENT), foreground: '6a9955' },
        { token: postfixTokenClass(TokenClassConsts.IDENTIFIER), foreground: '9cdcfe' },
        { token: postfixTokenClass(TokenClassConsts.KEYWORD), foreground: '569cd6' },
        { token: postfixTokenClass(TokenClassConsts.NUMBER), foreground: 'b5cea8' },
        { token: postfixTokenClass(TokenClassConsts.STRING), foreground: 'ce9178' },
        { token: postfixTokenClass(TokenClassConsts.TYPE), foreground: '4ec9b0' }
    ],
    colors: {}
};

// Define the monaco theme
editor.defineTheme('my-theme', myThemeData);

postfixTokenClass is not required in most cases, but since Monaco SQL Languages has tokenPostfix: 'sql' internally set for all SQL languages, in some cases your custom style may not work if you don't use postfixTokenClassClass to handle TokenClassConsts.*.

Dev: cheat sheet

  • initial setup

    pnpm install
  • open the dev web

    pnpm watch-esm
    cd website
    pnpm install
    pnpm dev
  • compile

    pnpm compile
  • run test

    pnpm compile
    pnpm test

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

License

MIT