Skip to content

Commit 75e489a

Browse files
author
Daniele Briggi
committed
feat(websocket): use new verision of endpoint
1 parent a9952b7 commit 75e489a

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
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.338",
3+
"version": "1.0.339",
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/connection-ws.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {
5252
commands = { query: commands }
5353
}
5454

55-
this.socket.emit('v2/weblite/sql', { sql: commands.query, bind: commands.parameters, row: 'array' }, (response: any) => {
55+
this.socket.emit('GET /v2/weblite/sql', { sql: commands.query, bind: commands.parameters, row: 'array' }, (response: any) => {
5656
if (response?.error) {
5757
const error = new SQLiteCloudError(response.error.detail, { ...response.error })
5858
callback?.call(this, error)

src/drivers/database.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export class Database extends EventEmitter {
204204
public run<T>(sql: string, params: any, callback?: ResultsCallback<T>): this
205205
public run(sql: string, ...params: any[]): this {
206206
const { args, callback } = popCallback<ResultsCallback>(params)
207-
const command: SQLiteCloudCommand = { query: sql, parameters: args?.flat() }
207+
const command: SQLiteCloudCommand = { query: sql, parameters: args }
208208
this.getConnection((error, connection) => {
209209
if (error || !connection) {
210210
this.handleError(null, error as Error, callback)
@@ -237,7 +237,7 @@ export class Database extends EventEmitter {
237237
public get<T>(sql: string, params: any, callback?: RowCallback<T>): this
238238
public get(sql: string, ...params: any[]): this {
239239
const { args, callback } = popCallback<RowCallback>(params)
240-
const command: SQLiteCloudCommand = { query: sql, parameters: args?.flat() }
240+
const command: SQLiteCloudCommand = { query: sql, parameters: args }
241241
this.getConnection((error, connection) => {
242242
if (error || !connection) {
243243
this.handleError(null, error as Error, callback)
@@ -275,7 +275,7 @@ export class Database extends EventEmitter {
275275
public all<T>(sql: string, params: any, callback?: RowsCallback<T>): this
276276
public all(sql: string, ...params: any[]): this {
277277
const { args, callback } = popCallback<RowsCallback>(params)
278-
const command: SQLiteCloudCommand = { query: sql, parameters: args?.flat() }
278+
const command: SQLiteCloudCommand = { query: sql, parameters: args }
279279
this.getConnection((error, connection) => {
280280
if (error || !connection) {
281281
this.handleError(null, error as Error, callback)
@@ -316,7 +316,7 @@ export class Database extends EventEmitter {
316316
// extract optional parameters and one or two callbacks
317317
const { args, callback, complete } = popCallback<RowCallback>(params)
318318

319-
const command: SQLiteCloudCommand = { query: sql, parameters: args?.flat() }
319+
const command: SQLiteCloudCommand = { query: sql, parameters: args }
320320
this.getConnection((error, connection) => {
321321
if (error || !connection) {
322322
this.handleError(null, error as Error, callback)

src/drivers/statement.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,16 @@ export class Statement<T> {
6464
if (args?.length > 0) {
6565
// apply new bindings then execute
6666
this.bind(...args, () => {
67-
this._database.run(this._preparedSql.query || '', this._preparedSql.parameters, callback)
67+
const query = this._preparedSql.query || ''
68+
const parametes: any = [...this._preparedSql.parameters ?? []]
69+
this._database.run(query, ...parametes, callback)
6870
})
6971
} else {
7072
// execute prepared sql with same bindings
71-
this._database.run(this._preparedSql.query || '', this._preparedSql.parameters, callback)
72-
}
73+
const query = this._preparedSql.query || ''
74+
const parametes: any = [...this._preparedSql.parameters ?? []]
75+
this._database.run(query, ...parametes, callback)
76+
}
7377

7478
return this
7579
}
@@ -89,12 +93,16 @@ export class Statement<T> {
8993
if (args?.length > 0) {
9094
// apply new bindings then execute
9195
this.bind(...args, () => {
92-
this._database.get(this._preparedSql.query || '', this._preparedSql.parameters, callback)
96+
const query = this._preparedSql.query || ''
97+
const parametes: any = [...this._preparedSql.parameters ?? []]
98+
this._database.get(query, ...parametes, callback)
9399
})
94100
} else {
95101
// execute prepared sql with same bindings
96-
this._database.get(this._preparedSql.query || '', this._preparedSql.parameters, callback)
97-
}
102+
const query = this._preparedSql.query || ''
103+
const parametes: any = [...this._preparedSql.parameters ?? []]
104+
this._database.get(query, ...parametes, callback)
105+
}
98106

99107
return this
100108
}
@@ -111,12 +119,16 @@ export class Statement<T> {
111119
if (args?.length > 0) {
112120
// apply new bindings then execute
113121
this.bind(...args, () => {
114-
this._database.all(this._preparedSql.query || '', this._preparedSql.parameters, callback)
122+
const query = this._preparedSql.query || ''
123+
const parametes: any = [...this._preparedSql.parameters ?? []]
124+
this._database.all(query, ...parametes, callback)
115125
})
116126
} else {
117127
// execute prepared sql with same bindings
118-
this._database.all(this._preparedSql.query || '', this._preparedSql.parameters, callback)
119-
}
128+
const query = this._preparedSql.query || ''
129+
const parametes: any = [...this._preparedSql.parameters ?? []]
130+
this._database.all(query, ...parametes, callback)
131+
}
120132

121133
return this
122134
}
@@ -133,12 +145,16 @@ export class Statement<T> {
133145
if (args?.length > 0) {
134146
// apply new bindings then execute
135147
this.bind(...args, () => {
136-
this._database.each(this._preparedSql.query || '', this._preparedSql.parameters, callback, complete as RowCountCallback)
148+
const query = this._preparedSql.query || ''
149+
const parametes: any = [...this._preparedSql.parameters ?? [], ...[callback, complete as RowCountCallback]]
150+
this._database.each(query, ...parametes)
137151
})
138152
} else {
139153
// execute prepared sql with same bindings
140-
this._database.each(this._preparedSql.query || '', this._preparedSql.parameters, callback, complete as RowCountCallback)
141-
}
154+
const query = this._preparedSql.query || ''
155+
const parametes: any = [...this._preparedSql.parameters ?? [], ...[callback, complete as RowCountCallback]]
156+
this._database.each(query, ...parametes)
157+
}
142158

143159
return this
144160
}

test/connection-ws.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ describe('connection-ws', () => {
391391
const command: SQLiteCloudCommand = { query: 'SELECT * FROM albums WHERE albumId = ?', parameters: [1] }
392392
chinook.sendCommands(command, (error, results) => {
393393
expect(error).toBeNull()
394-
expect(results.numberOfColumns).toBe(1)
394+
expect(results.numberOfColumns).toBe(3)
395395
done()
396396
})
397397
})

0 commit comments

Comments
 (0)