Skip to content

Commit

Permalink
Merge pull request #55 from YizYah/truncate
Browse files Browse the repository at this point in the history
Truncate
  • Loading branch information
YizYah authored Jul 22, 2024
2 parents 260abb4 + 108d263 commit 8c9008c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const databaseInfo:DatabaseInfo = {

#### getSessionVerify()

An async version of `getSession` that also verifies your connection. Everything else is the same.
An async version of `getSession` that also verifies your connection. Everything else is the same as `getSession`.

```typescript
async function getSessionVerify(databaseInfo?: DatabaseInfo)
Expand Down
8 changes: 4 additions & 4 deletions src/getSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export function getSession(databaseInfo?: DatabaseInfo, config?: Config): Sessio
config,
)

if (finalDatabaseInfo && finalDatabaseInfo.DATABASE){
return driver.session({database: finalDatabaseInfo.DATABASE});
}
if (finalDatabaseInfo && finalDatabaseInfo.DATABASE) {
return driver.session({ database: finalDatabaseInfo.DATABASE });
}
return driver.session();

}
10 changes: 9 additions & 1 deletion src/queryForErrorString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ export function truncatedParamString(params: any) {
return paramsString
}

export function truncateQueryString(queryString: string): string {
const MAX_LENGTH = 60;
if (queryString.length > MAX_LENGTH) {
return queryString.substring(0, MAX_LENGTH) + '...';
}
return queryString;
}

export function queryForErrorString(queryString: string,
params: any) {
return `
query:
-----------------
${queryString.trim()}
${truncateQueryString(queryString.trim())}
-----------------
params: ${truncatedParamString(params)}
Expand Down
2 changes: 1 addition & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function run(
summary
}
} catch (err) {
throw new Error(`problem converting to simple records the response to this query: : ${queryForErrorString}
throw new Error(`problem converting to simple records the response to this query: : ${queryForErrorString(queryString, params)}
-------------------
Here is the error reported: ${err}`);
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ test('run() throws error string', async (t: any) => {

})

const errorMessage = "problem calling the query: \n \n query:\n -----------------\n match (i:Instance {id:'cb71439d-8727-400a-aaf5-95cc2cad06f0'}) \nset i.value = $valueIn \nreturn i.value as value\n ----------------- \n params: {\"valueIn\":\"newValue\"}\n \n \n -------------------\n Here is the error reported: Error: the query set provided does not contain the given query:\n\nquery:\n-----------------\nmatch (i:Instance {id:'cb71439d-8727-400a-aaf5-95cc2cad06f0'}) \nset i.value = $valueIn \nreturn i.value as value\n----------------- \nparams: {\"valueIn\":\"newValue\"}\n"

const errorMessage = "problem calling the query: \n \n query:\n -----------------\n match (i:Instance {id:'cb71439d-8727-400a-aaf5-95cc2cad06f0'...\n ----------------- \n params: {\"valueIn\":\"newValue\"}\n \n \n -------------------\n Here is the error reported: Error: the query set provided does not contain the given query:\n\nquery:\n-----------------\nmatch (i:Instance {id:'cb71439d-8727-400a-aaf5-95cc2cad06f0'}) \nset i.value = $valueIn \nreturn i.value as value\n----------------- \nparams: {\"valueIn\":\"newValue\"}\n"
t.is(error.message, errorMessage);

})

0 comments on commit 8c9008c

Please sign in to comment.