Skip to content

Commit

Permalink
feat: Added debug logging to new functions in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
darunrs committed Aug 31, 2023
1 parent a142c7f commit c01090f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
28 changes: 12 additions & 16 deletions frontend/src/utils/indexerRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,16 @@ export default class IndexerRunner {
const result = tables.reduce((prev, tableName) => {
const sanitizedTableName = this.sanitizeTableName(tableName);
const funcForTable = {
[`insert_${sanitizedTableName}`]: async (objects) => await this.insert(blockHeight, schemaName, tableName, objects),
[`select_${sanitizedTableName}`]: async (object, limit = 0) => await this.select(blockHeight, schemaName, tableName, object, limit)
[`insert_${sanitizedTableName}`]: async (objects) => await this.dbOperationLog(blockHeight,
`Inserting object ${JSON.stringify(objects)} into table ${tableName} on schema ${schemaName}`),
[`select_${sanitizedTableName}`]: async (object, limit = 0) => await this.dbOperationLog(blockHeight,
`Selecting objects with values ${JSON.stringify(object)} from table ${tableName} on schema ${schemaName} with ${limit === 0 ? 'no' : roundedLimit.toString()} limit`),
[`update_${sanitizedTableName}`]: async (whereObj, updateObj) => await this.dbOperationLog(blockHeight,
`Updating objects that match ${JSON.stringify(whereObj)} with values ${JSON.stringify(updateObj)} in table ${tableName} on schema ${schemaName}`),
[`upsert_${sanitizedTableName}`]: async (objects, conflictColumns, updateColumns) => await this.dbOperationLog(blockHeight,
`Inserting objects with values ${JSON.stringify(objects)} in table ${tableName} on schema ${schemaName}. Conflict on columns ${conflictColumns.join(', ')} will update values in columns ${updateColumns.join(', ')}`),
[`delete_${sanitizedTableName}`]: async (object) => await this.dbOperationLog(blockHeight,
`Deleting objects with values ${JSON.stringify(object)} in table ${tableName} on schema ${schemaName}`)
};

return {
Expand All @@ -209,24 +217,12 @@ export default class IndexerRunner {
}
}

insert(blockHeight, schemaName, tableName, objects) {
dbOperationLog(blockHeight, logMessage) {
this.handleLog(
blockHeight,
"",
() => {
console.log('Inserting object %s into table %s on schema %s', JSON.stringify(objects), tableName, schemaName);
}
);
return {};
}

select(blockHeight, schemaName, tableName, object, limit) {
this.handleLog(
blockHeight,
"",
() => {
const roundedLimit = Math.round(limit);
console.log('Selecting objects with values %s from table %s on schema %s with %s limit', JSON.stringify(object), tableName, schemaName, limit === 0 ? 'no' : roundedLimit.toString());
console.log(logMessage);
}
);
return {};
Expand Down
4 changes: 2 additions & 2 deletions runner/src/indexer/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@ export default class Indexer {
[`update_${sanitizedTableName}`]: async (whereObj: any, updateObj: any) => {
await this.writeLog(`context.db.update_${sanitizedTableName}`, blockHeight,
`Calling context.db.update_${sanitizedTableName}.`,
`Updating object that matches ${JSON.stringify(whereObj)} with values ${JSON.stringify(updateObj)} in table ${tableName} on schema ${schemaName}`);
`Updating objects that match ${JSON.stringify(whereObj)} with values ${JSON.stringify(updateObj)} in table ${tableName} on schema ${schemaName}`);
dmlHandler = dmlHandler ?? new this.deps.DmlHandler(account);
return await dmlHandler.update(schemaName, tableName, whereObj, updateObj);
},
[`upsert_${sanitizedTableName}`]: async (objects: any, conflictColumns: string[], updateColumns: string[]) => {
await this.writeLog(`context.db.upsert_${sanitizedTableName}`, blockHeight,
`Calling context.db.upsert_${sanitizedTableName}.`,
`Inserting objects with values ${JSON.stringify(objects)} in table ${tableName} on schema ${schemaName}. On conflict on columns ${conflictColumns.join(', ')} will update values in columns ${updateColumns.join(', ')}`);
`Inserting objects with values ${JSON.stringify(objects)} in table ${tableName} on schema ${schemaName}. Conflict on columns ${conflictColumns.join(', ')} will update values in columns ${updateColumns.join(', ')}`);
dmlHandler = dmlHandler ?? new this.deps.DmlHandler(account);
return await dmlHandler.upsert(schemaName, tableName, Array.isArray(objects) ? objects : [objects], conflictColumns, updateColumns);
},
Expand Down

0 comments on commit c01090f

Please sign in to comment.