[AI] GROUP BY in Database Query

OS info

  • Operating System : Windows 10.0.22631
  • Wappler Version : 7.3.6

Problem description

Claude Sonnet 3.7

AI generated code using Database Query instead of Database Custom Query.

....

{
    "name": "available_expos",
    "module": "dbconnector",
    "action": "select",
    "options": {
      "connection": "db",
      "sql": {
        "type": "SELECT",
        "columns": [
          {
            "table": "expos",
            "column": "id"
          },
          {
            "table": "expos",
            "column": "name"
          },
          {
            "table": "expos",
            "column": "description"
          },
          {
            "table": "expos",
            "column": "start_date"
          },
          {
            "table": "expos",
            "column": "end_date"
          },
          {
            "table": "expos",
            "column": "location"
          },
          {
            "table": "expos",
            "column": "address"
          },
          {
            "table": "expos",
            "column": "city"
          },
          {
            "table": "expos",
            "column": "state"
          },
          {
            "table": "expos",
            "column": "max_vendors"
          },
          {
            "table": "vendor_count_subquery",
            "column": "current_vendors",
            "alias": "current_vendors"
          }
        ],
        "table": {
          "name": "expos"
        },
        "joins": [
          {
            "table": "(SELECT expo_id, COUNT(*) AS current_vendors FROM expo_vendors GROUP BY expo_id) AS vendor_count_subquery",
            "alias": "vendor_count_subquery",
            "type": "LEFT",
            "clauses": {
              "condition": "AND",
              "rules": [
                {
                  "operator": "equal",
                  "id": "expos.id",
                  "value": {
                    "table": "vendor_count_subquery",
                    "column": "expo_id"
                  }
                }
              ]
            }
          }
        ],
        "wheres": {
          "condition": "AND",
          "rules": [
            {
              "id": "expos.end_date",
              "field": "end_date",
              "type": "date",
              "operator": "greater",
              "value": "{{NOW}}",
              "data": {
                "table": "expos",
                "column": "end_date"
              },
              "operation": ">"
            },
            {
              "id": "expos.status",
              "field": "status",
              "type": "text",
              "operator": "in",
              "value": [
                "active",
                "upcoming"
              ],
              "data": {
                "table": "expos",
                "column": "status"
              },
              "operation": "IN"
            },
            {
              "id": "custom",
              "operator": "custom",
              "value": "(vendor_count_subquery.current_vendors IS NULL OR vendor_count_subquery.current_vendors < expos.max_vendors)"
            }
          ]
        },
        "orders": [
          {
            "table": "expos",
            "column": "start_date",
            "direction": "ASC",
            "recid": "start_date"
          }
        ]
      }
    },
    "output": true,
    "meta": [
      {
        "type": "number",
        "name": "id"
      },
      {
        "type": "text",
        "name": "name"
      },
      {
        "type": "text",
        "name": "description"
      },
      {
        "type": "date",
        "name": "start_date"
      },
      {
        "type": "date",
        "name": "end_date"
      },
      {
        "type": "text",
        "name": "location"
      },
      {
        "type": "text",
        "name": "address"
      },
      {
        "type": "text",
        "name": "city"
      },
      {
        "type": "text",
        "name": "state"
      },
      {
        "type": "number",
        "name": "max_vendors"
      }
    ],
    "outputType": "array",
    "collapsed": true
  },