Skip to content

Commit 7cfab10

Browse files
committed
new removeDoubleArray
1 parent 1b77f58 commit 7cfab10

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.413",
3+
"version": "1.0.415",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

src/drivers/utilities.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ export function getUpdateResults(results?: any): Record<string, any> | undefined
125125
return undefined
126126
}
127127

128+
/**
129+
* Allow compatibility with ORMs that call methods such as all(), get(), etc.
130+
* by passing parameters in an array
131+
*/
132+
function removeDoubleArray(array: any[]): SQLiteCloudDataTypes[] {
133+
if (Array.isArray(array) && array.length == 1 && Array.isArray(array[0])) {
134+
return array[0]
135+
}
136+
return array
137+
}
138+
128139
/**
129140
* Many of the methods in our API may contain a callback as their last argument.
130141
* This method will take the arguments array passed to the method and return an object
@@ -140,9 +151,9 @@ export function popCallback<T extends ErrorCallback = ErrorCallback>(
140151
if (args && args.length > 0 && typeof args[args.length - 1] === 'function') {
141152
// at least 2 callbacks?
142153
if (args.length > 1 && typeof args[args.length - 2] === 'function') {
143-
return { args: remaining.slice(0, -2), callback: args[args.length - 2] as T, complete: args[args.length - 1] as T }
154+
return { args: removeDoubleArray(remaining.slice(0, -2)), callback: args[args.length - 2] as T, complete: args[args.length - 1] as T }
144155
}
145-
return { args: remaining.slice(0, -1), callback: args[args.length - 1] as T }
156+
return { args: removeDoubleArray(remaining.slice(0, -1)), callback: args[args.length - 1] as T }
146157
}
147158
return { args: remaining }
148159
}

0 commit comments

Comments
 (0)