* Get row count estimate for a table. * Prefers the connector's native statistics-based method (e.g. pg_class.reltuples) * when available, falling back to COUNT(*) for connectors that don't implement it.
( connector: Connector, tableName: string, schemaName?: string )
| 93 | * when available, falling back to COUNT(*) for connectors that don't implement it. |
| 94 | */ |
| 95 | async function getTableRowCount( |
| 96 | connector: Connector, |
| 97 | tableName: string, |
| 98 | schemaName?: string |
| 99 | ): Promise<number | null> { |
| 100 | try { |
| 101 | if (connector.getTableRowCount) { |
| 102 | return await connector.getTableRowCount(tableName, schemaName); |
| 103 | } |
| 104 | |
| 105 | // Fallback: COUNT(*) for connectors without a statistics-based implementation |
| 106 | const qualifiedTable = quoteQualifiedIdentifier(tableName, schemaName, connector.id); |
| 107 | const countQuery = `SELECT COUNT(*) as count FROM ${qualifiedTable}`; |
| 108 | const result = await connector.executeSQL(countQuery, { maxRows: 1 }); |
| 109 | |
| 110 | if (result.rows && result.rows.length > 0) { |
| 111 | return Number(result.rows[0].count || result.rows[0].COUNT || 0); |
| 112 | } |
| 113 | } catch (error) { |
| 114 | // If we can't get row count, return null (not critical) |
| 115 | return null; |
| 116 | } |
| 117 | return null; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Get table comment from the connector if supported. |
no test coverage detected