Skip to content

fix(pg): for pg tools, use count isntead of length for number of rows impacted#2317

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/pg
Dec 11, 2025
Merged

fix(pg): for pg tools, use count isntead of length for number of rows impacted#2317
waleedlatif1 merged 1 commit intostagingfrom
fix/pg

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • for pg tools, use count isntead of length for number of rows impacted

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Dec 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Dec 11, 2025 9:59pm

@waleedlatif1 waleedlatif1 merged commit c592e54 into staging Dec 11, 2025
5 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/pg branch December 11, 2025 22:03
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 11, 2025

Greptile Overview

Greptile Summary

Changed PostgreSQL utility functions to use result.count instead of result.length for determining the number of rows affected by queries.

  • Updated executeQuery, executeInsert, executeUpdate, and executeDelete functions to use result.count ?? result.length ?? 0 for more accurate row count tracking
  • The postgres library provides a count property that reflects the actual number of rows affected, similar to MySQL's affectedRows
  • Fallback chain ensures compatibility: uses count if available, then length, then defaults to 0

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is straightforward and improves accuracy by using the postgres library's built-in count property. The fallback chain (count ?? length ?? 0) ensures backward compatibility and handles edge cases gracefully
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/app/api/tools/postgresql/utils.ts 5/5 Changed rowCount calculation to use result.count property from postgres library instead of array length for more accurate row count tracking

Sequence Diagram

sequenceDiagram
    participant Client
    participant API as PostgreSQL API Route
    participant Utils as executeQuery/Insert/Update/Delete
    participant PG as postgres library
    participant DB as PostgreSQL Database

    Client->>API: POST request with query/data
    API->>Utils: Call execute function
    Utils->>PG: sql.unsafe(query, params)
    PG->>DB: Execute SQL query
    DB-->>PG: Return result with count + rows
    PG-->>Utils: result object
    Note over Utils: Extract rowCount:<br/>result.count ?? result.length ?? 0
    Utils-->>API: {rows: [], rowCount: number}
    API-->>Client: JSON response with rowCount
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant