@@ -5,7 +5,7 @@ import { ASSETS, BASIC_SCHEMA, identityBucketTransformer, PARSE_OPTIONS } from '
55describe ( 'data queries' , ( ) => {
66 test ( 'uses bucket id transformer' , function ( ) {
77 const sql = 'SELECT * FROM assets WHERE assets.org_id = bucket.org_id' ;
8- const query = SqlDataQuery . fromSql ( 'mybucket' , [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
8+ const query = SqlDataQuery . fromSql ( [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
99 expect ( query . errors ) . toEqual ( [ ] ) ;
1010
1111 expect ( query . evaluateRow ( ASSETS , { id : 'asset1' , org_id : 'org1' } , '1#mybucket' ) ) . toEqual ( [
@@ -20,7 +20,7 @@ describe('data queries', () => {
2020
2121 test ( 'bucket parameters = query' , function ( ) {
2222 const sql = 'SELECT * FROM assets WHERE assets.org_id = bucket.org_id' ;
23- const query = SqlDataQuery . fromSql ( 'mybucket' , [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
23+ const query = SqlDataQuery . fromSql ( [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
2424 expect ( query . errors ) . toEqual ( [ ] ) ;
2525
2626 expect ( query . evaluateRow ( ASSETS , { id : 'asset1' , org_id : 'org1' } , 'mybucket' ) ) . toEqual ( [
@@ -37,7 +37,7 @@ describe('data queries', () => {
3737
3838 test ( 'bucket parameters IN query' , function ( ) {
3939 const sql = 'SELECT * FROM assets WHERE bucket.category IN assets.categories' ;
40- const query = SqlDataQuery . fromSql ( 'mybucket' , [ 'category' ] , sql , PARSE_OPTIONS , compatibility ) ;
40+ const query = SqlDataQuery . fromSql ( [ 'category' ] , sql , PARSE_OPTIONS , compatibility ) ;
4141 expect ( query . errors ) . toEqual ( [ ] ) ;
4242
4343 expect (
@@ -60,7 +60,7 @@ describe('data queries', () => {
6060
6161 test ( 'static IN data query' , function ( ) {
6262 const sql = `SELECT * FROM assets WHERE 'green' IN assets.categories` ;
63- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
63+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
6464 expect ( query . errors ) . toEqual ( [ ] ) ;
6565
6666 expect (
@@ -80,7 +80,7 @@ describe('data queries', () => {
8080
8181 test ( 'data IN static query' , function ( ) {
8282 const sql = `SELECT * FROM assets WHERE assets.condition IN '["good","great"]'` ;
83- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
83+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
8484 expect ( query . errors ) . toEqual ( [ ] ) ;
8585
8686 expect ( query . evaluateRow ( ASSETS , { id : 'asset1' , condition : 'good' } , 'mybucket' ) ) . toMatchObject ( [
@@ -96,7 +96,7 @@ describe('data queries', () => {
9696
9797 test ( 'table alias' , function ( ) {
9898 const sql = 'SELECT * FROM assets as others WHERE others.org_id = bucket.org_id' ;
99- const query = SqlDataQuery . fromSql ( 'mybucket' , [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
99+ const query = SqlDataQuery . fromSql ( [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
100100 expect ( query . errors ) . toEqual ( [ ] ) ;
101101
102102 expect ( query . evaluateRow ( ASSETS , { id : 'asset1' , org_id : 'org1' } , 'mybucket' ) ) . toEqual ( [
@@ -113,7 +113,6 @@ describe('data queries', () => {
113113 const schema = BASIC_SCHEMA ;
114114
115115 const q1 = SqlDataQuery . fromSql (
116- 'q1' ,
117116 [ 'user_id' ] ,
118117 `SELECT * FROM assets WHERE owner_id = bucket.user_id` ,
119118 PARSE_OPTIONS ,
@@ -132,7 +131,6 @@ describe('data queries', () => {
132131 ] ) ;
133132
134133 const q2 = SqlDataQuery . fromSql (
135- 'q1' ,
136134 [ 'user_id' ] ,
137135 `
138136 SELECT id :: integer as id,
@@ -167,7 +165,6 @@ describe('data queries', () => {
167165 test ( 'validate columns' , ( ) => {
168166 const schema = BASIC_SCHEMA ;
169167 const q1 = SqlDataQuery . fromSql (
170- 'q1' ,
171168 [ 'user_id' ] ,
172169 'SELECT id, name, count FROM assets WHERE owner_id = bucket.user_id' ,
173170 { ...PARSE_OPTIONS , schema } ,
@@ -176,7 +173,6 @@ describe('data queries', () => {
176173 expect ( q1 . errors ) . toEqual ( [ ] ) ;
177174
178175 const q2 = SqlDataQuery . fromSql (
179- 'q2' ,
180176 [ 'user_id' ] ,
181177 'SELECT id, upper(description) as d FROM assets WHERE other_id = bucket.user_id' ,
182178 { ...PARSE_OPTIONS , schema } ,
@@ -194,7 +190,6 @@ describe('data queries', () => {
194190 ] ) ;
195191
196192 const q3 = SqlDataQuery . fromSql (
197- 'q3' ,
198193 [ 'user_id' ] ,
199194 'SELECT id, description, * FROM nope WHERE other_id = bucket.user_id' ,
200195 { ...PARSE_OPTIONS , schema } ,
@@ -207,7 +202,7 @@ describe('data queries', () => {
207202 }
208203 ] ) ;
209204
210- const q4 = SqlDataQuery . fromSql ( 'q4' , [ ] , 'SELECT * FROM other' , { ...PARSE_OPTIONS , schema } , compatibility ) ;
205+ const q4 = SqlDataQuery . fromSql ( [ ] , 'SELECT * FROM other' , { ...PARSE_OPTIONS , schema } , compatibility ) ;
211206 expect ( q4 . errors ) . toMatchObject ( [
212207 {
213208 message : `Query must return an "id" column` ,
@@ -216,7 +211,6 @@ describe('data queries', () => {
216211 ] ) ;
217212
218213 const q5 = SqlDataQuery . fromSql (
219- 'q5' ,
220214 [ ] ,
221215 'SELECT other_id as id, * FROM other' ,
222216 { ...PARSE_OPTIONS , schema } ,
@@ -227,65 +221,65 @@ describe('data queries', () => {
227221
228222 test ( 'invalid query - invalid IN' , function ( ) {
229223 const sql = 'SELECT * FROM assets WHERE assets.category IN bucket.categories' ;
230- const query = SqlDataQuery . fromSql ( 'mybucket' , [ 'categories' ] , sql , PARSE_OPTIONS , compatibility ) ;
224+ const query = SqlDataQuery . fromSql ( [ 'categories' ] , sql , PARSE_OPTIONS , compatibility ) ;
231225 expect ( query . errors ) . toMatchObject ( [
232226 { type : 'fatal' , message : 'Cannot use bucket parameters on the right side of IN operators' }
233227 ] ) ;
234228 } ) ;
235229
236230 test ( 'invalid query - not all parameters used' , function ( ) {
237231 const sql = 'SELECT * FROM assets WHERE 1' ;
238- const query = SqlDataQuery . fromSql ( 'mybucket' , [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
232+ const query = SqlDataQuery . fromSql ( [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
239233 expect ( query . errors ) . toMatchObject ( [
240234 { type : 'fatal' , message : 'Query must cover all bucket parameters. Expected: ["bucket.org_id"] Got: []' }
241235 ] ) ;
242236 } ) ;
243237
244238 test ( 'invalid query - parameter not defined' , function ( ) {
245239 const sql = 'SELECT * FROM assets WHERE assets.org_id = bucket.org_id' ;
246- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
240+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
247241 expect ( query . errors ) . toMatchObject ( [
248242 { type : 'fatal' , message : 'Query must cover all bucket parameters. Expected: [] Got: ["bucket.org_id"]' }
249243 ] ) ;
250244 } ) ;
251245
252246 test ( 'invalid query - function on parameter (1)' , function ( ) {
253247 const sql = 'SELECT * FROM assets WHERE assets.org_id = upper(bucket.org_id)' ;
254- const query = SqlDataQuery . fromSql ( 'mybucket' , [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
248+ const query = SqlDataQuery . fromSql ( [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
255249 expect ( query . errors ) . toMatchObject ( [ { type : 'fatal' , message : 'Cannot use bucket parameters in expressions' } ] ) ;
256250 } ) ;
257251
258252 test ( 'invalid query - function on parameter (2)' , function ( ) {
259253 const sql = 'SELECT * FROM assets WHERE assets.org_id = upper(bucket.org_id)' ;
260- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
254+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
261255 expect ( query . errors ) . toMatchObject ( [ { type : 'fatal' , message : 'Cannot use bucket parameters in expressions' } ] ) ;
262256 } ) ;
263257
264258 test ( 'invalid query - match clause in select' , ( ) => {
265259 const sql = 'SELECT id, (bucket.org_id = assets.org_id) as org_matches FROM assets where org_id = bucket.org_id' ;
266- const query = SqlDataQuery . fromSql ( 'mybucket' , [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
260+ const query = SqlDataQuery . fromSql ( [ 'org_id' ] , sql , PARSE_OPTIONS , compatibility ) ;
267261 expect ( query . errors [ 0 ] . message ) . toMatch ( / P a r a m e t e r m a t c h e x p r e s s i o n i s n o t a l l o w e d h e r e / ) ;
268262 } ) ;
269263
270264 test ( 'case-sensitive queries (1)' , ( ) => {
271265 const sql = 'SELECT * FROM Assets' ;
272- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
266+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
273267 expect ( query . errors ) . toMatchObject ( [
274268 { message : `Unquoted identifiers are converted to lower-case. Use "Assets" instead.` }
275269 ] ) ;
276270 } ) ;
277271
278272 test ( 'case-sensitive queries (2)' , ( ) => {
279273 const sql = 'SELECT *, Name FROM assets' ;
280- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
274+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
281275 expect ( query . errors ) . toMatchObject ( [
282276 { message : `Unquoted identifiers are converted to lower-case. Use "Name" instead.` }
283277 ] ) ;
284278 } ) ;
285279
286280 test ( 'case-sensitive queries (3)' , ( ) => {
287281 const sql = 'SELECT * FROM assets WHERE Archived = False' ;
288- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
282+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
289283 expect ( query . errors ) . toMatchObject ( [
290284 { message : `Unquoted identifiers are converted to lower-case. Use "Archived" instead.` }
291285 ] ) ;
@@ -294,7 +288,7 @@ describe('data queries', () => {
294288 test . skip ( 'case-sensitive queries (4)' , ( ) => {
295289 // Cannot validate table alias yet
296290 const sql = 'SELECT * FROM assets as myAssets' ;
297- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
291+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
298292 expect ( query . errors ) . toMatchObject ( [
299293 { message : `Unquoted identifiers are converted to lower-case. Use "myAssets" instead.` }
300294 ] ) ;
@@ -303,7 +297,7 @@ describe('data queries', () => {
303297 test . skip ( 'case-sensitive queries (5)' , ( ) => {
304298 // Cannot validate table alias yet
305299 const sql = 'SELECT * FROM assets myAssets' ;
306- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
300+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
307301 expect ( query . errors ) . toMatchObject ( [
308302 { message : `Unquoted identifiers are converted to lower-case. Use "myAssets" instead.` }
309303 ] ) ;
@@ -312,7 +306,7 @@ describe('data queries', () => {
312306 test . skip ( 'case-sensitive queries (6)' , ( ) => {
313307 // Cannot validate anything with a schema yet
314308 const sql = 'SELECT * FROM public.ASSETS' ;
315- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
309+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
316310 expect ( query . errors ) . toMatchObject ( [
317311 { message : `Unquoted identifiers are converted to lower-case. Use "ASSETS" instead.` }
318312 ] ) ;
@@ -321,7 +315,7 @@ describe('data queries', () => {
321315 test . skip ( 'case-sensitive queries (7)' , ( ) => {
322316 // Cannot validate schema yet
323317 const sql = 'SELECT * FROM PUBLIC.assets' ;
324- const query = SqlDataQuery . fromSql ( 'mybucket' , [ ] , sql , PARSE_OPTIONS , compatibility ) ;
318+ const query = SqlDataQuery . fromSql ( [ ] , sql , PARSE_OPTIONS , compatibility ) ;
325319 expect ( query . errors ) . toMatchObject ( [
326320 { message : `Unquoted identifiers are converted to lower-case. Use "PUBLIC" instead.` }
327321 ] ) ;
0 commit comments