Skip to content

Commit 1dab23a

Browse files
Add eventEmitter, close #16
1 parent 5667ad5 commit 1dab23a

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
},
4242
"homepage": "https://github.com/sqlitecloud/sqlitecloud-js#readme",
4343
"dependencies": {
44+
"eventemitter3": "^5.0.1",
4445
"lz4": "^0.6.5"
4546
},
4647
"devDependencies": {
@@ -58,10 +59,10 @@
5859
"lint-staged": "^13.2.1",
5960
"prettier": "^2.2.1",
6061
"sqlite3": "^5.1.6",
61-
"typedoc-plugin-markdown": "^3.17.1",
6262
"ts-jest": "^29.1.1",
6363
"ts-node": "^10.9.1",
6464
"typedoc": "^0.25.3",
65+
"typedoc-plugin-markdown": "^3.17.1",
6566
"typescript": "^4.9.5"
6667
},
6768
"config": {},

src/database.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ export class Database extends EventEmitter {
352352
}
353353
}
354354
callback?.call(this, null)
355+
this.emitEvent('close')
355356
}
356357

357358
/**

test/compare.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ describe('Database.on', () => {
7474
chinookCloud.exec('BOGUS SQL MEISTER;')
7575
})
7676

77+
it('sqlite3: should emit close event', done => {
78+
const chinookFile = getChinookDatabaseFile()
79+
chinookFile.on('close', () => {
80+
done()
81+
})
82+
chinookFile.close()
83+
})
84+
85+
it('sqlitecloud: should emit close event', done => {
86+
const chinookCloud = getChinookDatabase()
87+
chinookCloud.once('close', () => {
88+
done()
89+
})
90+
chinookCloud.close()
91+
})
92+
7793
// end Database.on
7894
})
7995

test/connection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('connection', () => {
4242
expect(localConfig.tlsOptions?.ca).toBeTruthy()
4343

4444
const remoteConfig = getChinoookConfig('sqlitecloud://admin:xxx@sqlitecloud.io:8850/chinook.db')
45-
expect(remoteConfig.host).toBe('yahoo.com')
45+
expect(remoteConfig.host).toBe('sqlitecloud.io')
4646
expect(remoteConfig.tlsOptions).toBeFalsy()
4747
})
4848

0 commit comments

Comments
 (0)