Skip to content

Commit

Permalink
create ArgumentsArray type and remove FieldInfo export
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kornelakis authored and CodeFoodPixels committed Apr 29, 2022
1 parent faf740f commit ca9fde2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions examples/connection/typescript/src/returnArgumentsArray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mysql from '../../../../index';
import type { FieldInfo, Query } from '../../../../index';
import mysql, { ArgumentsArray } from '../../../../index';
import { Employee } from './employee';

function run() {
Expand All @@ -13,7 +12,7 @@ function run() {
}).then((conn) => {
connection = conn;

return connection.query<[data: Employee[], fields: FieldInfo[], query: Query<Employee>]>('select * from employees limit 0, 10');
return connection.query<ArgumentsArray<Employee>>('select * from employees limit 0, 10');
}).then(([data, fields, query]) => {
console.log(`The SQL for the query was: ${query.sql}\n`);

Expand All @@ -40,7 +39,7 @@ async function runAwait() {
returnArgumentsArray: true
});

const [data, fields, query] = await connection.query<[data: Employee[], fields: mysql.FieldInfo[], query: Query<Employee>]>('select * from employees limit 0, 10');
const [data, fields, query] = await connection.query<ArgumentsArray<Employee>>('select * from employees limit 0, 10');

console.log(`The SQL for the query was: ${query.sql}\n`);

Expand Down
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as mysql from 'mysql';
import * as Bluebird from 'bluebird';

export type { FieldInfo } from 'mysql';
import Bluebird from 'bluebird';

export function createConnection(connectionUri: string | ConnectionConfig): Bluebird<Connection>;

Expand All @@ -12,6 +10,8 @@ export function createPoolCluster(config: mysql.PoolClusterConfig): Bluebird<Poo
export { Types, escape, escapeId, format, raw, ConnectionOptions, PoolClusterConfig, MysqlError } from 'mysql';

export type mysqlModule = typeof mysql;

export type ArgumentsArray<T> = [data: T[], fields: mysql.FieldInfo[], query: Query<T>];
export interface ConnectionConfig extends mysql.ConnectionConfig {
mysqlWrapper?: (mysql: mysqlModule, callback?: (err: Error | null, success?: mysqlModule) => void) => mysqlModule | Promise<mysqlModule> | void;
returnArgumentsArray?: boolean;
Expand Down

0 comments on commit ca9fde2

Please sign in to comment.