{
  "db_name": "PostgreSQL",
  "query": "\n        SELECT\n            r.id,\n            r.key,\n            r.name,\n            r.audience,\n            r.description,\n            r.department_id,\n            d.name AS \"department_name?\",\n            r.is_active,\n            r.can_approve_requests,\n            r.can_manage_system_settings,\n            r.created_at,\n            COUNT(DISTINCT e.id) AS users_assigned,\n            COUNT(DISTINCT rp.id) AS permissions_count\n        FROM roles r\n        LEFT JOIN departments d ON d.id = r.department_id\n        LEFT JOIN employees e ON e.role_code = r.key\n        LEFT JOIN role_permissions rp ON rp.role_id = r.id\n        WHERE ($1 = '' OR r.audience = $1)\n          AND ($2 = '' OR LOWER(r.name) LIKE '%' || $2 || '%' OR LOWER(r.key) LIKE '%' || $2 || '%')\n        GROUP BY r.id, d.name\n        ORDER BY r.created_at DESC\n        LIMIT $3 OFFSET $4\n        ",
  "describe": {
    "columns": [
      {
        "ordinal": 0,
        "name": "id",
        "type_info": "Uuid"
      },
      {
        "ordinal": 1,
        "name": "key",
        "type_info": "Varchar"
      },
      {
        "ordinal": 2,
        "name": "name",
        "type_info": "Varchar"
      },
      {
        "ordinal": 3,
        "name": "audience",
        "type_info": "Varchar"
      },
      {
        "ordinal": 4,
        "name": "description",
        "type_info": "Text"
      },
      {
        "ordinal": 5,
        "name": "department_id",
        "type_info": "Uuid"
      },
      {
        "ordinal": 6,
        "name": "department_name?",
        "type_info": "Varchar"
      },
      {
        "ordinal": 7,
        "name": "is_active",
        "type_info": "Bool"
      },
      {
        "ordinal": 8,
        "name": "can_approve_requests",
        "type_info": "Bool"
      },
      {
        "ordinal": 9,
        "name": "can_manage_system_settings",
        "type_info": "Bool"
      },
      {
        "ordinal": 10,
        "name": "created_at",
        "type_info": "Timestamptz"
      },
      {
        "ordinal": 11,
        "name": "users_assigned",
        "type_info": "Int8"
      },
      {
        "ordinal": 12,
        "name": "permissions_count",
        "type_info": "Int8"
      }
    ],
    "parameters": {
      "Left": [
        "Text",
        "Text",
        "Int8",
        "Int8"
      ]
    },
    "nullable": [
      false,
      false,
      false,
      false,
      true,
      true,
      false,
      false,
      false,
      false,
      false,
      null,
      null
    ]
  },
  "hash": "5767adf000e23b56255aa4a00370c8403dba7e91a69673a320beb680359f33b8"
}
