Skip to content

Commit e4bc40a

Browse files
author
Daniele Briggi
committed
feat(websocket): support to bindings
1 parent b0c5457 commit e4bc40a

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
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.333",
3+
"version": "1.0.336",
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* transport-ws.ts - handles low level communication with sqlitecloud server via socket.io websocket
33
*/
44

5-
import { SQLiteCloudConfig, SQLiteCloudError, ErrorCallback, ResultsCallback, SQLiteCloudCommand } from './types'
5+
import { SQLiteCloudConfig, SQLiteCloudError, ErrorCallback, ResultsCallback, SQLiteCloudCommand, SQLiteCloudDataTypes } from './types'
66
import { SQLiteCloudRowset } from './rowset'
77
import { SQLiteCloudConnection } from './connection'
88
import { io, Socket } from 'socket.io-client'
@@ -46,9 +46,13 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {
4646
if (!this.socket) {
4747
callback?.call(this, new SQLiteCloudError('Connection not established', { errorCode: 'ERR_CONNECTION_NOT_ESTABLISHED' }))
4848
return this
49+
}
50+
51+
if (typeof commands === 'string') {
52+
commands = { query: commands }
4953
}
5054

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

test/connection-ws.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
WARN_SPEED_MS,
1515
EXPECT_SPEED_MS
1616
} from './shared'
17-
import { error } from 'console'
17+
import { SQLiteCloudCommand } from '../src/drivers/types'
1818

1919
describe('connection-ws', () => {
2020
let chinook: SQLiteCloudConnection
@@ -377,6 +377,24 @@ describe('connection-ws', () => {
377377
done()
378378
})
379379
})
380+
381+
it('should select without bindings', done => {
382+
const command = { query: 'SELECT * FROM albums' } as SQLiteCloudCommand
383+
chinook.sendCommands(command, (error, results) => {
384+
expect(error).toBeNull()
385+
expect(results.numberOfColumns).toBeGreaterThan(0)
386+
done()
387+
})
388+
})
389+
390+
it('should select with bindings', done => {
391+
const command: SQLiteCloudCommand = { query: 'SELECT * FROM albums WHERE albumId = ?', parameters: [1] }
392+
chinook.sendCommands(command, (error, results) => {
393+
expect(error).toBeNull()
394+
expect(results.numberOfColumns).toBe(1)
395+
done()
396+
})
397+
})
380398
})
381399

382400
describe('connection stress testing', () => {

test/database.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
*/
44

55
import { SQLiteCloudRowset, SQLiteCloudRow, SQLiteCloudError, sanitizeSQLiteIdentifier } from '../src/index'
6-
import { getTestingDatabase, getTestingDatabaseAsync, getChinookDatabase, removeDatabase, removeDatabaseAsync, LONG_TIMEOUT } from './shared'
6+
import { getTestingDatabase, getTestingDatabaseAsync, getChinookDatabase, removeDatabase, removeDatabaseAsync, LONG_TIMEOUT, getChinookWebsocketConnection } from './shared'
77
import { RowCountCallback } from '../src/drivers/types'
88
import { expect, describe, it } from '@jest/globals'
9+
import { Database } from 'sqlite3'
910

1011
//
1112
// utility methods to setup and destroy temporary test databases

0 commit comments

Comments
 (0)