{
  "servicename": "pgsqlstore",
  "routes": [
    {
      "route": "/databases",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetDatabases",
      "description": "Get databases at this postgresSQL server",
      "examples": [
        {
          "param": "/databases"
        }
      ]
    },
    {
      "route": "/databases",
      "configured": true,
      "type": "post",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "CreateDatabase",
      "description": "Crete a named database",
      "bodyschema": {
        "required": [
          "name"
        ],
        "type": "object",
        "properties": {
          "name": {
            "description": "name of the database to create",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases",
          "payload": {
            "name": "test"
          }
        }
      ]
    },
    {
      "route": "/databases/:name",
      "configured": true,
      "type": "delete",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "DeleteDatabase",
      "description": "Delete named database",
      "paramschema": {
        "required": [
          "name"
        ],
        "type": "object",
        "properties": {
          "name": {
            "description": "name of the database to delete",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test"
        }
      ]
    },
    {
      "route": "/databases/user",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetUser",
      "description": "GetCurrentUser",
      "examples": [
        {
          "param": "/databases/user"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetSchemas",
      "description": "Get schemas in a database",
      "examples": [
        {
          "param": "/databases/test/schemas"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas",
      "configured": true,
      "type": "post",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "CreateSchema",
      "description": "Create Schema with the schema",
      "paramschema": {
        "required": [
          "database"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "type": "object",
        "properties": {
          "required": [
            "table"
          ],
          "schema": {
            "description": "schema name",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas",
          "payload": {
            "schema": "schema1"
          }
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema",
      "configured": true,
      "type": "delete",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "DeleteSchemasSchema",
      "description": "Delete a schema",
      "paramschema": {
        "required": [
          "database",
          "schema"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetTables",
      "description": "Get all coumns and all rows in a table",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "schema"
        ],
        "properties": {
          "database": {
            "type": "string",
            "description": "database name"
          },
          "schema": {
            "type": "string",
            "description": "schema name"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables",
      "configured": true,
      "type": "post",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "CreateTable",
      "description": "Create Table with the schema",
      "paramschema": {
        "required": [
          "database",
          "schema"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "type": "object",
        "properties": {
          "required": [
            "table"
          ],
          "table": {
            "description": "table name",
            "type": "string"
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "column",
                "ctype"
              ],
              "properties": {
                "column": {
                  "type": "string",
                  "description": "column name"
                },
                "ctype": {
                  "type": "string",
                  "description": "column data type"
                },
                "special": {
                  "type": "string",
                  "description": "optional special strings like null, not null etc. this will append after column name and type are passed to create table"
                },
                "index": {
                  "type": {
                    "enum": [
                      "asc",
                      "desc"
                    ]
                  },
                  "description": "there will be an index created for this column. It can be ascendiing or descending. For postgresSQL server it's always ascending.'"
                },
                "primarykey": {
                  "type": "boolean",
                  "description": "If present this column will be primary key"
                },
                "identity": {
                  "type": "boolean",
                  "description": "if present, this column will represent auto_increment column"
                },
                "foreignkey": {
                  "type": "object",
                  "required": [
                    "table"
                  ],
                  "table": {
                    "type": "string",
                    "description": "the table name the foreign key references"
                  },
                  "column": {
                    "type": "string",
                    "description": "the table column (optional) the foreign key references"
                  }
                }
              }
            }
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables",
          "payload": {
            "table": "employees",
            "columns": [
              {
                "column": "emp_id",
                "ctype": "INT",
                "primarykey": true,
                "identity": true,
                "special": "NOT NULL"
              },
              {
                "column": "first_name",
                "ctype": "VARCHAR(255)",
                "special": "NOT NULL"
              },
              {
                "column": "last_name",
                "ctype": "VARCHAR(255)",
                "special": "NOT NULL"
              }
            ]
          }
        },
        {
          "param": "/databases/test/schemas/schema1/tables",
          "payload": {
            "table": "salaries",
            "columns": [
              {
                "column": "emp",
                "ctype": "INT",
                "foreignkey": {
                  "table": "employees",
                  "column": "emp_id"
                }
              },
              {
                "column": "salary",
                "ctype": "INT",
                "special": "NOT NULL"
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables/:table",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetTableSchema",
      "description": "Get schema for a table",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees"
        },
        {
          "param": "/databases/test/schemas/schema1/tables/salaries"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/schema/tables/:table",
      "configured": true,
      "type": "put",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "AlterTable",
      "description": "Add Columns to the table schema",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "type": "object",
        "properties": {
          "required": [
            "columns"
          ],
          "columns": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "column",
                "ctype"
              ],
              "properties": {
                "column": {
                  "type": "string",
                  "description": "column name"
                },
                "ctype": {
                  "type": "string",
                  "description": "column data type"
                },
                "special": {
                  "type": "string",
                  "description": "optional special strings like null, not null etc. this will append after column name and type are passed to create table"
                },
                "index": {
                  "type": {
                    "enum": [
                      "asc",
                      "desc"
                    ]
                  },
                  "description": "there will be an index created for this column. It can be ascendiing or descending. For postgresSQL server it's always ascending.'"
                },
                "primarykey": {
                  "type": "boolean",
                  "description": "If present this column will be primary key"
                },
                "identity": {
                  "type": "boolean",
                  "description": "if present, this column will represent auto_increment column"
                },
                "foreignkey": {
                  "type": "object",
                  "required": [
                    "table"
                  ],
                  "table": {
                    "type": "string",
                    "description": "the table name the foreign key references"
                  },
                  "column": {
                    "type": "string",
                    "description": "the table column (optional) the foreign key references"
                  }
                }
              }
            }
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees",
          "payload": {
            "columns": [
              {
                "column": "age",
                "ctype": "INT"
              },
              {
                "column": "address",
                "ctype": "VARCHAR(255)"
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables/:table",
      "configured": true,
      "type": "delete",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "DeleteTableAndSchema",
      "description": "This can only try and delete the table and the associated schema. If there are constraints it will fail.",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees"
        },
        {
          "param": "/databases/test/schemas/schema1/salaries"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables/:table/rows",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetTableRows",
      "description": "Get all coumns and all rows in a table",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          },
          "stream": {
            "description": "stream the data instead of sending it",
            "type": "boolean"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rows"
        },
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rows?stream"
        },
        {
          "param": "/databases/test/schemas/schema1/tables/salaries/rows"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables/:table/rows",
      "configured": true,
      "type": "post",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "InsertRecord",
      "description": "insert a record into a table",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "type": "object",
        "oneOf": [
          {
            "required": [
              "columns"
            ]
          },
          {
            "required": [
              "loaddata"
            ]
          },
          {
            "required": [
              "filename"
            ]
          }
        ],
        "properties": {
          "filename": {
            "type": "string",
            "description": "csv file to load the data from into the table (note the data has to be local to the connector"
          },
          "loaddata": {
            "type": "string",
            "description": "csv data load the data from into the table."
          },
          "header": {
            "type": "boolean",
            "description": "set to true if csv data contains the column headers in row 1"
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "column",
                "value"
              ],
              "properties": {
                "column": {
                  "type": "string",
                  "description": "column name"
                },
                "value": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "integer"
                    },
                    {
                      "type": "number"
                    }
                  ],
                  "description": "column value"
                }
              }
            }
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rows",
          "payload": {
            "columns": [
              {
                "column": "first_name",
                "value": "John"
              },
              {
                "column": "last_name",
                "value": "Doe"
              }
            ]
          }
        },
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rows",
          "payload": {
            "loaddata": "3,'david','blum'\n4,'jane','dar'\n5,'darin','hatake'\n6,'lauren','gyro'\n7,'lina','carr'\n"
          }
        },
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rows",
          "payload": {
            "loaddata": "'emp_id','first_name', 'last_name'\n3,'david','blum'\n4,'jane','dar'\n5,'darin','hatake'\n6,'lauren','gyro'\n7,'lina','carr'\n",
            "header": true
          }
        },
        {
          "param": "/databases/test/schemas/schema1/tables/salaries/rows",
          "payload": {
            "columns": [
              {
                "column": "emp",
                "value": 1
              },
              {
                "column": "salary",
                "value": 100000
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables/:table/rows/:limit",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetTableRowsLimit",
      "description": "Get all coumns and all rows in a table upto limit (kept for backward compatibiity) use the /rows/limits... route instead",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table",
          "limit"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          },
          "limit": {
            "description": "limit",
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rows/100"
        },
        {
          "param": "/databases/test/schemas/schema1/tables/salaries/rows/100"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables/:table/rows/limits/:offset/:limit/:orderby",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetTableRowsLimit",
      "description": "Get all coumns and all rows in a table from offset to limit. Offset starts with 1 not 0. limit is the count of rows to fetch from offset.",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table",
          "offset",
          "limit",
          "orderby"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          },
          "offset": {
            "description": "offset",
            "type": "integer",
            "minimum": 1
          },
          "limit": {
            "description": "limit",
            "type": "integer",
            "minimum": 1
          },
          "orderby": {
            "description": "column name to order by",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rows/limits/1/100/emp_id"
        },
        {
          "param": "/databases/test/schemas/schema1/tables/salaries/rows/limits/1/100/emp"
        }
      ]
    },
    {
      "route": "/databases/{database}/schemas/:schema/tables/{table}/rowcount",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetTableRowCount",
      "description": "Get the row count for the table",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rowcount"
        },
        {
          "param": "/databases/test/schemas/schema1/tables/salaries/rowcount"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables/:table/rows/:field/:value",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetTableRowsRow",
      "description": "Get all rows in a table that have the field equal to value",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table",
          "field",
          "value"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          },
          "field": {
            "description": "column name",
            "type": "string"
          },
          "value": {
            "description": "value for the column can be any value"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rows/emp_id/1"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/tables/:table/rows/:field/:value",
      "configured": true,
      "type": "delete",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "DeleteTableRowsRow",
      "description": "Delete all rows in a table where field equal to value",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "table",
          "field",
          "value"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          },
          "field": {
            "description": "column name",
            "type": "string"
          },
          "value": {
            "description": "value for the column can be any value"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/tables/employees/rows/emp_id/1"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/functions",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetFunctions",
      "description": "List all the Functions in the database",
      "paramschema": {
        "required": [
          "database",
          "schema"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/functions"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/functions",
      "configured": true,
      "type": "post",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "CreateFunction",
      "description": "Create a function in the database",
      "paramschema": {
        "required": [
          "database",
          "schema"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "required": [
          "name",
          "body"
        ],
        "type": "object",
        "properties": {
          "required": [
            "name"
          ],
          "name": {
            "type": "string",
            "minLength": 1,
            "description": "name of the function"
          },
          "body": {
            "type": "string",
            "minLength": 1
          },
          "params": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "mode",
                "type"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "description": "parameter name"
                },
                "mode": {
                  "type": {
                    "enum": [
                      "in",
                      "out",
                      "inout"
                    ]
                  },
                  "description": "specify if in, out or inout variable"
                },
                "type": {
                  "type": "string",
                  "minLength": 1,
                  "description": "sql compatible datatypes"
                }
              }
            }
          },
          "returns": {
            "type": "string",
            "description": "can be table with comma delimited variables or varilables"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/functions",
          "payload": {
            "name": "sumprodfunc",
            "params": [
              {
                "name": "x",
                "mode": "in",
                "type": "decimal(5,2)"
              },
              {
                "name": "y",
                "mode": "in",
                "type": "decimal(5,2)"
              },
              {
                "name": "sum",
                "mode": "out",
                "type": "decimal(5,2)"
              },
              {
                "name": "prod",
                "mode": "out",
                "type": "decimal(5,2)"
              }
            ],
            "body": "SELECT x+y,x*y;"
          }
        },
        {
          "param": "/databases/test/schemas/schema1/functions",
          "payload": {
            "name": "sumfunc",
            "params": [
              {
                "name": "x",
                "mode": "in",
                "type": "decimal(5,2)"
              },
              {
                "name": "y",
                "mode": "in",
                "type": "decimal(5,2)"
              }
            ],
            "body": "SELECT x+y",
            "returns": "decimal(5,2)"
          }
        },
        {
          "param": "/databases/test/schemas/schema1/functions",
          "payload": {
            "name": "sel",
            "params": [
              {
                "name": "x",
                "mode": "in",
                "type": "decimal(5,2)"
              },
              {
                "name": "y",
                "mode": "in",
                "type": "decimal(5,2)"
              }
            ],
            "body": "SELECT * from schema1.employees",
            "returns": "schema1.employees"
          }
        }

      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/functions/:name",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetFunctionDetails",
      "description": "Get storedprocedure details in the database with the name",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "name"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string",
            "minLength": 1
          },
          "schema": {
            "description": "name of the schema",
            "type": "string",
            "minLength": 1
          },
          "name": {
            "description": "name of the function",
            "type": "string",
            "minLength": 1
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/functions/sumprodfunc"
        },
        {
          "param": "/databases/test/schemas/schema1/functions/sumfunc"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/functions/:name",
      "configured": true,
      "type": "delete",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "DeleteFunction",
      "description": "Delete storedprocedure in the database with the name",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "name"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string",
            "minLength": 1
          },
          "schema": {
            "description": "name of the schema",
            "type": "string",
            "minLength": 1
          },
          "name": {
            "description": "name of the function",
            "type": "string",
            "minLength": 1
          },
          "parameters" : {
            "description": "optional parameter types passed as query paramters. Postgresql supports overloading functions and storeprocs. These are necessary if the functiosn are overloaded to distinguish.",
            "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "array",
                  "items": {
                    "type": "string"                    
                  }
                }
              ]
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/functions/sumprodfunc?parameters=int&parameters=int"
        },
        {
          "param": "/databases/test/schemas/schema1/functions/sumfunc"
        },
        {
          "param": "/databases/test/schemas/schema1/functions/testsp?parameters=int"
        },
        {
          "param": "/databases/test/schemas/schema1/functions/testsp"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/functions/:name",
      "configured": true,
      "type": "put",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "ExecFunction",
      "description": "Execute function in the database with the name",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "name"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string",
            "minLength": 1
          },
          "schema": {
            "description": "name of the schema",
            "type": "string",
            "minLength": 1
          },
          "name": {
            "description": "name of the stored procedure",
            "type": "string",
            "minLength": 1
          }
        }
      },
      "bodyschema": {
        "required": [
          "params"
        ],
        "type": "object",
        "properties": {
          "prestatements": {
            "type": "string",
            "minLength": 0
          },
          "poststatements": {
            "type": "string",
            "minLength": 0
          },
          "params": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "mode"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "description": "parameter name if mode is in, out, or inout and value if mode is lieteral"
                },
                "value": {
                  "type": "string",
                  "description": "parameter value only used if mode is in or inout"
                },
                "type": {
                  "type": "string",
                  "description": "parameter type if not present assumes integer"
                },
                "mode": {
                  "type": {
                    "enum": [
                      "in",
                      "out",
                      "inout",
                      "literal"
                    ]
                  },
                  "description": "parameter mode which is in, out, inout, or literal"
                }
              }
            }
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/functions/sumprodfunc",
          "payload": {
            "prestatements": "",
            "poststatements": "",
            "params": [
              {
                "name": "x",
                "mode": "in",
                "type": "decimal(5,2)",
                "value": "10.025"
              },
              {
                "name": "y",
                "type": "decimal(5, 2)",
                "mode": "in",
                "value": "5.2"
              }
            ]
          }
        },
        {
          "param": "/databases/test/schemas/schema1/functions/sumprodfunc",
          "payload": {
            "prestatements": "select * from schema1.employees;",
            "poststatements": "select schema1.sumprodfunc(10,2);",
            "params": [
              {
                "name": "x",
                "mode": "in",
                "type": "decimal(5,2)",
                "value": "6"
              },
              {
                "name": "y",
                "type": "decimal(5,2)",
                "mode": "in",
                "value": "7"
              }
            ]
          }
        },
        {
          "param": "/databases/test/schemas/schema1/functions/sumfunc",
          "payload": {
            "prestatements": "",
            "poststatements": "",
            "params": [
              {
                "name": "x",
                "mode": "in",
                "type": "decimal(5,2)",
                "value": "10.025"
              },
              {
                "name": "y",
                "type": "decimal(5, 2)",
                "mode": "in",
                "value": "5.2"
              }
            ]
          }
        },
        {
          "param": "/databases/test/schemas/schema1/functions/sumfunc",
          "payload": {
            "prestatements": "select * from schema1.employees;",
            "poststatements": "select schema1.sumfunc(10,2);",
            "params": [
              {
                "name": "x",
                "mode": "in",
                "type": "decimal(5,2)",
                "value": "6"
              },
              {
                "name": "y",
                "type": "decimal(5,2)",
                "mode": "in",
                "value": "7"
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/storedprocs",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetSPs",
      "description": "List all the stored procedure in the database",
      "paramschema": {
        "required": [
          "database",
          "schema"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/storedprocs"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/storedprocs",
      "configured": true,
      "type": "post",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "CreateSP",
      "description": "Create a storedproc in the database",
      "paramschema": {
        "required": [
          "database",
          "schema"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "schema": {
            "description": "name of the schema",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "required": [
          "name",
          "body"
        ],
        "type": "object",
        "properties": {
          "required": [
            "name"
          ],
          "name": {
            "type": "string",
            "minLength": 1,
            "description": "name of the function"
          },
          "body": {
            "type": "string",
            "minLength": 1
          },
          "params": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "mode",
                "type"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "description": "parameter name"
                },
                "mode": {
                  "type": {
                    "enum": [
                      "in",
                      "out",
                      "inout"
                    ]
                  },
                  "description": "specify if in, out or inout variable"
                },
                "type": {
                  "type": "string",
                  "minLength": 1,
                  "description": "sql compatible datatypes"
                }
              }
            }
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/storedprocs",
          "payload": {
            "name": "AddEmployee",
            "params": [
              {
                "name": "firstname",
                "mode": "in",
                "type": "varchar(255)"
              },
              {
                "name": "lastname",
                "mode": "in",
                "type": "varchar(255)"
              }
            ],
            "body": "insert into schema1.employees values(default, firstname, lastname); select * from schema1.employees where emp_id > 1"
          }
        },
        {
          "param": "/databases/test/schemas/schema1/storedprocs",
          "payload": {
            "name": "DeleteEmployee",
            "params": [
              {
                "name": "id",
                "mode": "in",
                "type": "INT"
              }
            ],
            "body": "delete from schema1.employees where emp_id = id;"
          }
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/storedprocs/:name",
      "configured": true,
      "type": "get",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GetSPDetails",
      "description": "Get storedprocedure details in the database with the name",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "name"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string",
            "minLength": 1
          },
          "schema": {
            "description": "name of the schema",
            "type": "string",
            "minLength": 1
          },
          "name": {
            "description": "name of the stored procedure",
            "type": "string",
            "minLength": 1
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema/storedprocs/AddEmployee"
        },
        {
          "param": "/databases/test/schemas/schema/storedprocs/DeleteEmployee"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/storedprocs/:name",
      "configured": true,
      "type": "delete",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "DeleteSP",
      "description": "Delete storedprocedure in the database with the name",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "name"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string",
            "minLength": 1
          },
          "schema": {
            "description": "name of the schema",
            "type": "string",
            "minLength": 1
          },
          "name": {
            "description": "name of the stored procedure",
            "type": "string",
            "minLength": 1
          },
          "parameters" : {
            "description": "optional parameter types passed as query paramters. Postgresql supports overloading functions and storeprocs. These are necessary if the functiosn are overloaded to distinguish.",
            "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "array",
                  "items": {
                    "type": "string"                    
                  }
                }
              ]
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/storedprocs/AddEmployee"
        },
        {
          "param": "/databases/test/schemas/schema1/storedprocs/DeleteEmployee"
        }
      ]
    },
    {
      "route": "/databases/:database/schemas/:schema/storedprocs/:name",
      "configured": true,
      "type": "put",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "ExecSP",
      "description": "Execute storedprocedure in the database with the name",
      "paramschema": {
        "required": [
          "database",
          "schema",
          "name"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string",
            "minLength": 1
          },
          "name": {
            "description": "name of the stored procedure",
            "type": "string",
            "minLength": 1
          }
        }
      },
      "bodyschema": {
        "required": [
          "params"
        ],
        "type": "object",
        "properties": {
          "prestatements": {
            "type": "string",
            "minLength": 0
          },
          "poststatements": {
            "type": "string",
            "minLength": 0
          },
          "params": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "mode"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "description": "parameter name if mode is in, out, or inout and value if mode is lieteral"
                },
                "value": {
                  "type": "string",
                  "description": "parameter value only used if mode is in or inout"
                },
                "mode": {
                  "type": {
                    "enum": [
                      "in",
                      "out",
                      "inout"
                    ]
                  },
                  "description": "parameter mode which is in, out, inout, or literal"
                }
              }
            }
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/schemas/schema1/storedprocs/AddEmployee",
          "payload": {
            "prestatements": "",
            "poststatements": "select * from schema1.employees;",
            "params": [
              {
                "name": "firstname",
                "mode": "in",
                "value": "Vinay"
              },
              {
                "name": "lastname",
                "mode": "in",
                "value": "David"
              }
            ]
          }
        },
        {
          "param": "/databases/test/schemas/schema1/storedprocs/DeleteEmployee",
          "payload": {
            "prestatements": "",
            "poststatements": "select * from schema1.employees;",
            "params": [
              {
                "name": "id",
                "mode": "in",
                "value": "2"
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/databases/:database/execstatements",
      "configured": true,
      "type": "post",
      "routeclass": "./pgsqlstore.js",
      "routefunction": "GeneralQuery",
      "description": "Execute statements given as a strig with ; as delimeter",
      "paramschema": {
        "required": [
          "database"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string",
            "minLength": 1
          }
        }
      },
      "bodyschema": {
        "required": [
          "statements"
        ],
        "type": "object",
        "properties": {
          "statements": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/execstatements",
          "payload": {
            "statements": "select * from schema1.employees where emp_id=1"
          }
        },
        {
          "param": "/databases/retail/execstatements",
          "payload": {
            "statements": "select * from schema1.salaries limit 10"
          }
        }
      ]
    }
  ],
  "loglevel": "trace"
}