sessionDatabase.ts ×13

Frontier kind: Code frontier

unlabeled · c_5b521fe8d3fd

95 tests · 14035 LOC · 48 files · introduces 0 tests · 68 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
13 ranges68 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1217 ranges14035 lines · 48 files · Browse complete extent
All tests (intent)
95 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 68 introduced LOC across 13 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/sessionDatabase.ts 68 introduced LOC · 13 ranges

Open complete file

117 // ---- Promise wrappers around callback-based @vscode/sqlite3 API -----------
118
119 > function dbExec(db: Database, sql: string): Promise<void> { sessionDatabase.ts
120 > return new Promise((resolve, reject) => {
121 > db.exec(sql, err => err ? reject(err) : resolve());
122 > });
123 > }
124
125 function dbRun(db: Database, sql: string, params: unknown[]): Promise<{ changes: number; lastID: number }> {
134 }
135
136 > function dbGet(db: Database, sql: string, params: unknown[]): Promise<Record<string, unknown> | undefined> { sessionDatabase.ts
137 > return new Promise((resolve, reject) => {
138 > db.get(sql, params, (err: Error | null, row: Record<string, unknown> | undefined) => {
139 > if (err) {
140 return reject(err);
141 }
142 > resolve(row); sessionDatabase.ts
143 > });
144 > });
145 > }
146
147 function dbAll(db: Database, sql: string, params: unknown[]): Promise<Record<string, unknown>[]> {
156 }
157
158 > function dbClose(db: Database): Promise<void> { sessionDatabase.ts
159 > return new Promise((resolve, reject) => {
160 > db.close(err => err ? reject(err) : resolve());
161 > });
162 > }
163
164 > function dbOpen(path: string): Promise<Database> { sessionDatabase.ts
165 > return new Promise((resolve, reject) => {
166 > import('@vscode/sqlite3').then(sqlite3 => {
167 > const db = new sqlite3.default.Database(path, (err: Error | null) => {
168 > if (err) {
169 return reject(err);
170 }
171 > resolve(db); sessionDatabase.ts
172 > });
173 > }, reject);
174 > });
175 > }
176
177 /**
181 * migrations complete the pragma is updated to the highest applied version.
182 */
183 > export async function runMigrations(db: Database, migrations: readonly ISessionDatabaseMigration[]): Promise<void> { sessionDatabase.ts
184 > // Enable foreign key enforcement — must be set outside a transaction
185 > // and every time a connection is opened.
186 > await dbExec(db, 'PRAGMA foreign_keys = ON');
187 >
188 > const row = await dbGet(db, 'PRAGMA user_version', []);
189 > const currentVersion = (row?.user_version as number | undefined) ?? 0;
190 >
191 > const pending = migrations
192 > .filter(m => m.version > currentVersion)
193 > .sort((a, b) => a.version - b.version);
194 >
195 > if (pending.length === 0) {
196 return;
197 }
199 > await dbExec(db, 'BEGIN TRANSACTION');
200 > try {
201 > for (const migration of pending) {
202 > await dbExec(db, migration.sql);
203 > // PRAGMA cannot be parameterized; the version is a trusted literal.
204 > await dbExec(db, `PRAGMA user_version = ${migration.version}`);
205 > }
206 > await dbExec(db, 'COMMIT');
207 > } catch (err) {
208 await dbExec(db, 'ROLLBACK');
209 throw err;
210 }
212
213 /**
271 return Promise.reject(new Error('SessionDatabase has been disposed'));
272 }
273 > if (!this._dbPromise) { sessionDatabase.ts
274 > this._dbPromise = (async () => {
275 > // Ensure the parent directory exists before SQLite tries to
276 > // create the database file.
277 > await fs.promises.mkdir(dirname(this._path), { recursive: true });
278 > const db = await dbOpen(this._path);
279 > try {
280 > await runMigrations(db, this._migrations);
281 > } catch (err) {
282 await dbClose(db);
283 this._dbPromise = undefined;
284 throw err;
285 }
286 > // If dispose() was called while we were opening, close immediately. sessionDatabase.ts
287 > if (this._closed) {
288 await dbClose(db);
289 throw new Error('SessionDatabase has been disposed');
290 }
291 > return db; sessionDatabase.ts
292 > })().catch(err => {
293 this._dbPromise = undefined;
294 throw err;
295 > }); sessionDatabase.ts
296 > }
297 > return this._dbPromise;
298 }
299