{
  "servicename": "relstore",
  "routes": [
    {
      "route": "/databases",
      "configured": true,
      "type": "get",
      "routeclass": "./relstore.js",
      "routefunction": "GetDatabases",
      "description": "Get databases at this mysql server",
      "examples": [
        {
          "param": "/databases"
        }
      ]
    },
    {
      "route": "/databases",
      "configured": true,
      "type": "post",
      "routeclass": "./relstore.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": "./relstore.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": "./relstore.js",
      "routefunction": "GetUser",
      "description": "GetCurrentUser",
      "examples": [
        {
          "param": "/databases/user"
        }
      ]
    },
    {
      "route": "/connections",
      "configured": false,
      "type": "post",
      "routeclass": "./relstore.js",
      "routefunction": "NewConnection",
      "description": "Establish a new connection",
      "bodyschema": {
        "required": [
          "host",
          "user",
          "password"
        ],
        "type": "object",
        "properties": {
          "limit": {
            "description": "number of connections in the pool",
            "type": "integer",
            "minimum": 1
          },
          "user": {
            "description": "task name (applies only for nudge)",
            "type": "string"
          },
          "password": {
            "description": "password",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/connections",
          "payload": {
            "host": "host",
            "user": "user",
            "password": "password",
            "limit": 2
          }
        }
      ]
    },
    {
      "route": "/databases/:database/tables",
      "configured": true,
      "type": "get",
      "routeclass": "./relstore.js",
      "routefunction": "GetTables",
      "description": "Get all coumns and all rows in a table",
      "examples": [
        {
          "param": "/databases/test/tables"
        },
        {
          "param": "/databases/retail/tables"
        }
      ]
    },
    {
      "route": "/databases/:database/tables",
      "configured": true,
      "type": "post",
      "routeclass": "./relstore.js",
      "routefunction": "CreateTable",
      "description": "Create Table with the schema",
      "paramschema": {
        "required": [
          "database"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "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 MySQL 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/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/tables",
          "payload": {
            "table": "salaries",
            "columns": [
              {
                "column": "emp",
                "ctype": "INT",
                "foreignkey": {
                  "table": "employees",
                  "column": "emp_id"
                }
              },
              {
                "column": "salary",
                "ctype": "int(11)",
                "special": "NOT NULL"
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/databases/:database/tables/:table",
      "configured": true,
      "type": "get",
      "routeclass": "./relstore.js",
      "routefunction": "GetTableSchema",
      "description": "Get schema for a table",
      "paramschema": {
        "required": [
          "database",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/tables/employees"
        },
        {
          "param": "/databases/retail/tables/sales"
        }
      ]
    },
    {
      "route": "/databases/:database/tables/:table",
      "configured": true,
      "type": "put",
      "routeclass": "./relstore.js",
      "routefunction": "AlterTable",
      "description": "Add Columns to the table schema",
      "paramschema": {
        "required": [
          "database",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "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 MySQL 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/tables/employees",
          "payload": {
            "columns": [
              {
                "column": "age",
                "ctype": "INT"
              },
              {
                "column": "address",
                "ctype": "VARCHAR(255)"
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/databases/:database/tables/:table",
      "configured": true,
      "type": "delete",
      "routeclass": "./relstore.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",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/tables/employees"
        },
        {
          "param": "/databases/retail/tables/sales"
        }
      ]
    },
    {
      "route": "/databases/:database/tables/:table/rows",
      "configured": true,
      "type": "get",
      "routeclass": "./relstore.js",
      "routefunction": "GetTableRows",
      "description": "Get all coumns and all rows in a table",
      "paramschema": {
        "required": [
          "database",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "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/tables/employees/rows"
        },
        {
          "param": "/databases/test/tables/employees/rows?stream"
        },
        {
          "param": "/databases/retail/tables/sales/rows"
        },
        {
          "param": "/databases/retail/tables/features/rows"
        },
        {
          "param": "/databases/retail/tables/stores/rows"
        }
      ]
    },
    {
      "route": "/databases/:database/tables/:table/rows",
      "configured": true,
      "type": "post",
      "routeclass": "./relstore.js",
      "routefunction": "InsertRecord",
      "description": "insert a record into a table",
      "paramschema": {
        "required": [
          "database",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "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/tables/employees/rows",
          "payload": {
            "columns": [
              {
                "column": "first_name",
                "value": "John"
              },
              {
                "column": "last_name",
                "value": "Doe"
              }
            ]
          }
        },
        {
          "param": "/databases/test/tables/employees/rows",
          "payload": {
            "loaddata": "3,'david','blum'\n4,'jane','dar'\n5,'darin','hatake'\n6,'lauren','gyro'\n7,'lina','carr'\n"
          }
        },
        {
          "param": "/databases/test/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/tables/salaries/rows",
          "payload": {
            "columns": [
              {
                "column": "emp",
                "value": 1
              },
              {
                "column": "salary",
                "value": 100000
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/databases/:database/tables/:table/rows/limits/:offset/:limit/:orderby",
      "configured": true,
      "type": "get",
      "routeclass": "./relstore.js",
      "routefunction": "GetTableRowsLimit",
      "description": "Get all coumns and all rows in a table upto limit",
      "paramschema": {
        "required": [
          "database",
          "table",
          "offset",
          "limit",
          "orderby"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "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/tables/employees/rows/limits/1/100/emp_id"
        },
        {
          "param": "/databases/retail/tables/sales/rows/limits/1/100"
        },
        {
          "param": "/databases/retail/tables/features/rows/limits/1/10"
        },
        {
          "param": "/databases/retail/tables/stores/rows/limits/1/20"
        }
      ]
    },
    {
      "route": "/databases/{database}/tables/{table}/rowcount",
      "configured": true,
      "type": "get",
      "routeclass": "./relstore.js",
      "routefunction": "GetTableRowCount",
      "description": "Get the row count for the table",
      "paramschema": {
        "required": [
          "database",
          "table"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "table": {
            "description": "name of the table",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/tables/employees/rowcount"
        },
        {
          "param": "/databases/retail/tables/sales/rowcount"
        },
        {
          "param": "/databases/retail/tables/features/rowcount"
        },
        {
          "param": "/databases/retail/tables/stores/rowcount"
        }
      ]
    },
    {
      "route": "/databases/:database/tables/:table/rows/:field/:value",
      "configured": true,
      "type": "get",
      "routeclass": "./relstore.js",
      "routefunction": "GetTableRowsRow",
      "description": "Get all coumns and all rows in a table",
      "paramschema": {
        "required": [
          "database",
          "table",
          "field",
          "value"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "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/tables/employees/rows/emp_id/1"
        }
      ]
    },
    {
      "route": "/databases/:database/tables/:table/rows/:field/:value",
      "configured": true,
      "type": "delete",
      "routeclass": "./relstore.js",
      "routefunction": "DeleteTableRowsRow",
      "description": "Get all coumns and all rows in a table",
      "paramschema": {
        "required": [
          "database",
          "table",
          "field",
          "value"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "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/tables/employees/rows/emp_id/1"
        }
      ]
    },
    {
      "route": "/databases/:database/storedprocs",
      "configured": true,
      "type": "get",
      "routeclass": "./relstore.js",
      "routefunction": "GetSPs",
      "description": "List all the stored procedure in the database",
      "paramschema": {
        "required": [
          "database"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/storedprocs"
        }
      ]
    },
    {
      "route": "/databases/:database/storedprocs",
      "configured": true,
      "type": "post",
      "routeclass": "./relstore.js",
      "routefunction": "CreateSP",
      "description": "Create a stored procedure in the database",
      "paramschema": {
        "required": [
          "database"
        ],
        "type": "object",
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "required": [
          "name",
          "body"
        ],
        "type": "object",
        "properties": {
          "required": [
            "name"
          ],
          "name": {
            "type": "string",
            "minLength": 1
          },
          "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": "column value"
                },
                "type": {
                  "type": "string",
                  "minLength": 1,
                  "description": "sql compatible datatypes"
                }
              }
            }
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/storedprocs",
          "payload": {
            "name": "AddEmployee",
            "params": [
              {
                "name": "fn",
                "mode": "in",
                "type": "varchar(255)"
              },
              {
                "name": "ln",
                "mode": "in",
                "type": "varchar(255)"
              }
            ],
            "body": "insert into employees (first_name, last_name) values(fn, ln); select * from employees where emp_id > 1;"
          }
        },
        {
          "param": "/databases/test/storedprocs",
          "payload": {
            "name": "DeleteEmployee",
            "params": [
              {
                "name": "id",
                "mode": "in",
                "type": "INT"
              }
            ],
            "body": "delete from employees where emp_id = id;"
          }
        },
        {
          "param": "/databases/test/storedprocs",
          "payload": {
            "name": "testsp",
            "params": [
              {
                "name": "param1",
                "mode": "in",
                "type": "decimal(5,2)"
              },
              {
                "name": "param2",
                "mode": "out",
                "type": "decimal(5,2)"
              }
            ],
            "body": "SELECT * from employees; SET param2 = param1 + 20;"
          }
        }
      ]
    },
    {
      "route": "/databases/:database/storedprocs/:name",
      "configured": true,
      "type": "get",
      "routeclass": "./relstore.js",
      "routefunction": "GetSPDetails",
      "description": "Get storedprocedure details in the database with the name",
      "paramschema": {
        "required": [
          "database",
          "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
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/storedprocs/AddEmployee"
        },
        {
          "param": "/databases/test/storedprocs/DeleteEmployee"
        },
        {
          "param": "/databases/test/storedprocs/testsp"
        }
      ]
    },
    {
      "route": "/databases/:database/storedprocs/:name",
      "configured": true,
      "type": "delete",
      "routeclass": "./relstore.js",
      "routefunction": "DeleteSP",
      "description": "Delete storedprocedure in the database with the name",
      "paramschema": {
        "required": [
          "database",
          "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
          }
        }
      },
      "examples": [
        {
          "param": "/databases/test/storedprocs/AddEmployee"
        },
        {
          "param": "/databases/test/storedprocs/DeleteEmployee"
        },
        {
          "param": "/databases/test/storedprocs/testsp"
        }
      ]
    },
    {
      "route": "/databases/:database/storedprocs/:name",
      "configured": true,
      "type": "put",
      "routeclass": "./relstore.js",
      "routefunction": "ExecSP",
      "description": "Execute storedprocedure in the database with the name",
      "paramschema": {
        "required": [
          "database",
          "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": {
        "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/storedprocs/AddEmployee",
          "payload": {
            "prestatements": "",
            "poststatements": "select * from employees;",
            "params": [
              {
                "name": "firstname",
                "mode": "in",
                "value": "Vinay"
              },
              {
                "name": "lastname",
                "mode": "in",
                "value": "David"
              }
            ]
          }
        },
        {
          "param": "/databases/test/storedprocs/DeleteEmployee",
          "payload": {
            "prestatements": "",
            "poststatements": "select * from employees;",
            "params": [
              {
                "name": "id",
                "mode": "in",
                "value": "2"
              }
            ]
          }
        },
        {
          "param": "/databases/test/storedprocs/testsp",
          "payload": {
            "prestatements": "",
            "poststatements": "",
            "params": [
              {
                "name": "var1",
                "mode": "in",
                "type": "decimal(5,2)",
                "value": "10.025"
              },
              {
                "name": "var2",
                "type": "decimal(5, 2)",
                "mode": "out"
              }
            ]
          }
        },
        {
          "param": "/databases/test/storedprocs/testsp",
          "payload": {
            "name": "testsp",
            "prestatements": "set @var3 = 5.1;",
            "poststatements": "select @var2+@var3 as var; select @var2 as var2",
            "params": [
              {
                "name": "var1",
                "mode": "in",
                "type": "decimal(5,2)",
                "value": "10.025"
              },
              {
                "name": "var2",
                "type": "decimal(5,2)",
                "mode": "out"
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/databases/:database/execstatements",
      "configured": true,
      "type": "post",
      "routeclass": "./relstore.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 employees where emp_id=1"
          }
        },
        {
          "param": "/databases/retail/execstatements",
          "payload": {
            "statements": "select * from sales limit 10"
          }
        },
        {
          "param": "/databases/retail/execstatements",
          "payload": {
            "statements": "select * from features limit 10"
          }
        },
        {
          "param": "/databases/retail/execstatements",
          "payload": {
            "statements": "select * from stores limit 10"
          }
        },
        {
          "param": "/databases/test/execstatements",
          "payload": {
            "statements": "insert into employees (emp_id, first_name, last_name) values(2, 'Roger', 'Meyer'); select * from employees"
          }
        },
        {
          "param": "/databases/test/execstatements",
          "payload": {
            "statements": "select * from employees limit 10"
          }
        }
      ]
    }
  ],
  "loglevel": "trace"
}