Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions postgress/1.0.0/api.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions postgress/1.0.0/requirements.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions postgress/1.1.0/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
app_version: 1.1.0
name: postgress
description: postgress integration. Compatible with SQL databases.
contact_info:
name: "@d4rkw0lv3s"
url: https://github.com/D4rkw0lv3s
email: d4rkw0lv3s@outlook.pt
tags:
- postgress
- postgresql
categories:
- Intel
- Network
authentication:
required: true
parameters:
- name: host
description: PostgreSQL server IP or FQDN
example: myserver.com or 127.0.0.1
required: true
multiline: false
schema:
type: string
- name: port
description: PostgreSQL database port
example: "5432"
required: false
multiline: false
schema:
type: string
- name: dbname
description: PostgreSQL database name
example: my_database
required: true
multiline: false
schema:
type: string
- name: user
description: PostgreSQL user name
example: my_username
required: true
multiline: false
schema:
type: string
- name: password
description: PostgreSQL user password
example: my_password
required: true
multiline: false
schema:
type: string
actions:
- name: run_query
description: Create a new database
parameters:
- name: query
description: PostgreSQL query
example: SELECT 1
required: true
schema:
type: string
return:
schema:
type: string
2 changes: 2 additions & 0 deletions postgress/1.1.0/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
psycopg2-binary == 2.9.12
shuffle-sdk >= 0.0.31
17 changes: 9 additions & 8 deletions postgress/1.0.0/src/app.py → postgress/1.1.0/src/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import psycopg2
from psycopg2 import connect, ProgrammingError
from psycopg2.extras import RealDictCursor
#from walkoff_app_sdk.app_base import AppBase
from shuffle_sdk import AppBase


class PostgreSQL(AppBase):
__version__ = "1.0.0"
__version__ = "1.1.0"
app_name = "PostgreSQL"

def __init__(self, redis, logger, console_logger=None):
super().__init__(redis, logger, console_logger)

def connect(self, host, port, dbname, user, password):
conn = psycopg2.connect(
@staticmethod
def connect(host, port, dbname, user, password):
conn = connect(
host=host,
port=port,
dbname=dbname,
Expand All @@ -24,12 +24,13 @@ def connect(self, host, port, dbname, user, password):

def run_query(self, host, port, dbname, user, password, query):
with self.connect(host, port, dbname, user, password) as conn:
with conn.cursor() as cur:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute(query)
try:
return {"result": cur.fetchall()}
except psycopg2.ProgrammingError:
return {"result": [dict(row) for row in cur.fetchall() if row]}
except ProgrammingError:
return {"message": "Query executed successfully, no data returned."}


if __name__ == "__main__":
PostgreSQL.run()