MCPcopy Create free account
hub / github.com/damms005/devdb-vscode / getTotalRows

Method getTotalRows

src/database-engines/sqlite-engine.ts:253–288  ·  view source on GitHub ↗
(
    table: string,
    columns: Column[],
    whereClause?: Record<string, any>
  )

Source from the content-addressed store, hash-verified

251 }
252
253 async getTotalRows(
254 table: string,
255 columns: Column[],
256 whereClause?: Record<string, any>
257 ): Promise<number> {
258 try {
259 const db = this.getConnection();
260 if (!db) {
261 return Promise.reject('Cannot connect to database')
262 }
263
264 let query = `SELECT COUNT(*) as count FROM ${this.escapeIdentifier(table)}`;
265 const params: any[] = [];
266
267 if (whereClause && Object.keys(whereClause).length > 0) {
268 const { whereString, whereParams } = this.buildWhereClause(whereClause, columns);
269 query += whereString.trim() ? ` WHERE ${whereString}` : '';
270 params.push(...whereParams);
271 }
272
273 return new Promise<number>((resolve, reject) => {
274 db.get(query, params, (err, row: any) => {
275 if (err) {
276 reportError(`SQLite get total rows error: ${err}`);
277 reject(err);
278 return;
279 }
280
281 resolve(row ? row.count : 0);
282 });
283 });
284 } catch (err) {
285 reportError(`SQLite get total rows error: ${err}`);
286 return 0;
287 }
288 }
289
290 async getRows(table: string, columns: Column[], limit: number, offset: number, whereClause?: Record<string, any>): Promise<QueryResponse | undefined> {
291 try {

Callers

nothing calls this directly

Calls 5

getConnectionMethod · 0.95
escapeIdentifierMethod · 0.95
buildWhereClauseMethod · 0.95
reportErrorFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected