@zukhruf/sqlite-open 0.8.43 → 0.8.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -146,8 +146,100 @@ A bundler that bundles this package does not copy the `lib` folder. A bundle tha
|
|
|
146
146
|
| Rails 8 | A SQLite database gets a write-ahead log, `journal_size_limit = 67108864` and `synchronous = NORMAL` by default. |
|
|
147
147
|
| `sqlite3 -readonly` | It opens a reader. A missing file fails with "unable to open database file", the text of CANTOPEN. |
|
|
148
148
|
|
|
149
|
+
## API
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
// The options of new DatabaseSync of node:sqlite, without open and readOnly.
|
|
153
|
+
type Settings = Omit<DatabaseSyncOptions, 'open' | 'readOnly'>;
|
|
154
|
+
|
|
155
|
+
// A reader: a read-only connection that never changes the database.
|
|
156
|
+
type ReaderOptions = Settings & {
|
|
157
|
+
readonly readOnly: true;
|
|
158
|
+
readonly journal?: never;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// The connection of the owner, which writes the database and sets its journal.
|
|
162
|
+
type OwnerOptions = Settings & {
|
|
163
|
+
readonly readOnly?: false;
|
|
164
|
+
readonly journal?: Journal; // default: new WriteAheadLog()
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// A reader with readOnly: true, else an owner. The busy timeout is 5000
|
|
168
|
+
// milliseconds unless the caller gives timeout.
|
|
169
|
+
function open(
|
|
170
|
+
path: ConstructorParameters<typeof DatabaseSync>[0],
|
|
171
|
+
options?: ReaderOptions | OwnerOptions,
|
|
172
|
+
): DatabaseSync;
|
|
173
|
+
|
|
174
|
+
interface Journal {
|
|
175
|
+
apply(database: DatabaseSync): void;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// A page size that SQLite accepts: a power of two from 512 to 65536.
|
|
179
|
+
type PageSize = 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768 | 65536;
|
|
180
|
+
|
|
181
|
+
class WriteAheadLog implements Journal {
|
|
182
|
+
constructor(options?: {
|
|
183
|
+
readonly pageSize?: PageSize; // default: the page size of SQLite
|
|
184
|
+
readonly synchronous?: 'normal' | 'full'; // default: 'normal'
|
|
185
|
+
});
|
|
186
|
+
apply(database: DatabaseSync): void;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
class PersistentWriteAheadLog implements Journal {
|
|
190
|
+
constructor(options?: {
|
|
191
|
+
readonly pageSize?: PageSize;
|
|
192
|
+
readonly synchronous?: 'normal' | 'full';
|
|
193
|
+
});
|
|
194
|
+
apply(database: DatabaseSync): void;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
class RollbackJournal implements Journal {
|
|
198
|
+
apply(database: DatabaseSync): void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
class UnchangedJournal implements Journal {
|
|
202
|
+
apply(): void;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
class UnavailableError extends Error {
|
|
206
|
+
readonly path: string;
|
|
207
|
+
constructor(path: string, cause: unknown);
|
|
208
|
+
// A MissingError or a DeniedError when the error says which, else undefined
|
|
209
|
+
// for an error that does not mean a missing or denied file.
|
|
210
|
+
static from(path: string, error: unknown): UnavailableError | undefined;
|
|
211
|
+
}
|
|
212
|
+
class MissingError extends UnavailableError {}
|
|
213
|
+
class DeniedError extends UnavailableError {}
|
|
214
|
+
|
|
215
|
+
// The result code of a SQLite error in its two parts: code is the primary
|
|
216
|
+
// code, the same for each variant, and extendedCode names the variant.
|
|
217
|
+
interface SqliteResultCode {
|
|
218
|
+
readonly code: number;
|
|
219
|
+
readonly extendedCode: number;
|
|
220
|
+
}
|
|
221
|
+
// undefined for a value that node:sqlite did not throw.
|
|
222
|
+
function sqliteResultCode(error: unknown): SqliteResultCode | undefined;
|
|
223
|
+
|
|
224
|
+
const SQLITE_ERROR = 1;
|
|
225
|
+
const SQLITE_BUSY = 5;
|
|
226
|
+
const SQLITE_CANTOPEN = 14;
|
|
227
|
+
const SQLITE_NOTADB = 26;
|
|
228
|
+
const SQLITE_CONSTRAINT_FOREIGNKEY = 787;
|
|
229
|
+
const SQLITE_CONSTRAINT_NOTNULL = 1299;
|
|
230
|
+
const SQLITE_READONLY_DIRECTORY = 1544;
|
|
231
|
+
const SQLITE_CONSTRAINT_UNIQUE = 2067;
|
|
232
|
+
```
|
|
233
|
+
|
|
149
234
|
## Documentation
|
|
150
235
|
|
|
236
|
+
**Recipes**
|
|
237
|
+
|
|
238
|
+
1. [Read the database of another program, and translate an unavailable file at your boundary](./docs/recipes/read-the-database-of-another-program.md)
|
|
239
|
+
2. [Build a database file, then move it into place](./docs/recipes/build-a-database-file-then-move-it-into-place.md)
|
|
240
|
+
|
|
241
|
+
**Decisions**
|
|
242
|
+
|
|
151
243
|
- [0001 One package opens the reader and owns UnavailableError](./docs/adr/0001-one-package-opens-the-reader-and-owns-unavailable-error.md)
|
|
152
244
|
- [0002 One open for readers and owners](./docs/adr/0002-one-open-for-readers-and-owners.md)
|
|
153
245
|
- [0003 Persistent WAL through a native library](./docs/adr/0003-persistent-wal-through-a-native-library.md)
|
|
@@ -178,7 +270,11 @@ src/
|
|
|
178
270
|
rollback-journal.ts RollbackJournal
|
|
179
271
|
unchanged-journal.ts UnchangedJournal
|
|
180
272
|
unavailable-error.ts UnavailableError, MissingError, DeniedError
|
|
273
|
+
result-code.ts sqliteResultCode and the SQLITE_ result codes
|
|
181
274
|
open.test.ts the tests, on real SQLite files and processes
|
|
275
|
+
result-code.test.ts the tests of sqliteResultCode, on real SQLite errors
|
|
276
|
+
testing/
|
|
277
|
+
scratch-directory.ts scratchDirectory, a temporary folder for each test
|
|
182
278
|
native/
|
|
183
279
|
persist_wal.c the native library
|
|
184
280
|
sqlite3.h, sqlite3ext.h the SQLite 3.54.0 headers
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/sqlite-open",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.45",
|
|
4
4
|
"description": "One open for every node:sqlite connection: a reader, or an owner whose journal is a strategy (WAL by default, persistent WAL for readers that cannot write the folder), a 5 s busy timeout, and UnavailableError.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|