Skip to content

Commit 4059bdb

Browse files
authored
Cleaning up some leftovers from #7836 (#7982)
* Cleaning up some leftovers from #7836 * Close the conn too
1 parent 08aa6e2 commit 4059bdb

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

firebase-vscode/package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@
8080
}
8181
}
8282
},
83-
"keybindings": [
84-
{
85-
"command": "firebase.dataConnect.executeOperationAtCursor",
86-
"key": "ctrl+enter",
87-
"mac": "cmd+enter",
88-
"when": "editorLangId == gql || editorLangId == graphql"
89-
}
90-
],
9183
"viewsContainers": {
9284
"activitybar": [
9385
{

src/emulator/dataconnect/pgliteServer.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ import {
1717
} from "./pg-gateway/index";
1818
import { fromNodeSocket } from "./pg-gateway/platforms/node";
1919
import { logger } from "../../logger";
20+
export const TRUNCATE_TABLES_SQL = `
21+
DO $do$
22+
BEGIN
23+
EXECUTE
24+
(SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE'
25+
FROM pg_class
26+
WHERE relkind = 'r'
27+
AND relnamespace = 'public'::regnamespace
28+
);
29+
END
30+
$do$;`;
2031

2132
export class PostgresServer {
2233
private username: string;
@@ -95,17 +106,7 @@ export class PostgresServer {
95106

96107
public async clearDb(): Promise<void> {
97108
const db = await this.getDb();
98-
await db.query(`
99-
DO $do$
100-
BEGIN
101-
EXECUTE
102-
(SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE'
103-
FROM pg_class
104-
WHERE relkind = 'r'
105-
AND relnamespace = 'public'::regnamespace
106-
);
107-
END
108-
$do$;`);
109+
await db.query(TRUNCATE_TABLES_SQL);
109110
}
110111

111112
public async exportData(exportPath: string): Promise<void> {

src/emulator/dataconnectEmulator.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as childProcess from "child_process";
2+
import * as pg from "pg";
23
import { EventEmitter } from "events";
34
import * as clc from "colorette";
45
import * as path from "path";
@@ -17,7 +18,7 @@ import { EmulatorRegistry } from "./registry";
1718
import { logger } from "../logger";
1819
import { load } from "../dataconnect/load";
1920
import { Config } from "../config";
20-
import { PostgresServer } from "./dataconnect/pgliteServer";
21+
import { PostgresServer, TRUNCATE_TABLES_SQL } from "./dataconnect/pgliteServer";
2122
import { cleanShutdown } from "./controller";
2223
import { connectableHostname } from "../utils";
2324

@@ -180,6 +181,10 @@ export class DataConnectEmulator implements EmulatorInstance {
180181
async clearData(): Promise<void> {
181182
if (this.postgresServer) {
182183
await this.postgresServer.clearDb();
184+
} else {
185+
const conn = new pg.Client(dataConnectLocalConnString());
186+
await conn.query(TRUNCATE_TABLES_SQL);
187+
await conn.end();
183188
}
184189
}
185190

src/emulator/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ export const DOWNLOADABLE_EMULATORS = [
3636
Emulators.DATACONNECT,
3737
];
3838

39-
export type ImportExportEmulators = Emulators.FIRESTORE | Emulators.DATABASE | Emulators.AUTH;
39+
export type ImportExportEmulators =
40+
| Emulators.FIRESTORE
41+
| Emulators.DATABASE
42+
| Emulators.AUTH
43+
| Emulators.STORAGE
44+
| Emulators.DATACONNECT;
4045
export const IMPORT_EXPORT_EMULATORS = [
4146
Emulators.FIRESTORE,
4247
Emulators.DATABASE,

0 commit comments

Comments
 (0)