From d7832198abab8f0c8a629782d9622834d6cd5523 Mon Sep 17 00:00:00 2001 From: RandomFractals Date: Thu, 9 Feb 2023 06:58:23 -0600 Subject: [PATCH 1/2] update prql-js dependency to v0.5.0 in package.json --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4ecd68d..8fe9f59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.4.2", "dependencies": { "@types/vscode": "^1.75.0", - "prql-js": "^0.4.2", + "prql-js": "^0.5.0", "shiki": "^0.14.0" }, "devDependencies": { @@ -1320,9 +1320,9 @@ } }, "node_modules/prql-js": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/prql-js/-/prql-js-0.4.2.tgz", - "integrity": "sha512-L2EiM9QmOSD0AlZC9WXbN6dO5HeOo8HddKPCBjVo9bCSy67l65B4NqwD9ZfB9korxHXevXqk2F/vTptIDlauNg==" + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/prql-js/-/prql-js-0.5.0.tgz", + "integrity": "sha512-ozlrhX9uDc350ratvytXeu5T64ChMLVa/k6IG4Okk4gAmnStIZuZWmH8/GH3Vb3TPTo2hgPEdCt3k91rasMl/A==" }, "node_modules/punycode": { "version": "2.2.0", diff --git a/package.json b/package.json index d50bccb..189af5d 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,7 @@ }, "dependencies": { "@types/vscode": "^1.75.0", - "prql-js": "^0.4.2", + "prql-js": "^0.5.0", "shiki": "^0.14.0" }, "devDependencies": { From fbf2718b0334287337b946a9eae21d81044cb37e Mon Sep 17 00:00:00 2001 From: RandomFractals Date: Thu, 9 Feb 2023 06:58:46 -0600 Subject: [PATCH 2/2] use new compile options with target in compile.ts --- src/compiler.ts | 42 +++--------------------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 6ab3291..42faa23 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2,12 +2,11 @@ import { workspace } from 'vscode'; import * as prql from 'prql-js'; export function compile(prqlString: string): string | ErrorMessage[] { + // create compile options from prql workspace settings + const compileOptions = new prql.CompileOptions(); const target = workspace.getConfiguration('prql').get('target'); - const options: CompileOptions = { target: target }; + compileOptions.target = `sql.${target.toLowerCase()}`; try { - // map new compile options to the old prql JS SQL options for now - const compileOptions = new prql.SQLCompileOptions(); - compileOptions.dialect = targetToDialect(options.target); return prql.compile(prqlString, compileOptions) as string; } catch (error) { if ((error as any)?.message) { @@ -22,10 +21,6 @@ export function compile(prqlString: string): string | ErrorMessage[] { } } -export interface CompileOptions { - target?: string; -} - export interface ErrorMessage { /// Plain text of the error reason: string; @@ -48,34 +43,3 @@ export interface SourceLocation { start: [number, number]; end: [number, number]; } - -/** - * Temp. target to dialect conversion function till we update prql-js. - * @param target Compilation target string. - */ -function targetToDialect(target: string | undefined) { - switch (target) { - case 'BigQuery': - return prql.Dialect.BigQuery; - case 'ClickHouse': - return prql.Dialect.ClickHouse; - case 'DuckDb': - return prql.Dialect.DuckDb; - case 'Generic': - return prql.Dialect.Generic; - case 'Hive': - return prql.Dialect.Hive; - case 'MsSql': - return prql.Dialect.MsSql; - case 'MySql': - return prql.Dialect.MySql; - case 'PostgreSql': - return prql.Dialect.PostgreSql; - case 'SQLite': - return prql.Dialect.SQLite; - case 'Snowflake': - return prql.Dialect.Snowflake; - default: - return prql.Dialect.Ansi; - } -}