Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@codemirror/lang-sql
Advanced tools
@codemirror/lang-sql is a language support package for CodeMirror 6 that provides syntax highlighting, autocompletion, and other SQL language features. It is designed to help developers integrate SQL editing capabilities into their web applications.
Syntax Highlighting
This feature provides syntax highlighting for SQL code. The code sample demonstrates how to set up a CodeMirror editor with SQL syntax highlighting.
import { sql } from '@codemirror/lang-sql';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'SELECT * FROM users;',
extensions: [basicSetup, sql()]
});
const view = new EditorView({
state,
parent: document.body
});
Autocompletion
This feature provides autocompletion for SQL code. The code sample demonstrates how to set up a CodeMirror editor with SQL autocompletion.
import { sql, sqlCompletion } from '@codemirror/lang-sql';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';
import { autocompletion } from '@codemirror/autocomplete';
const state = EditorState.create({
doc: 'SELECT * FROM ',
extensions: [basicSetup, sql(), autocompletion({ override: [sqlCompletion] })]
});
const view = new EditorView({
state,
parent: document.body
});
Error Checking
This feature provides error checking for SQL code. The code sample demonstrates how to set up a CodeMirror editor with SQL error checking.
import { sql, sqlDiagnostics } from '@codemirror/lang-sql';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';
import { linter } from '@codemirror/lint';
const state = EditorState.create({
doc: 'SELECT * FORM users;',
extensions: [basicSetup, sql(), linter(sqlDiagnostics)]
});
const view = new EditorView({
state,
parent: document.body
});
codemirror-graphql provides GraphQL language support for CodeMirror. It offers similar features like syntax highlighting, autocompletion, and error checking but for GraphQL instead of SQL.
[ WEBSITE | ISSUES | FORUM | CHANGELOG ]
This package implements SQL language support for the CodeMirror code editor.
The project page has more information, a number of examples and the documentation.
This code is released under an MIT license.
We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.
sql(config?: SQLConfig = {}) → LanguageSupport
SQL language support for the given SQL dialect, with keyword completion, and, if provided, schema-based completion as extra extensions.
Options used to configure an SQL extension.
dialect?: SQLDialect
The dialect to use. Defaults to
StandardSQL
.
schema?: Object<readonly (string | Completion)[]>
An object that maps table names to options (columns) that can be completed for that table. Use lower-case names here.
tables?: readonly Completion[]
By default, the completions for the table names will be
generated from the schema
object. But if you want to
customize them, you can pass an array of completions through
this option.
defaultTable?: string
When given, columns from the named table can be completed directly at the top level.
upperCaseKeywords?: boolean
When set to true, keyword completions will be upper-case.
Represents an SQL dialect.
language: LezerLanguage
The language for this dialect.
extension: Extension
Returns the language for this dialect as an extension.
static define(spec: Object) → SQLDialect
Define a new dialect.
spec
keywords?: string
A space-separated list of keywords for the dialect.
builtin?: string
A space-separated string of built-in identifiers for the dialect.
types?: string
A space-separated string of type names for the dialect.
backslashEscapes?: boolean
Controls whether regular strings allow backslash escapes.
hashComments?: boolean
Controls whether # creates a line comment.
slashComments?: boolean
Controls whether //
creates a line comment.
spaceAfterDashes?: boolean
When enabled --
comments are only recognized when there's a
space after the dashes.
doubleQuotedStrings?: boolean
When enabled, things quoted with double quotes are treated as strings, rather than identifiers.
charSetCasts?: boolean
Enables strings like _utf8'str'
or N'str'
.
operatorChars?: string
The set of characters that make up operators. Defaults to
"*+\-%<>!=&|~^/"
.
specialVar?: string
The set of characters that start a special variable name.
Defaults to "?"
.
identifierQuotes?: string
The characters that can be used to quote identifiers. Defaults
to "\""
.
StandardSQL: SQLDialect
The standard SQL dialect.
PostgreSQL: SQLDialect
Dialect for PostgreSQL.
MySQL: SQLDialect
MySQL dialect.
MariaSQL: SQLDialect
MSSQL: SQLDialect
SQL dialect for Microsoft SQL Server.
SQLite: SQLDialect
SQLite dialect.
Cassandra: SQLDialect
Dialect for Cassandra's SQL-ish query language.
PLSQL: SQLDialect
PL/SQL dialect.
keywordCompletion(dialect: SQLDialect, upperCase?: boolean = false) → Extension
Returns an extension that enables keyword completion for the given SQL dialect.
schemaCompletion(config: SQLConfig) → Extension
Returns an extension that enables schema-based completion for the given configuration.
0.17.2 (2021-02-01)
Fix bad syntax tree creation when the input ends with an unfinished quoted identifier.
FAQs
SQL language support for the CodeMirror code editor
The npm package @codemirror/lang-sql receives a total of 218,543 weekly downloads. As such, @codemirror/lang-sql popularity was classified as popular.
We found that @codemirror/lang-sql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.