- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
New Components - nile_database #14223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 3 commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      3788613
              
                wip
              
              
                michelle0927 1119cff
              
                execute-query-action
              
              
                michelle0927 b173730
              
                pnpm-lock.yaml
              
              
                michelle0927 e421de5
              
                execute-query
              
              
                michelle0927 e3e8595
              
                user api components
              
              
                michelle0927 aedfa14
              
                pnpm-lock.yaml
              
              
                michelle0927 5127e5f
              
                remove console.log
              
              
                michelle0927 9fb079c
              
                update execute-query
              
              
                michelle0927 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            28 changes: 28 additions & 0 deletions
          
          28 
        
  components/nile_database/actions/execute-query/execute-query.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import nile from "../../nile_database.app.mjs"; | ||
|  | ||
| export default { | ||
| name: "Execute Query", | ||
| key: "nile_database-execute-query", | ||
| description: "Execute a custom PostgreSQL query. See [our docs](https://pipedream.com/docs/databases/working-with-sql) to learn more about working with SQL in Pipedream.", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| nile, | ||
| // eslint-disable-next-line pipedream/props-description | ||
| sql: { | ||
| type: "sql", | ||
| auth: { | ||
| app: "nile", | ||
| }, | ||
| label: "PostreSQL Query", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const args = this.nile.executeQueryAdapter(this.sql); | ||
| const data = await this.nile.executeQuery(args); | ||
| $.export("$summary", `Returned ${data.length} ${data.length === 1 | ||
| ? "row" | ||
| : "rows"}`); | ||
| return data; | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,11 +1,92 @@ | ||
| import pg from "pg"; | ||
|  | ||
| export default { | ||
| type: "app", | ||
| app: "nile_database", | ||
| propDefinitions: {}, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| getClientConfiguration() { | ||
| const { | ||
| username, | ||
| password, | ||
| host, | ||
| port, | ||
| database, | ||
| } = this.$auth; | ||
|  | ||
| return { | ||
| user: username, | ||
| password, | ||
| host, | ||
| port, | ||
| database, | ||
| }; | ||
| }, | ||
| async _getClient() { | ||
| const config = this.getClientConfiguration(); | ||
| const pool = new pg.Pool(config); | ||
| const client = await pool.connect(); | ||
| return client; | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| async _endClient(client) { | ||
| return client.release(); | ||
| }, | ||
| async executeQuery(query) { | ||
| const client = await this._getClient(); | ||
|  | ||
| try { | ||
| const { rows } = await client.query(query); | ||
| return rows; | ||
| } finally { | ||
| await this._endClient(client); | ||
| } | ||
| }, | ||
| executeQueryAdapter(proxyArgs = {}) { | ||
| const { | ||
| query: text = "", | ||
| params: values = [], | ||
| } = proxyArgs; | ||
| return { | ||
| text, | ||
| values, | ||
| }; | ||
| }, | ||
| proxyAdapter(query) { | ||
| if (typeof query === "string") { | ||
| return { | ||
| query, | ||
| }; | ||
| } | ||
|  | ||
| return { | ||
| query: query.text, | ||
| params: query.values, | ||
| }; | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| async getSchema() { | ||
| const text = ` | ||
| SELECT table_name AS "tableName", | ||
| column_name AS "columnName", | ||
| is_nullable AS "isNullable", | ||
| data_type AS "dataType", | ||
| column_default AS "columnDefault" | ||
| FROM information_schema.columns | ||
| WHERE table_schema NOT IN ('pg_catalog', 'information_schema', 'users', 'auth') | ||
| ORDER BY table_name, | ||
| ordinal_position | ||
| `; | ||
| const rows = await this.executeQuery({ | ||
| text, | ||
| }); | ||
| return rows.reduce((acc, row) => { | ||
| acc[row.tableName] ??= { | ||
| metadata: {}, | ||
| schema: {}, | ||
| }; | ||
| acc[row.tableName].schema[row.columnName] = { | ||
| ...row, | ||
| }; | ||
| return acc; | ||
| }, {}); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/nile_database", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Nile Database Components", | ||
| "main": "nile_database.app.mjs", | ||
| "keywords": [ | ||
|  | @@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "pg": "^8.13.0" | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.