@malloydata/malloy 0.0.55-dev230707164317 → 0.0.55-dev230707183945

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -88,8 +88,13 @@ function getShortString(cx) {
88
88
  // shortString: DQ_STRING | SQ_STRING; So this will never happen
89
89
  return '';
90
90
  }
91
- function containsID(cx) {
92
- return 'id' in cx;
91
+ function getOptionalString(cx) {
92
+ function containsString(cx) {
93
+ return 'shortString' in cx;
94
+ }
95
+ if (containsString(cx) && cx.shortString()) {
96
+ return getShortString(cx);
97
+ }
93
98
  }
94
99
  /**
95
100
  * An identifier is either a sequence of id characters or a `quoted`
@@ -105,6 +110,9 @@ function getId(cx) {
105
110
  return cx.id().text;
106
111
  }
107
112
  function getOptionalId(cx) {
113
+ function containsID(cx) {
114
+ return 'id' in cx;
115
+ }
108
116
  if (containsID(cx) && cx.id()) {
109
117
  return getId(cx);
110
118
  }
@@ -310,7 +318,13 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
310
318
  const connectionName = this.astAt(this.getModelEntryName(connId), connId);
311
319
  const sqlStr = new ast.SQLString();
312
320
  const selCx = pcx.sqlString();
313
- this.makeSqlString(selCx, sqlStr);
321
+ if (selCx) {
322
+ this.makeSqlString(selCx, sqlStr);
323
+ }
324
+ const shortSelect = getOptionalString(pcx);
325
+ if (shortSelect) {
326
+ sqlStr.push(shortSelect);
327
+ }
314
328
  const expr = new ast.SQLSource(connectionName, sqlStr);
315
329
  return this.astAt(expr, pcx);
316
330
  }
@@ -2788,6 +2788,34 @@ describe('sql expressions', () => {
2788
2788
  expect(m).toTranslate();
2789
2789
  }
2790
2790
  });
2791
+ test('sql expression legal with single quote', () => {
2792
+ const m = (0, test_translator_1.model) `
2793
+ source: na is bigquery.sql('SELECT 1 as one')
2794
+ `;
2795
+ expect(m).toParse();
2796
+ const compileSql = m.translator.translate().compileSQL;
2797
+ expect(compileSql).toBeDefined();
2798
+ if (compileSql) {
2799
+ m.translator.update({
2800
+ compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
2801
+ });
2802
+ expect(m).toTranslate();
2803
+ }
2804
+ });
2805
+ test('sql expression legal with double quote', () => {
2806
+ const m = (0, test_translator_1.model) `
2807
+ source: na is bigquery.sql("SELECT 1 as one")
2808
+ `;
2809
+ expect(m).toParse();
2810
+ const compileSql = m.translator.translate().compileSQL;
2811
+ expect(compileSql).toBeDefined();
2812
+ if (compileSql) {
2813
+ m.translator.update({
2814
+ compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
2815
+ });
2816
+ expect(m).toTranslate();
2817
+ }
2818
+ });
2791
2819
  test('reference to sql expression in extended source', () => {
2792
2820
  const m = (0, test_translator_1.model) `
2793
2821
  source: na is bigquery.sql("""SELECT 1 as one""") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.55-dev230707164317",
3
+ "version": "0.0.55-dev230707183945",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",