Skip to content

Commit bbd7c23

Browse files
author
Daniele Briggi
committed
fix(connection): suggestions
1 parent 6d0a24c commit bbd7c23

File tree

7 files changed

+8
-12
lines changed

7 files changed

+8
-12
lines changed

examples/with-javascript-expo/db/dbConnection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Database } from "@sqlitecloud/drivers";
66
*/
77
let database = null;
88

9-
export function getDbConnection() {
9+
export default function getDbConnection() {
1010
if (!database || !database.isConnected()) {
1111
database = new Database(DATABASE_URL);
1212
}

examples/with-javascript-vite/src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let db = null
55

66
function getDatabase() {
77
if (!db || !db.isConnected()) {
8-
db = new Database("chinook.sqlite");
8+
db = new Database(import.meta.env.VITE_DATABASE_URL);
99
}
1010

1111
return db;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/drivers/connection-tls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export class SQLiteCloudTlsConnection extends SQLiteCloudConnection {
250250
}
251251

252252
/** Disconnect immediately, release connection, no events. */
253-
public close(): this {
253+
close(): this {
254254
if (this.socket) {
255255
this.socket.removeAllListeners()
256256
this.socket.destroy()

src/drivers/connection-ws.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {
3939

4040
this.socket.on('disconnect', (reason) => {
4141
this.close()
42-
callback?.call(this, new SQLiteCloudError('Disconnected', { errorCode: 'ERR_CONNECTION_DISCONNECTED', cause: reason }))
42+
callback?.call(this, new SQLiteCloudError('Disconnected', { errorCode: 'ERR_CONNECTION_ENDED', cause: reason }))
4343
})
4444

4545
this.socket.on('error', (error: Error) => {

test/connection-tls.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ it(
6060
const connection = new SQLiteCloudTlsConnection(configObj, error => {
6161
expect(error).toBeNull()
6262
expect(connection.connected).toBe(true)
63-
done()
6463
connection.close()
64+
done()
6565
})
66-
expect(connection).toBeDefined()
6766
},
6867
LONG_TIMEOUT
6968
)
@@ -82,7 +81,6 @@ it(
8281
done()
8382
})
8483
})
85-
expect(connection).toBeDefined()
8684
},
8785
LONG_TIMEOUT
8886
)
@@ -103,7 +101,6 @@ it(
103101
done()
104102
})
105103
})
106-
expect(connection).toBeDefined()
107104
} catch (error) {
108105
console.error(`An error occurred while connecting using api key: ${error}`)
109106
debugger
@@ -142,7 +139,6 @@ it(
142139
}
143140
})
144141
})
145-
expect(connection).toBeDefined()
146142
})
147143

148144
it('should connect with insecure connection string', done => {

test/connection-ws.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ describe('connection-ws', () => {
4040
let connection: SQLiteCloudWebsocketConnection | null = null
4141
connection = new SQLiteCloudWebsocketConnection(configObj, error => {
4242
expect(error).toBeNull()
43-
done()
4443
connection?.close()
44+
done()
4545
})
4646
})
4747

0 commit comments

Comments
 (0)