Skip to content

Commit 10606d0

Browse files
committed
fix: remove pub sub
1 parent 73a0c52 commit 10606d0

5 files changed

Lines changed: 4 additions & 387 deletions

File tree

README.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,6 @@ We aim for full compatibility with the established [sqlite3 API](https://www.npm
7070

7171
The package is developed entirely in TypeScript and is fully compatible with JavaScript. It doesn't require any native libraries. This makes it a straightforward and effective tool for managing cloud-based databases in a familiar SQLite environment.
7272

73-
## Publish / Subscribe (Pub/Sub)
74-
75-
```ts
76-
import { Database } from '@sqlitecloud/drivers'
77-
import { PubSub, PUBSUB_ENTITY_TYPE } from '@sqlitecloud/drivers/lib/drivers/pubsub'
78-
79-
let database = new Database('sqlitecloud://user:password@xxx.sqlite.cloud:8860/chinook.sqlite')
80-
// or use sqlitecloud://xxx.sqlite.cloud:8860?apikey=xxxxxxx
81-
82-
const pubSub: PubSub = await database.getPubSub()
83-
84-
await pubSub.listen(PUBSUB_ENTITY_TYPE.TABLE, 'albums', (error, results, data) => {
85-
if (results) {
86-
// Changes on albums table will be received here as JSON object
87-
console.log('Received message:', results)
88-
}
89-
})
90-
91-
await database.sql("INSERT INTO albums (Title, ArtistId) values ('Brand new song', 1)")
92-
93-
// Stop listening changes on the table
94-
await pubSub.unlisten(PUBSUB_ENTITY_TYPE.TABLE, 'albums')
95-
```
96-
97-
Pub/Sub is a messaging pattern that allows multiple applications to communicate with each other asynchronously. In the context of SQLiteCloud, Pub/Sub can be used to provide real-time updates and notifications to subscribed applications whenever data changes in the database or it can be used to send payloads (messages) to anyone subscribed to a channel.
98-
99-
Pub/Sub Documentation: [https://docs.sqlitecloud.io/docs/pub-sub](https://docs.sqlitecloud.io/docs/pub-sub)
100-
10173
## Examples
10274

10375
Check out all the supported platforms with related examples [here](https://github.com/sqlitecloud/sqlitecloud-js/tree/main/examples)!

src/drivers/database.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import EventEmitter from 'eventemitter3'
1111
import { SQLiteCloudConnection } from './connection'
12-
import { PubSub } from './pubsub'
1312
import { OperationsQueue } from './queue'
1413
import { SQLiteCloudRowset } from './rowset'
1514
import { Statement } from './statement'
@@ -386,7 +385,7 @@ export class Database extends EventEmitter {
386385
public close(callback?: ConnectionCallback): void {
387386
this.operations.enqueue(done => {
388387
this.connection?.close()
389-
388+
390389
callback?.call(this, null)
391390
this.emitEvent('close')
392391

@@ -477,30 +476,4 @@ export class Database extends EventEmitter {
477476
public isConnected(): boolean {
478477
return this.connection != null && this.connection.connected
479478
}
480-
481-
/**
482-
* PubSub class provides a Pub/Sub real-time updates and notifications system to
483-
* allow multiple applications to communicate with each other asynchronously.
484-
* It allows applications to subscribe to tables and receive notifications whenever
485-
* data changes in the database table. It also enables sending messages to anyone
486-
* subscribed to a specific channel.
487-
* @returns {PubSub} A PubSub object
488-
*/
489-
public async getPubSub(): Promise<PubSub> {
490-
return new Promise((resolve, reject) => {
491-
this.operations.enqueue(done => {
492-
let error = null
493-
try {
494-
if (!this.connection) {
495-
error = new SQLiteCloudError('Connection not established', { errorCode: 'ERR_CONNECTION_NOT_ESTABLISHED' })
496-
reject(error)
497-
} else {
498-
resolve(new PubSub(this.connection))
499-
}
500-
} finally {
501-
done(error)
502-
}
503-
})
504-
})
505-
}
506479
}

src/drivers/pubsub.ts

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/drivers/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ if (SAFE_INTEGER_MODE == 'bigint') {
3535
console.debug('BigInt mode: Using Number for all INTEGER values from SQLite, including meta information from WRITE statements.')
3636
}
3737
if (SAFE_INTEGER_MODE == 'mixed') {
38-
console.debug('Mixed mode: Using BigInt for INTEGER values from SQLite (including meta information from WRITE statements) bigger then 2^53, Number otherwise.')
38+
console.debug(
39+
'Mixed mode: Using BigInt for INTEGER values from SQLite (including meta information from WRITE statements) bigger then 2^53, Number otherwise.'
40+
)
3941
}
4042

4143
/**
@@ -178,7 +180,6 @@ export type ResultsCallback<T = any> = (error: Error | null, results?: T) => voi
178180
export type RowsCallback<T = Record<string, any>> = (error: Error | null, rows?: T[]) => void
179181
export type RowCallback<T = Record<string, any>> = (error: Error | null, row?: T) => void
180182
export type RowCountCallback = (error: Error | null, rowCount?: number) => void
181-
export type PubSubCallback<T = any> = (error: Error | null, results?: T, extraData?: T) => void
182183

183184
/**
184185
* Certain responses include arrays with various types of metadata.

0 commit comments

Comments
 (0)