Skip to content

Commit f5d3fa2

Browse files
committed
fix pubsub test and added remove channel method
1 parent 271727a commit f5d3fa2

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

.github/workflows/examples-test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'end to end test'
1+
name: 'Test'
22
on:
33
push:
44
workflow_dispatch:
@@ -349,7 +349,7 @@ jobs:
349349

350350
- name: install driver
351351
working-directory: examples/with-typescript-react-native
352-
run: npm i ../../${{ env.DRIVER }}
352+
run: npm i ../../${{ env.DRIVER }} #installing a tar packaged version of the driver since react native doesn't work well with local dependencies
353353

354354
- name: install cocoapods
355355
working-directory: examples/with-typescript-react-native
@@ -413,7 +413,7 @@ jobs:
413413

414414
- name: install driver
415415
working-directory: examples/with-typescript-react-native
416-
run: npm i ../../${{ env.DRIVER }}
416+
run: npm i ../../${{ env.DRIVER }} #installing a tar packaged version of the driver since react native doesn't work well with local dependencies
417417

418418
- name: build app
419419
working-directory: examples/with-typescript-react-native
@@ -474,7 +474,7 @@ jobs:
474474

475475
- name: install driver
476476
working-directory: examples/with-javascript-expo
477-
run: npm i ../../${{ env.DRIVER }}
477+
run: npm i ../../${{ env.DRIVER }} #installing a tar packaged version of the driver since react native doesn't work well with local dependencies
478478

479479
- name: expo prebuild
480480
working-directory: examples/with-javascript-expo
@@ -538,7 +538,7 @@ jobs:
538538

539539
- name: install driver
540540
working-directory: examples/with-javascript-expo
541-
run: npm i ../../${{ env.DRIVER }}
541+
run: npm i ../../${{ env.DRIVER }} #installing a tar packaged version of the driver since react native doesn't work well with local dependencies
542542

543543
- name: expo prebuild
544544
working-directory: examples/with-javascript-expo

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.331",
3+
"version": "1.0.332",
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/pubsub.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,18 @@ export class PubSub {
6666
public async createChannel(name: string, failIfExists: boolean = true): Promise<any> {
6767
let notExistsCommand = ''
6868
if (!failIfExists) {
69-
notExistsCommand = 'IF NOT EXISTS;'
69+
notExistsCommand = 'IF NOT EXISTS'
7070
}
7171

72-
return this.connection.sql(`CREATE CHANNEL ? ${notExistsCommand}`, name)
72+
return this.connection.sql(`CREATE CHANNEL ?${notExistsCommand};`, name)
73+
}
74+
75+
/**
76+
* Deletes a Pub/Sub channel.
77+
* @param name Channel name
78+
*/
79+
public async removeChannel(name: string): Promise<any> {
80+
return this.connection.sql(`REMOVE CHANNEL ?;`, name)
7381
}
7482

7583
/**

test/pubsub.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ describe('pubSub', () => {
99
const connection = getChinookDatabase()
1010
const pubSub = await connection.getPubSub()
1111

12+
const channelName = 'test-channel-' + self.crypto.randomUUID()
1213
try {
1314
let callbackCalled = false
14-
const channelName = 'test-channel-' + Math.floor(Math.random() * 999)
1515
const message = 'Message in a bottle ' + Math.floor(Math.random() * 999)
1616

1717
await pubSub.createChannel(channelName)
@@ -39,6 +39,7 @@ describe('pubSub', () => {
3939

4040
expect(callbackCalled).toBeTruthy()
4141
} finally {
42+
pubSub.removeChannel(channelName)
4243
connection.close()
4344
pubSub.close()
4445
}
@@ -52,7 +53,7 @@ describe('pubSub', () => {
5253
try {
5354
const channelName = 'test-channel-' + Math.floor(Math.random() * 999)
5455

55-
await pubSub.createChannel(channelName)
56+
await pubSub.createChannel(channelName, false)
5657

5758
await pubSub.listen(PUBSUB_ENTITY_TYPE.CHANNEL, channelName, (error, results, data) => {
5859
expect(true).toBeFalsy()

0 commit comments

Comments
 (0)