[CONJS-108] typescript escape/escapeId definition

This commit is contained in:
rusher
2019-11-04 09:17:59 +01:00
parent da0c9a405b
commit ba953560fa
2 changed files with 41 additions and 0 deletions

32
types/index.d.ts vendored
View File

@ -491,6 +491,22 @@ export interface Connection {
*/
debugCompress(value: boolean): void;
/**
* This function permit to escape a parameter properly according to parameter type to avoid injection.
* @param value parameter
*/
escape(value: any): string;
/**
* This function permit to escape a Identifier properly . See Identifier Names for escaping. Value will be enclosed by '`' character if content doesn't satisfy:
* <OL>
* <LI>ASCII: [0-9,a-z,A-Z$_] (numerals 0-9, basic Latin letters, both lowercase and uppercase, dollar sign, underscore)</LI>
* <LI>Extended: U+0080 .. U+FFFF and escaping '`' character if needed.</LI>
* </OL>
* @param identifier identifier
*/
escapeId(identifier: string): string;
on(ev: 'end', callback: () => void): Connection;
on(ev: 'error', callback: (err: MariaDbError) => void): Connection;
}
@ -544,6 +560,22 @@ export interface Pool {
* Get current stacked connection request.
*/
taskQueueSize(): number;
/**
* This function permit to escape a parameter properly according to parameter type to avoid injection.
* @param value parameter
*/
escape(value: any): string;
/**
* This function permit to escape a Identifier properly . See Identifier Names for escaping. Value will be enclosed by '`' character if content doesn't satisfy:
* <OL>
* <LI>ASCII: [0-9,a-z,A-Z$_] (numerals 0-9, basic Latin letters, both lowercase and uppercase, dollar sign, underscore)</LI>
* <LI>Extended: U+0080 .. U+FFFF and escaping '`' character if needed.</LI>
* </OL>
* @param identifier identifier
*/
escapeId(identifier: string): string;
}
export interface FilteredPoolCluster {

View File

@ -111,6 +111,10 @@ async function testMisc(): Promise<void> {
console.log('ended');
connection.destroy();
connection.escape('test');
connection.escape(true);
connection.escape(5);
connection.escapeId('myColumn');
await createConnection({ multipleStatements: true });
@ -167,6 +171,11 @@ async function testPool(): Promise<void> {
pool = createPool();
const connection = await pool.getConnection();
pool.escape('test');
pool.escape(true);
pool.escape(5);
pool.escapeId('myColumn');
console.log(connection.threadId != null);
await connection.query('SELECT 1 + 1 AS solution');