@@ -262,6 +262,107 @@ describe('RelAPIMixin', () => {
262262 } ) . timeout ( 60000 ) ;
263263 } ) ;
264264
265+ describe ( '#query with inputs' , ( ) => {
266+ const dbname = createUniqueName ( 'db' ) ;
267+ initializeDatabase ( dbname ) ;
268+
269+ const queryString1 = 'def p2={10} def r=sum[p1*p2]' ;
270+
271+ // Represents `def p = [1,2]`
272+ const inputs1 = [
273+ {
274+ "rel_key" : {
275+ "values" : [ ] ,
276+ "name" : "p1" ,
277+ "keys" : [ "Int64" ] ,
278+ "type" : "RelKey"
279+ } ,
280+ "type" : "Relation" ,
281+ "columns" : [ [ 1 , 2 ] ]
282+ }
283+ ] ;
284+
285+ const NOTEBOOK_RELATION = 'nb' ;
286+ const notebookName = 'myNotebook' ;
287+ const property = 'testProperty' ;
288+ const cellId = 'id_20' ;
289+ const initialValue = 'initial data value' ;
290+ const value = 'test data value' ;
291+ const queryString2 = `
292+ def previousValue = ${ NOTEBOOK_RELATION } [query_notebook_name, :cells, query_cell_id, :${ property } ]
293+ def delete[:${ NOTEBOOK_RELATION } ] = (query_notebook_name, :cells, query_cell_id, :${ property } , previousValue)
294+ def insert[:${ NOTEBOOK_RELATION } ] = (query_notebook_name, :cells, query_cell_id, :${ property } , query_value)
295+ ` ;
296+ const queryString2Init = `def insert[:${ NOTEBOOK_RELATION } ] = ("${ notebookName } ", :cells, "${ cellId } ", :${ property } , "${ initialValue } ")` ;
297+
298+ const inputs2 = [
299+ {
300+ rel_key : {
301+ values : [ "DelveFixedSizeStrings.FixedSizeString{DelveFixedSizeStrings.Str128}" ] ,
302+ name : 'query_cell_id' ,
303+ keys : [ ] ,
304+ type : 'RelKey' ,
305+ } ,
306+ type : 'Relation' ,
307+ columns : [ [ cellId ] ] ,
308+ } ,
309+ {
310+ rel_key : {
311+ values : [ "DelveFixedSizeStrings.FixedSizeString{DelveFixedSizeStrings.Str128}" ] ,
312+ name : 'query_value' ,
313+ keys : [ ] ,
314+ type : 'RelKey' ,
315+ } ,
316+ type : 'Relation' ,
317+ columns : [ [ value ] ] ,
318+ } ,
319+ {
320+ rel_key : {
321+ values : [ "DelveFixedSizeStrings.FixedSizeString{DelveFixedSizeStrings.Str128}" ] ,
322+ name : 'query_notebook_name' ,
323+ keys : [ ] ,
324+ type : 'RelKey' ,
325+ } ,
326+ type : 'Relation' ,
327+ columns : [ [ notebookName ] ] ,
328+ }
329+ ] ;
330+
331+ it ( `should query '${ queryString1 } ' with input relationship 'def p1=[1,2]'` , ( ) => {
332+ return lc . query ( dbname , queryString1 , true , [ 'r' ] , inputs1 ) . then ( res => {
333+ assert . strictEqual ( res . error , null ) ;
334+ assert . strictEqual ( res . result . problems . length , 0 ) ;
335+ assert . strictEqual ( res . result . actions [ 0 ] . result . output [ 0 ] . columns [ 0 ] [ 0 ] , 30 ) ;
336+ } ) ;
337+ } ) . timeout ( 60000 ) ;
338+ it ( `should insert "${ queryString2Init } "` , ( ) => {
339+ return lc . query ( dbname , queryString2Init , false , [ NOTEBOOK_RELATION ] ) . then ( res => {
340+ assert . strictEqual ( res . error , null ) ;
341+ assert . strictEqual ( res . result . problems . length , 0 ) ;
342+ assert . strictEqual ( res . result . actions [ 0 ] . result . output [ 0 ] . columns . length , 3 ) ;
343+ // Ignore issues of order and stringify the JSON array, searching for the
344+ // string values we expect to find within the structure.
345+ const str = JSON . stringify ( res . result . actions [ 0 ] . result . output [ 0 ] . columns ) ;
346+ assert . notStrictEqual ( - 1 , str . indexOf ( notebookName ) ) ;
347+ assert . notStrictEqual ( - 1 , str . indexOf ( cellId ) ) ;
348+ assert . notStrictEqual ( - 1 , str . indexOf ( initialValue ) ) ;
349+ } ) ;
350+ } ) . timeout ( 60000 ) ;
351+ it ( `should query an update query with inputs` , ( ) => {
352+ return lc . query ( dbname , queryString2 , false , [ NOTEBOOK_RELATION ] , inputs2 ) . then ( res => {
353+ assert . strictEqual ( res . error , null ) ;
354+ assert . strictEqual ( res . result . problems . length , 0 ) ;
355+ assert . strictEqual ( res . result . actions [ 0 ] . result . output [ 0 ] . columns . length , 3 ) ;
356+ // Ignore issues of order and stringify the JSON array, searching for the
357+ // string values we expect to find within the structure.
358+ const str = JSON . stringify ( res . result . actions [ 0 ] . result . output [ 0 ] . columns ) ;
359+ assert . notStrictEqual ( - 1 , str . indexOf ( notebookName ) ) ;
360+ assert . notStrictEqual ( - 1 , str . indexOf ( cellId ) ) ;
361+ assert . notStrictEqual ( - 1 , str . indexOf ( value ) ) ;
362+ } ) ;
363+ } ) . timeout ( 60000 ) ;
364+ } ) ;
365+
265366 describe ( '#cardinality' , ( ) => {
266367 const dbname = createUniqueName ( 'db' ) ;
267368 initializeDatabase ( dbname ) ;
0 commit comments