File tree Expand file tree Collapse file tree 2 files changed +40
-21
lines changed Expand file tree Collapse file tree 2 files changed +40
-21
lines changed Original file line number Diff line number Diff line change @@ -8,32 +8,28 @@ export default {
88 type : "action" ,
99 props : {
1010 nile,
11+ workspace : {
12+ propDefinition : [
13+ nile ,
14+ "workspace" ,
15+ ] ,
16+ } ,
17+ database : {
18+ propDefinition : [
19+ nile ,
20+ "database" ,
21+ ] ,
22+ } ,
1123 user : {
1224 type : "string" ,
1325 label : "Username" ,
14- description : "The username of the database user" ,
26+ description : "The username or userId of the database user. Note: Credentials are generated in the Nile Dashboard under Settings -> Credentials " ,
1527 } ,
1628 password : {
1729 type : "string" ,
1830 label : "Password" ,
1931 description : "The password of the database user" ,
2032 } ,
21- host : {
22- type : "string" ,
23- label : "Host" ,
24- description : "The host of the database" ,
25- } ,
26- port : {
27- type : "string" ,
28- label : "Port" ,
29- description : "The port to connect to the database. Example: `5432`" ,
30- } ,
31- database : {
32- propDefinition : [
33- nile ,
34- "database" ,
35- ] ,
36- } ,
3733 query : {
3834 type : "string" ,
3935 label : "Query" ,
@@ -44,8 +40,11 @@ export default {
4440 const config = {
4541 user : this . user ,
4642 password : this . password ,
47- host : this . host ,
48- port : this . port ,
43+ host : await this . nile . getHost ( {
44+ workspace : this . workspace ,
45+ database : this . database ,
46+ } ) ,
47+ port : "5432" ,
4948 database : this . database ,
5049 } ;
5150 const data = await this . nile . executeQuery ( config , this . query ) ;
Original file line number Diff line number Diff line change @@ -31,8 +31,7 @@ export default {
3131 async _getBaseUrl ( {
3232 workspace, database, ...opts
3333 } ) {
34- const { apiHost } = await this . _makeRequest ( {
35- url : `${ this . _globalBaseUrl ( ) } /workspaces/${ workspace } /databases/${ database } ` ,
34+ const { apiHost } = await this . getDatabase ( {
3635 workspace,
3736 database,
3837 ...opts ,
@@ -59,12 +58,33 @@ export default {
5958 ...opts ,
6059 } ) ;
6160 } ,
61+ getDatabase ( {
62+ workspace, database, ...opts
63+ } ) {
64+ return this . _makeRequest ( {
65+ url : `${ this . _globalBaseUrl ( ) } /workspaces/${ workspace } /databases/${ database } ` ,
66+ workspace,
67+ database,
68+ ...opts ,
69+ } ) ;
70+ } ,
6271 getAuthenticatedUser ( opts = { } ) {
6372 return this . _makeRequest ( {
6473 url : `${ this . _globalBaseUrl ( ) } /developers/me/full` ,
6574 ...opts ,
6675 } ) ;
6776 } ,
77+ async getHost ( {
78+ workspace, database, ...opts
79+ } ) {
80+ const { dbHost } = await this . getDatabase ( {
81+ workspace,
82+ database,
83+ ...opts ,
84+ } ) ;
85+ const host = dbHost . match ( / p o s t g r e s : \/ \/ ( [ ^ / ] + ) \/ / ) ;
86+ return host [ 1 ] ;
87+ } ,
6888 listUsers ( {
6989 workspace, database, ...opts
7090 } ) {
You can’t perform that action at this time.
0 commit comments