Skip to content

Commit

Permalink
[CONJS-199] return type for batch() is wrong on typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 18, 2022
1 parent 048fd65 commit ebb3fef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ export interface Connection {
/**
* Execute batch. Values are Array of Array.
*/
batch(sql: string | QueryOptions, values?: any): Promise<UpsertResult[]>;
batch(sql: string | QueryOptions, values?: any): Promise<UpsertResult> | Promise<UpsertResult[]>;

/**
* Execute query returning a Readable Object that will emit columns/data/end/error events
Expand Down Expand Up @@ -678,7 +678,7 @@ export interface Pool {
/**
* Execute a batch on one connection from pool.
*/
batch(sql: string | QueryOptions, values?: any): Promise<UpsertResult[]>;
batch(sql: string | QueryOptions, values?: any): Promise<UpsertResult> | Promise<UpsertResult[]>;

/**
* Execute query using binary (prepare) protocol
Expand Down Expand Up @@ -737,7 +737,7 @@ export interface Pool {
export interface FilteredPoolCluster {
getConnection(): Promise<PoolConnection>;
query(sql: string | QueryOptions, values?: any): Promise<any>;
batch(sql: string | QueryOptions, values?: any): Promise<UpsertResult[]>;
batch(sql: string | QueryOptions, values?: any): Promise<UpsertResult> | Promise<UpsertResult[]>;
execute(sql: string | QueryOptions, values?: any): Promise<any>;
}

Expand Down
23 changes: 19 additions & 4 deletions types/mariadb-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mariadb = require('..');
import { Connection, FieldInfo, ConnectionConfig, PoolConfig } from '..';
import { Connection, FieldInfo, ConnectionConfig, PoolConfig, UpsertResult } from '..';
import { Stream } from 'stream';

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -150,7 +150,11 @@ async function testMisc(): Promise<void> {
connection.escape(true);
connection.escape(5);
connection.escapeId('myColumn');

const res = (await connection.batch('INSERT INTO myTable VALUE (?,?)', [
[1, 2],
[4, 3]
])) as UpsertResult;
console.log(res.affectedRows);
await createConnection({ multipleStatements: true });

await createConnection({ debug: true });
Expand Down Expand Up @@ -221,7 +225,11 @@ async function testPool(): Promise<void> {
pool.escape(true);
pool.escape(5);
pool.escapeId('myColumn');

const res = (await pool.batch('INSERT INTO myTable VALUE (?,?)', [
[1, 2],
[4, 3]
])) as UpsertResult;
console.log(res.affectedRows);
console.log(connection.threadId != null);

await connection.query('SELECT 1 + 1 AS solution');
Expand Down Expand Up @@ -258,8 +266,15 @@ async function testPoolCluster(): Promise<void> {
connection = await poolCluster.of(null, 'RR').getConnection();
console.log(connection.threadId != null);

poolCluster.of('SLAVE.*', 'RANDOM');
const filtered = poolCluster.of('SLAVE.*', 'RANDOM');
const res = (await filtered.batch('INSERT INTO myTable VALUE (?,?)', [
[1, 2],
[4, 3]
])) as UpsertResult;
console.log(res.affectedRows);

await filtered.query('SELECT 1 + 1 AS solution');
connection.release();
mariadb.createPoolCluster({
canRetry: true,
removeNodeErrorCount: 3,
Expand Down

0 comments on commit ebb3fef

Please sign in to comment.