Skip to content

Commit 493f9cf

Browse files
authored
Revert filename optional; update filename checks instead (#125)
* Revert filename optional; update filename checks instead The `filename` property is back to being required, but empty strings are valid values for the purpose of using an anonymous disk-based database. Values of `undefined` or `null` for `filename` will throw.
1 parent 02f30f3 commit 493f9cf

14 files changed

+56
-56
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ const db = await open({
217217
* Anonymous databases are not persisted and when closing the database
218218
* handle, their contents are lost.
219219
*/
220-
filename?: string
220+
filename: string
221221

222222
/**
223223
* One or more of sqlite3.OPEN_READONLY, sqlite3.OPEN_READWRITE and

docs/classes/_src_database_.database.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Promisified wrapper for the sqlite3#Database interface.
4949

5050
\+ **new Database**(`config`: [Config](../interfaces/_src_interfaces_.isqlite.config.md)): *[Database](_src_database_.database.md)*
5151

52-
*Defined in [src/Database.ts:18](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L18)*
52+
*Defined in [src/Database.ts:18](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L18)*
5353

5454
**Parameters:**
5555

@@ -65,23 +65,23 @@ Name | Type |
6565

6666
**config**: *[Config](../interfaces/_src_interfaces_.isqlite.config.md)*
6767

68-
*Defined in [src/Database.ts:17](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L17)*
68+
*Defined in [src/Database.ts:17](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L17)*
6969

7070
___
7171

7272
### db
7373

7474
**db**: *Driver*
7575

76-
*Defined in [src/Database.ts:18](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L18)*
76+
*Defined in [src/Database.ts:18](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L18)*
7777

7878
## Methods
7979

8080
### all
8181

8282
**all****T**›(`sql`: [SqlType](../modules/_src_interfaces_.isqlite.md#sqltype), ...`params`: any[]): *Promise‹T›*
8383

84-
*Defined in [src/Database.ts:255](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L255)*
84+
*Defined in [src/Database.ts:255](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L255)*
8585

8686
Runs the SQL query with the specified parameters. The parameters are the same as the
8787
Database#run function, with the following differences:
@@ -116,7 +116,7 @@ ___
116116

117117
**close**(): *Promise‹void›*
118118

119-
*Defined in [src/Database.ts:79](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L79)*
119+
*Defined in [src/Database.ts:79](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L79)*
120120

121121
Closes the database.
122122

@@ -128,7 +128,7 @@ ___
128128

129129
**configure**(`option`: [ConfigureOption](../modules/_src_interfaces_.isqlite.md#configureoption), `value`: any): *any*
130130

131-
*Defined in [src/Database.ts:94](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L94)*
131+
*Defined in [src/Database.ts:94](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L94)*
132132

133133
**`see`** https://github.com/mapbox/node-sqlite3/wiki/API#databaseconfigureoption-value
134134

@@ -147,7 +147,7 @@ ___
147147

148148
**each****T**›(`sql`: [SqlType](../modules/_src_interfaces_.isqlite.md#sqltype), ...`params`: any[]): *Promise‹number›*
149149

150-
*Defined in [src/Database.ts:187](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L187)*
150+
*Defined in [src/Database.ts:187](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L187)*
151151

152152
Runs the SQL query with the specified parameters and calls the callback once for each result
153153
row. The parameters are the same as the Database#run function, with the following differences:
@@ -188,7 +188,7 @@ ___
188188

189189
**exec**(`sql`: [SqlType](../modules/_src_interfaces_.isqlite.md#sqltype)): *Promise‹void›*
190190

191-
*Defined in [src/Database.ts:280](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L280)*
191+
*Defined in [src/Database.ts:280](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L280)*
192192

193193
Runs all SQL queries in the supplied string. No result rows are retrieved. If a query fails,
194194
no subsequent statements will be executed (wrap it in a transaction if you want all
@@ -213,7 +213,7 @@ ___
213213

214214
**get****T**›(`sql`: [SqlType](../modules/_src_interfaces_.isqlite.md#sqltype), ...`params`: any[]): *Promise‹T | undefined›*
215215

216-
*Defined in [src/Database.ts:150](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L150)*
216+
*Defined in [src/Database.ts:150](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L150)*
217217

218218
Runs the SQL query with the specified parameters and resolves with
219219
with the first result row afterwards. If the result set is empty, returns undefined.
@@ -242,7 +242,7 @@ ___
242242

243243
**getDatabaseInstance**(): *Driver*
244244

245-
*Defined in [src/Database.ts:36](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L36)*
245+
*Defined in [src/Database.ts:36](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L36)*
246246

247247
Returns the underlying sqlite3 Database instance
248248

@@ -254,7 +254,7 @@ ___
254254

255255
**loadExtension**(`path`: string): *Promise‹unknown›*
256256

257-
*Defined in [src/Database.ts:325](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L325)*
257+
*Defined in [src/Database.ts:325](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L325)*
258258

259259
Loads a compiled SQLite extension into the database connection object.
260260

@@ -272,7 +272,7 @@ ___
272272

273273
**migrate**(`config?`: [MigrationParams](../interfaces/_src_interfaces_.imigrate.migrationparams.md)): *Promise‹void›*
274274

275-
*Defined in [src/Database.ts:340](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L340)*
275+
*Defined in [src/Database.ts:340](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L340)*
276276

277277
Performs a database migration.
278278

@@ -290,7 +290,7 @@ ___
290290

291291
**on**(`event`: string, `listener`: any): *void*
292292

293-
*Defined in [src/Database.ts:29](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L29)*
293+
*Defined in [src/Database.ts:29](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L29)*
294294

295295
Event handler when verbose mode is enabled.
296296

@@ -311,7 +311,7 @@ ___
311311

312312
**open**(): *Promise‹void›*
313313

314-
*Defined in [src/Database.ts:43](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L43)*
314+
*Defined in [src/Database.ts:43](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L43)*
315315

316316
Opens the database
317317

@@ -323,7 +323,7 @@ ___
323323

324324
**parallelize**(): *void*
325325

326-
*Defined in [src/Database.ts:360](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L360)*
326+
*Defined in [src/Database.ts:360](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L360)*
327327

328328
**Returns:** *void*
329329

@@ -333,7 +333,7 @@ ___
333333

334334
**prepare**(`sql`: [SqlType](../modules/_src_interfaces_.isqlite.md#sqltype), ...`params`: any[]): *Promise‹[Statement](_src_statement_.statement.md)‹Stmt››*
335335

336-
*Defined in [src/Database.ts:306](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L306)*
336+
*Defined in [src/Database.ts:306](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L306)*
337337

338338
Prepares the SQL statement and optionally binds the specified parameters.
339339
When bind parameters are supplied, they are bound to the prepared statement.
@@ -355,7 +355,7 @@ ___
355355

356356
**run**(`sql`: [SqlType](../modules/_src_interfaces_.isqlite.md#sqltype), ...`params`: any[]): *Promise‹[RunResult](../interfaces/_src_interfaces_.isqlite.runresult.md)‹Stmt››*
357357

358-
*Defined in [src/Database.ts:112](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L112)*
358+
*Defined in [src/Database.ts:112](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L112)*
359359

360360
Runs the SQL query with the specified parameters. It does not retrieve any result data.
361361
The function returns the Database object for which it was called to allow for function chaining.
@@ -377,7 +377,7 @@ ___
377377

378378
**serialize**(): *void*
379379

380-
*Defined in [src/Database.ts:351](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Database.ts#L351)*
380+
*Defined in [src/Database.ts:351](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Database.ts#L351)*
381381

382382
The methods underneath requires creative work to implement. PRs / proposals accepted!
383383

docs/classes/_src_statement_.statement.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Promisified wrapper for the sqlite3#Statement interface.
3939

4040
\+ **new Statement**(`stmt`: S): *[Statement](_src_statement_.statement.md)*
4141

42-
*Defined in [src/Statement.ts:8](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L8)*
42+
*Defined in [src/Statement.ts:8](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L8)*
4343

4444
**Parameters:**
4545

@@ -55,15 +55,15 @@ Name | Type |
5555

5656
**stmt**: *S*
5757

58-
*Defined in [src/Statement.ts:8](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L8)*
58+
*Defined in [src/Statement.ts:8](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L8)*
5959

6060
## Methods
6161

6262
### all
6363

6464
**all****T**›(...`params`: any[]): *Promise‹T›*
6565

66-
*Defined in [src/Statement.ts:146](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L146)*
66+
*Defined in [src/Statement.ts:146](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L146)*
6767

6868
Binds parameters, executes the statement and calls the callback with all result rows.
6969
The parameters are the same as the Statement#run function, with the following differences:
@@ -92,7 +92,7 @@ ___
9292

9393
**bind**(...`params`: any[]): *Promise‹void›*
9494

95-
*Defined in [src/Statement.ts:27](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L27)*
95+
*Defined in [src/Statement.ts:27](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L27)*
9696

9797
Binds parameters to the prepared statement.
9898

@@ -113,7 +113,7 @@ ___
113113

114114
**each****T**›(...`params`: any[]): *Promise‹number›*
115115

116-
*Defined in [src/Statement.ts:180](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L180)*
116+
*Defined in [src/Statement.ts:180](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L180)*
117117

118118
Binds parameters, executes the statement and calls the callback for each result row.
119119

@@ -155,7 +155,7 @@ ___
155155

156156
**finalize**(): *Promise‹void›*
157157

158-
*Defined in [src/Statement.ts:58](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L58)*
158+
*Defined in [src/Statement.ts:58](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L58)*
159159

160160
Finalizes the statement. This is typically optional, but if you experience long delays before
161161
the next query is executed, explicitly finalizing your statement might be necessary.
@@ -171,7 +171,7 @@ ___
171171

172172
**get****T**›(...`params`: any[]): *Promise‹T | undefined›*
173173

174-
*Defined in [src/Statement.ts:118](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L118)*
174+
*Defined in [src/Statement.ts:118](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L118)*
175175

176176
Binds parameters, executes the statement and retrieves the first result row.
177177
The parameters are the same as the Statement#run function, with the following differences:
@@ -199,7 +199,7 @@ ___
199199

200200
**getStatementInstance**(): *S*
201201

202-
*Defined in [src/Statement.ts:17](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L17)*
202+
*Defined in [src/Statement.ts:17](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L17)*
203203

204204
Returns the underlying sqlite3 Statement instance
205205

@@ -211,7 +211,7 @@ ___
211211

212212
**reset**(): *Promise‹void›*
213213

214-
*Defined in [src/Statement.ts:43](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L43)*
214+
*Defined in [src/Statement.ts:43](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L43)*
215215

216216
Resets the row cursor of the statement and preserves the parameter bindings.
217217
Use this function to re-execute the same query with the same bindings.
@@ -224,7 +224,7 @@ ___
224224

225225
**run**(...`params`: any[]): *Promise‹[RunResult](../interfaces/_src_interfaces_.isqlite.runresult.md)*
226226

227-
*Defined in [src/Statement.ts:85](https://github.com/kriasoft/node-sqlite/blob/244b720/src/Statement.ts#L85)*
227+
*Defined in [src/Statement.ts:85](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/Statement.ts#L85)*
228228

229229
Binds parameters and executes the statement.
230230

docs/interfaces/_src_interfaces_.imigrate.migrationfile.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,36 @@
2222

2323
**down**? : *string*
2424

25-
*Defined in [src/interfaces.ts:103](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L103)*
25+
*Defined in [src/interfaces.ts:103](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L103)*
2626

2727
___
2828

2929
### filename
3030

3131
**filename**: *string*
3232

33-
*Defined in [src/interfaces.ts:101](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L101)*
33+
*Defined in [src/interfaces.ts:101](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L101)*
3434

3535
___
3636

3737
### id
3838

3939
**id**: *number*
4040

41-
*Defined in [src/interfaces.ts:99](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L99)*
41+
*Defined in [src/interfaces.ts:99](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L99)*
4242

4343
___
4444

4545
### name
4646

4747
**name**: *string*
4848

49-
*Defined in [src/interfaces.ts:100](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L100)*
49+
*Defined in [src/interfaces.ts:100](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L100)*
5050

5151
___
5252

5353
### `Optional` up
5454

5555
**up**? : *string*
5656

57-
*Defined in [src/interfaces.ts:102](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L102)*
57+
*Defined in [src/interfaces.ts:102](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L102)*

docs/interfaces/_src_interfaces_.imigrate.migrationparams.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
**force**? : *boolean*
2222

23-
*Defined in [src/interfaces.ts:87](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L87)*
23+
*Defined in [src/interfaces.ts:87](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L87)*
2424

2525
If true, will force the migration API to rollback and re-apply the latest migration over
2626
again each time when Node.js app launches.
@@ -31,7 +31,7 @@ ___
3131

3232
**migrationsPath**? : *string*
3333

34-
*Defined in [src/interfaces.ts:95](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L95)*
34+
*Defined in [src/interfaces.ts:95](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L95)*
3535

3636
Path to the migrations folder. Default is `path.join(process.cwd(), 'migrations')`
3737

@@ -41,6 +41,6 @@ ___
4141

4242
**table**? : *string*
4343

44-
*Defined in [src/interfaces.ts:91](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L91)*
44+
*Defined in [src/interfaces.ts:91](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L91)*
4545

4646
Migrations table name. Default is 'migrations'

docs/interfaces/_src_interfaces_.isqlite.config.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
### Properties
1212

1313
* [driver](_src_interfaces_.isqlite.config.md#driver)
14-
* [filename](_src_interfaces_.isqlite.config.md#optional-filename)
14+
* [filename](_src_interfaces_.isqlite.config.md#filename)
1515
* [mode](_src_interfaces_.isqlite.config.md#optional-mode)
1616

1717
## Properties
@@ -20,7 +20,7 @@
2020

2121
**driver**: *any*
2222

23-
*Defined in [src/interfaces.ts:48](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L48)*
23+
*Defined in [src/interfaces.ts:48](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L48)*
2424

2525
The database driver. Most will install `sqlite3` and use the `Database` class from it.
2626
As long as the library you are using conforms to the `sqlite3` API, you can use it as
@@ -36,11 +36,11 @@ const driver = sqlite.Database
3636

3737
___
3838

39-
### `Optional` filename
39+
### filename
4040

41-
**filename**? : *string*
41+
**filename**: *string*
4242

43-
*Defined in [src/interfaces.ts:27](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L27)*
43+
*Defined in [src/interfaces.ts:27](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L27)*
4444

4545
Valid values are filenames, ":memory:" for an anonymous in-memory
4646
database and an empty string for an anonymous disk-based database.
@@ -53,7 +53,7 @@ ___
5353

5454
**mode**? : *number*
5555

56-
*Defined in [src/interfaces.ts:33](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L33)*
56+
*Defined in [src/interfaces.ts:33](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L33)*
5757

5858
One or more of sqlite3.OPEN_READONLY, sqlite3.OPEN_READWRITE and
5959
sqlite3.OPEN_CREATE. The default value is OPEN_READWRITE | OPEN_CREATE.

docs/interfaces/_src_interfaces_.isqlite.runresult.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
**changes**? : *number*
2626

27-
*Defined in [src/interfaces.ts:77](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L77)*
27+
*Defined in [src/interfaces.ts:77](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L77)*
2828

2929
Number of rows changed.
3030

@@ -37,7 +37,7 @@ ___
3737

3838
**lastID**? : *number*
3939

40-
*Defined in [src/interfaces.ts:70](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L70)*
40+
*Defined in [src/interfaces.ts:70](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L70)*
4141

4242
Row id of the inserted row.
4343

@@ -50,7 +50,7 @@ ___
5050

5151
**stmt**: *[Statement](../classes/_src_statement_.statement.md)‹Stmt›*
5252

53-
*Defined in [src/interfaces.ts:63](https://github.com/kriasoft/node-sqlite/blob/244b720/src/interfaces.ts#L63)*
53+
*Defined in [src/interfaces.ts:63](https://github.com/kriasoft/node-sqlite/blob/d15b22e/src/interfaces.ts#L63)*
5454

5555
Statement object.
5656

0 commit comments

Comments
 (0)