@@ -4,12 +4,15 @@ import { IConnectionDriver, MConnectionExplorer, NSDatabase, ContextValue, Arg0
44import { v4 as generateId } from 'uuid' ;
55import IRISdb , { IRISDirect , IQueries } from './irisdb' ;
66import keywordsCompletion from './keywords' ;
7- // import { workspace } from "vscode";
7+
8+ const toBool = ( v : any ) => v && ( v . toString ( ) === '1' || v . toString ( ) . toLowerCase ( ) === 'true' || v . toString ( ) . toLowerCase ( ) === 'yes' ) ;
89
910type DriverOptions = any ;
11+
1012export default class IRISDriver extends AbstractDriver < IRISdb , DriverOptions > implements IConnectionDriver {
1113
1214 queries : IQueries = queries ;
15+ private showSystem = false ;
1316
1417 public async open ( ) {
1518 if ( this . connection ) {
@@ -18,19 +21,10 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im
1821
1922 const { namespace } = this . credentials ;
2023 let config : IRISDirect ;
24+ this . showSystem = this . credentials . showSystem || false ;
25+
2126 if ( this . credentials . serverName ) {
22- // const serverName = this.credentials.serverName;
23- // const server = workspace.getConfiguration(`intersystems.servers.${serverName}.webServer`);
24- // let { scheme, host, port, pathPrefix, username, password } = server;
25- // config = {
26- // https: scheme === "https",
27- // host,
28- // port,
29- // pathPrefix,
30- // namespace,
31- // username,
32- // password
33- // };
27+ throw new Error ( "not supported" ) ;
3428 } else {
3529 let { https, server : host , port, pathPrefix, username, password } = this . credentials ;
3630 config = {
@@ -60,16 +54,13 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im
6054 }
6155
6256 private splitQueries ( queries : string ) : string [ ] {
63- if ( ! queries . includes ( ';' ) ) {
64- return [ queries ]
65- }
66-
67- return queries . split ( / ; \s * \n / gm) . filter ( query => query . trim ( ) . length ) ;
57+ return queries . split ( / ; \s * ( \n | $ ) / gm) . filter ( query => query . trim ( ) . length ) ;
6858 }
6959
7060 public query : ( typeof AbstractDriver ) [ 'prototype' ] [ 'query' ] = async ( queries , opt = { } ) => {
7161 const irisdb = await this . open ( ) ;
72- const queriesResults = await Promise . all ( this . splitQueries ( queries . toString ( ) ) . map ( query => irisdb . query ( query , [ ] ) ) ) ;
62+ const listQueries = this . splitQueries ( queries . toString ( ) ) ;
63+ const queriesResults = await Promise . all ( listQueries . map ( query => irisdb . query ( query , [ ] ) ) ) ;
7364 const resultsAgg : NSDatabase . IResult [ ] = [ ] ;
7465 queriesResults . forEach ( queryResult => {
7566 resultsAgg . push ( {
@@ -114,44 +105,58 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im
114105 case ContextValue . TABLE :
115106 case ContextValue . VIEW :
116107 return this . getColumns ( item as NSDatabase . ITable ) ;
108+ case ContextValue . FUNCTION :
109+ return [ ] ;
117110 }
118111 return [ ] ;
119112 }
120113
121114 private async getSchemas ( { item } : Arg0 < IConnectionDriver [ 'getChildrenForItem' ] > ) {
115+ item [ 'showSystem' ] = this . showSystem ;
116+
122117 switch ( item . childType ) {
123118 case ContextValue . TABLE :
124- return this . queryResults ( this . queries . fetchTableSchemas ( ) ) ;
119+ return this . queryResults ( this . queries . fetchTableSchemas ( item as NSDatabase . IDatabase ) ) ;
125120 case ContextValue . VIEW :
126- return this . queryResults ( this . queries . fetchViewSchemas ( ) ) ;
121+ return this . queryResults ( this . queries . fetchViewSchemas ( item as NSDatabase . IDatabase ) ) ;
127122 case ContextValue . FUNCTION :
128- return this . queryResults ( this . queries . fetchFunctionSchemas ( ) ) ;
123+ return this . queryResults ( this . queries . fetchFunctionSchemas ( item as NSDatabase . IDatabase ) ) ;
129124 }
130125 return [ ] ;
131126 }
132127
133128 private async getChildrenForSchema ( { item } : Arg0 < IConnectionDriver [ 'getChildrenForItem' ] > ) {
129+ item [ 'showSystem' ] = this . showSystem ;
130+
134131 switch ( item . childType ) {
135132 case ContextValue . TABLE :
136133 return this . queryResults ( this . queries . fetchTables ( item as NSDatabase . ISchema ) ) ;
137134 case ContextValue . VIEW :
138135 return this . queryResults ( this . queries . fetchViews ( item as NSDatabase . ISchema ) ) ;
139136 case ContextValue . FUNCTION :
140- return this . queryResults ( this . queries . fetchFunctions ( item as NSDatabase . ISchema ) ) ;
137+ return this . queryResults ( this . queries . fetchFunctions ( item as NSDatabase . ISchema ) ) . then ( r => r . map ( t => {
138+ t . childType = ContextValue . NO_CHILD ;
139+ t [ "snippet" ] = "Testing" ;
140+ return t ;
141+ } ) ) ;
141142 }
142143 return [ ] ;
143144 }
144145
145146 /**
146147 * This method is a helper for intellisense and quick picks.
147148 */
148- public async searchItems ( itemType : ContextValue , _search : string , _extraParams : any = { } ) : Promise < NSDatabase . SearchableItem [ ] > {
149+ public async searchItems ( itemType : ContextValue , search : string , extraParams : any = { } ) : Promise < NSDatabase . SearchableItem [ ] > {
149150 switch ( itemType ) {
150151 case ContextValue . TABLE :
152+ case ContextValue . FUNCTION :
151153 case ContextValue . VIEW :
152- return [ ]
154+ return this . queryResults ( this . queries . searchEverything ( { search, showSystem : this . showSystem } ) ) . then ( r => r . map ( t => {
155+ t . isView = toBool ( t . isView ) ;
156+ return t ;
157+ } ) ) ;
153158 case ContextValue . COLUMN :
154- return [ ] ;
159+ return this . queryResults ( this . queries . searchColumns ( { search , ... extraParams } ) ) ;
155160 }
156161 return [ ] ;
157162 }
0 commit comments