Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prql-js v0.5.0 update with new prql.CompileOptions target usage #66

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
42 changes: 3 additions & 39 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <string>workspace.getConfiguration('prql').get('target');
const options: CompileOptions = { target: target };
compileOptions.target = `sql.${target.toLowerCase()}`;
RandomFractals marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand All @@ -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;
Expand All @@ -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;
}
}