{
  "routines": [
    {
      "type": "getlist",
      "name": "Get List",
      "summary": "Get list of #pluralForm#",
      "description": "Get a list of #pluralForm# based on criteria",
      "outputdescription": "Returns an array of #pluralForm# along with total count if requested.",
      "inputs": [
        { "type": "boolean", "name": "countOnly", "description": "Send true to only return the total count of the matching records" },
        { "type": "string", "name": "select", "ibmiLength": 1000, "multipleValues": true, "ibmiDim": 10000, "description": "Array of all the fields to be returned." },
        { "type": "string", "name": "filter", "ibmiLength": 1000, "description": "Enter the query filter." },
        { "type": "string", "name": "orderby", "ibmiLength": 1000, "multipleValues": true, "ibmiDim": 10000, "description": "Array of all the fields to be sorted by." },
        { "type": "boolean", "name": "count", "description": "Send true if you want the total count of the matching records" },
        { "type": "integer", "name": "limit", "description": "Enter the number of records to return" },
        { "type": "integer", "name": "skip", "description": "Enter the number of records to skip. This is useful when loading a page of records at a time." }
      ],
      "outputs": [ { "name": "totalCount", "type": "integer" } ],
      "steps": [
        {
          "text": "Count requested?",
          "answers": {
            "plugin": "Conditions:comparison",
            "variable": "input[\"count\"]",
            "type": "truthy",
            "and-or": "or",
            "variable2": "input[\"countOnly\"]",
            "type2": "truthy",
            "and-or2": ""
          },
          "isStructureStart": true
        },
        {
          "text": "Get record count",
          "answers": {
            "plugin": "Database:get-record-count",
            "connection": "#connection#",
            "tables": "#table#",
            "criteria": "${input[\"filter\"]}",
            "destination": "API output",
            "api_output": "output[\"totalCount\"]"
          }
        },
        {
          "isStructureEnd": true
        },
        {
          "text": "Records requested?",
          "answers": {
            "plugin": "Conditions:comparison",
            "variable": "input[\"countOnly\"]",
            "type": "falsy",
            "and-or": ""
          },
          "isStructureStart": true
        },
        {
          "text": "Get records",
          "answers": {
            "plugin": "Database:get-records",
            "connection": "#connection#",
            "tables": "#table#",
            "columns": "${input[\"select\"]}",
            "criteria": "${input[\"filter\"]}",
            "add_order_by": true,
            "order_by": "${input[\"orderby\"]}",
            "limit": "${input[\"limit\"]}",
            "skip": "${input[\"skip\"]}",
            "destination": "API output",
            "api_output": "output[\"data\"]"
          }
        },
        {
          "isStructureEnd": true
        }
      ]
    },
    {
      "type": "getone",
      "name": "Get One",
      "summary": "Get one #singleForm#",
      "description": "Get one #singleForm#",
      "outputdescription": "Returns one #singleForm#.",
      "inputs": [],
      "outputs": [],
      "steps": [
        {
          "text": "Get record",
          "answers": {
            "plugin": "Database:get-record",
            "connection": "#connection#",
            "tables": "#table#",
            "columns": "#columns#",
            "criteria": "#criteria#",
            "destination": "API output",
            "api_output": "output[\"data\"]"
          }
        }
      ]
    },
    {
      "type": "addone",
      "name": "Add One",
      "summary": "Add one #singleForm#",
      "description": "Add one #singleForm#",
      "outputdescription": "Returns the status of the request.",
      "inputs": [],
      "outputs": [ { "type": "object", "name": "status", "children": [ { "type": "boolean", "name": "success" }, { "type": "integer", "name": "affectedRows", "example": 1 } ] } ],
      "steps": [
        {
          "text": "Insert",
          "answers": {
            "plugin": "Database:insert-record",
            "connection": "#connection#",
            "table": "#table#",
            "record_source": "From API input",
            "api_input": "input[\"data\"]",
            "results": "output[\"status\"]"
          }
        }
      ]
    },
    {
      "type": "updateone",
      "name": "Update One",
      "summary": "Update one #singleForm#",
      "description": "Update one #singleForm#",
      "outputdescription": "Returns the status of the request.",
      "inputs": [],
      "outputs": [ { "type": "object", "name": "status", "children": [ { "type": "boolean", "name": "success" }, { "type": "integer", "name": "affectedRows", "example": 1 } ] } ],
      "steps": [
        {
          "text": "Update",
          "answers": {
            "plugin": "Database:update-records",
            "connection": "#connection#",
            "table": "#table#",
            "criteria": "#criteria#",
            "record_source": "From API input",
            "api_input": "input[\"data\"]",
            "results": "output[\"status\"]"
          }
        }
      ]
    },
    {
      "type": "deleteone",
      "name": "Delete One",
      "summary": "Delete one #singleForm#",
      "description": "Delete one #singleForm#",
      "outputdescription": "Returns the status of the request.",
      "inputs": [],
      "outputs": [ { "type": "object", "name": "status", "children": [ { "type": "boolean", "name": "success" }, { "type": "integer", "name": "affectedRows", "example": 1 } ] } ],
      "steps": [
        {
          "text": "Delete",
          "answers": {
            "plugin": "Database:delete-records",
            "connection": "#connection#",
            "table": "#table#",
            "criteria": "#criteria#",
            "results": "output[\"status\"]"
          }
        }
      ]
    }
  ]
}