mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 14:38:50 +00:00
fix: Scalar return value
This commit is contained in:
1 parent
e9721ca5ca
commit
38e30c6640
2 files changed
+7
-4
No files matched your search
+1
-1
@@ -2,7 +2,7 @@ import { RowDataPacket, ResultSetHeader, OkPacket } from 'mysql2';
|
||||
|
||||
type SQLResponse = RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader;
|
||||
|
||||
export type QueryResponse = SQLResponse | SQLResponse[];
|
||||
export type QueryResponse = SQLResponse | SQLResponse[] | RowDataPacket;
|
||||
|
||||
export type QueryType = 'insert' | 'update' | 'scalar' | 'single' | null;
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@ import type { QueryResponse, QueryType } from '../types';
|
||||
const isOkPacket = (result: QueryResponse, insertId?: boolean): result is OkPacket =>
|
||||
insertId ? (result as OkPacket).insertId !== undefined : (result as OkPacket).affectedRows !== undefined;
|
||||
|
||||
const isRowDataPacket = (result: QueryResponse): result is RowDataPacket[] => (result as RowDataPacket[]).length !== undefined;
|
||||
const isRowDataPacket = (result: QueryResponse): result is RowDataPacket[] =>
|
||||
(result as RowDataPacket[]).length !== undefined;
|
||||
|
||||
const isRowDataPacketArray = (result: QueryResponse): result is RowDataPacket[][] =>
|
||||
(result as RowDataPacket[][]).length !== undefined && (result as RowDataPacket[][])[0].length !== undefined;
|
||||
(result as RowDataPacket[][]).length !== undefined &&
|
||||
(result as RowDataPacket[][])[0] !== undefined &&
|
||||
Object.values((result as RowDataPacket[][])[0])[0] !== undefined;
|
||||
|
||||
export const parseResponse = (type: QueryType, result: QueryResponse): QueryResponse | RowDataPacket | number | null => {
|
||||
export const parseResponse = (type: QueryType, result: QueryResponse): QueryResponse | number | null => {
|
||||
switch (type) {
|
||||
case 'insert':
|
||||
return isOkPacket(result) ? result.insertId : null;
|
||||
|
||||
Reference in new issue
Block a user