@@ -4,12 +4,15 @@ import { IConnectionDriver, MConnectionExplorer, NSDatabase, ContextValue, Arg0
4
4
import { v4 as generateId } from 'uuid' ;
5
5
import IRISdb , { IRISDirect , IQueries } from './irisdb' ;
6
6
import 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' ) ;
8
9
9
10
type DriverOptions = any ;
11
+
10
12
export default class IRISDriver extends AbstractDriver < IRISdb , DriverOptions > implements IConnectionDriver {
11
13
12
14
queries : IQueries = queries ;
15
+ private showSystem = false ;
13
16
14
17
public async open ( ) {
15
18
if ( this . connection ) {
@@ -18,19 +21,10 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im
18
21
19
22
const { namespace } = this . credentials ;
20
23
let config : IRISDirect ;
24
+ this . showSystem = this . credentials . showSystem || false ;
25
+
21
26
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" ) ;
34
28
} else {
35
29
let { https, server : host , port, pathPrefix, username, password } = this . credentials ;
36
30
config = {
@@ -60,16 +54,13 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im
60
54
}
61
55
62
56
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 ) ;
68
58
}
69
59
70
60
public query : ( typeof AbstractDriver ) [ 'prototype' ] [ 'query' ] = async ( queries , opt = { } ) => {
71
61
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 , [ ] ) ) ) ;
73
64
const resultsAgg : NSDatabase . IResult [ ] = [ ] ;
74
65
queriesResults . forEach ( queryResult => {
75
66
resultsAgg . push ( {
@@ -114,44 +105,58 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im
114
105
case ContextValue . TABLE :
115
106
case ContextValue . VIEW :
116
107
return this . getColumns ( item as NSDatabase . ITable ) ;
108
+ case ContextValue . FUNCTION :
109
+ return [ ] ;
117
110
}
118
111
return [ ] ;
119
112
}
120
113
121
114
private async getSchemas ( { item } : Arg0 < IConnectionDriver [ 'getChildrenForItem' ] > ) {
115
+ item [ 'showSystem' ] = this . showSystem ;
116
+
122
117
switch ( item . childType ) {
123
118
case ContextValue . TABLE :
124
- return this . queryResults ( this . queries . fetchTableSchemas ( ) ) ;
119
+ return this . queryResults ( this . queries . fetchTableSchemas ( item as NSDatabase . IDatabase ) ) ;
125
120
case ContextValue . VIEW :
126
- return this . queryResults ( this . queries . fetchViewSchemas ( ) ) ;
121
+ return this . queryResults ( this . queries . fetchViewSchemas ( item as NSDatabase . IDatabase ) ) ;
127
122
case ContextValue . FUNCTION :
128
- return this . queryResults ( this . queries . fetchFunctionSchemas ( ) ) ;
123
+ return this . queryResults ( this . queries . fetchFunctionSchemas ( item as NSDatabase . IDatabase ) ) ;
129
124
}
130
125
return [ ] ;
131
126
}
132
127
133
128
private async getChildrenForSchema ( { item } : Arg0 < IConnectionDriver [ 'getChildrenForItem' ] > ) {
129
+ item [ 'showSystem' ] = this . showSystem ;
130
+
134
131
switch ( item . childType ) {
135
132
case ContextValue . TABLE :
136
133
return this . queryResults ( this . queries . fetchTables ( item as NSDatabase . ISchema ) ) ;
137
134
case ContextValue . VIEW :
138
135
return this . queryResults ( this . queries . fetchViews ( item as NSDatabase . ISchema ) ) ;
139
136
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
+ } ) ) ;
141
142
}
142
143
return [ ] ;
143
144
}
144
145
145
146
/**
146
147
* This method is a helper for intellisense and quick picks.
147
148
*/
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 [ ] > {
149
150
switch ( itemType ) {
150
151
case ContextValue . TABLE :
152
+ case ContextValue . FUNCTION :
151
153
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
+ } ) ) ;
153
158
case ContextValue . COLUMN :
154
- return [ ] ;
159
+ return this . queryResults ( this . queries . searchColumns ( { search , ... extraParams } ) ) ;
155
160
}
156
161
return [ ] ;
157
162
}
0 commit comments