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 80
80
}
81
81
}
82
82
},
83
- "keybindings" : [
84
- {
85
- "command" : " firebase.dataConnect.executeOperationAtCursor" ,
86
- "key" : " ctrl+enter" ,
87
- "mac" : " cmd+enter" ,
88
- "when" : " editorLangId == gql || editorLangId == graphql"
89
- }
90
- ],
91
83
"viewsContainers" : {
92
84
"activitybar" : [
93
85
{
Original file line number Diff line number Diff line change @@ -17,6 +17,17 @@ import {
17
17
} from "./pg-gateway/index" ;
18
18
import { fromNodeSocket } from "./pg-gateway/platforms/node" ;
19
19
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$;` ;
20
31
21
32
export class PostgresServer {
22
33
private username : string ;
@@ -95,17 +106,7 @@ export class PostgresServer {
95
106
96
107
public async clearDb ( ) : Promise < void > {
97
108
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 ) ;
109
110
}
110
111
111
112
public async exportData ( exportPath : string ) : Promise < void > {
Original file line number Diff line number Diff line change 1
1
import * as childProcess from "child_process" ;
2
+ import * as pg from "pg" ;
2
3
import { EventEmitter } from "events" ;
3
4
import * as clc from "colorette" ;
4
5
import * as path from "path" ;
@@ -17,7 +18,7 @@ import { EmulatorRegistry } from "./registry";
17
18
import { logger } from "../logger" ;
18
19
import { load } from "../dataconnect/load" ;
19
20
import { Config } from "../config" ;
20
- import { PostgresServer } from "./dataconnect/pgliteServer" ;
21
+ import { PostgresServer , TRUNCATE_TABLES_SQL } from "./dataconnect/pgliteServer" ;
21
22
import { cleanShutdown } from "./controller" ;
22
23
import { connectableHostname } from "../utils" ;
23
24
@@ -180,6 +181,10 @@ export class DataConnectEmulator implements EmulatorInstance {
180
181
async clearData ( ) : Promise < void > {
181
182
if ( this . postgresServer ) {
182
183
await this . postgresServer . clearDb ( ) ;
184
+ } else {
185
+ const conn = new pg . Client ( dataConnectLocalConnString ( ) ) ;
186
+ await conn . query ( TRUNCATE_TABLES_SQL ) ;
187
+ await conn . end ( ) ;
183
188
}
184
189
}
185
190
Original file line number Diff line number Diff line change @@ -36,7 +36,12 @@ export const DOWNLOADABLE_EMULATORS = [
36
36
Emulators . DATACONNECT ,
37
37
] ;
38
38
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 ;
40
45
export const IMPORT_EXPORT_EMULATORS = [
41
46
Emulators . FIRESTORE ,
42
47
Emulators . DATABASE ,
You can’t perform that action at this time.
0 commit comments