File tree Expand file tree Collapse file tree 4 files changed +24
-21
lines changed Expand file tree Collapse file tree 4 files changed +24
-21
lines changed Original file line number Diff line number Diff line change 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 {
Original file line number Diff line number Diff line change @@ -17,6 +17,17 @@ import {
1717} from "./pg-gateway/index" ;
1818import { fromNodeSocket } from "./pg-gateway/platforms/node" ;
1919import { 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
2132export 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 > {
Original file line number Diff line number Diff line change 11import * as childProcess from "child_process" ;
2+ import * as pg from "pg" ;
23import { EventEmitter } from "events" ;
34import * as clc from "colorette" ;
45import * as path from "path" ;
@@ -17,7 +18,7 @@ import { EmulatorRegistry } from "./registry";
1718import { logger } from "../logger" ;
1819import { load } from "../dataconnect/load" ;
1920import { Config } from "../config" ;
20- import { PostgresServer } from "./dataconnect/pgliteServer" ;
21+ import { PostgresServer , TRUNCATE_TABLES_SQL } from "./dataconnect/pgliteServer" ;
2122import { cleanShutdown } from "./controller" ;
2223import { 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
Original file line number Diff line number Diff 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 ;
4045export const IMPORT_EXPORT_EMULATORS = [
4146 Emulators . FIRESTORE ,
4247 Emulators . DATABASE ,
You can’t perform that action at this time.
0 commit comments