Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Commit db56a25

Browse files
committed
modified connection
1 parent 9642fbf commit db56a25

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

‎src/sql/connection/connection.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,30 @@ interface DbNameOption {
2121

2222
interface DbConnectionOption extends DbNameOption {
2323
entities?: (Function | string | EntitySchema<any>)[];
24+
shouldDrop?: boolean;
25+
shouldClear?: boolean;
2426
}
2527

26-
interface DbLoadingOption extends DbConnectionOption {
28+
interface DbLoadingOption extends DbNameOption {
29+
entities?: (Function | string | EntitySchema<any>)[];
2730
database: Uint8Array;
2831
}
2932

3033
export const connectDb = async ({
3134
name = defaultConnectionName,
3235
entities = defaultEntities,
36+
shouldDrop = false,
37+
shouldClear = false,
3338
}: DbConnectionOption) => {
3439
let connection: Connection;
40+
if (shouldClear) {
41+
await window.localforage?.removeItem(name);
42+
}
3543
try {
3644
connection = getConnection(name);
45+
if (!connection.isConnected) {
46+
await connection.connect();
47+
}
3748
} catch (error) {
3849
connection = getConnectionManager().create({
3950
type: 'sqljs',
@@ -45,9 +56,11 @@ export const connectDb = async ({
4556
useLocalForage: true,
4657
logging: !isProd && ['query', 'schema'],
4758
});
48-
}
49-
if (!connection.isConnected) {
50-
await connection.connect();
59+
60+
if (!connection.isConnected) {
61+
await connection.connect();
62+
}
63+
await connection.synchronize(shouldDrop);
5164
}
5265
return connection;
5366
};
@@ -77,7 +90,7 @@ export const loadDbFromFile = async ({
7790
export const createDbUrl = async ({
7891
name = defaultConnectionName,
7992
}: DbNameOption) => {
80-
const connection = getConnection(name);
93+
const connection = awaitconnectDb({name});
8194
const arrayBuffer = connection.sqljsManager.exportDatabase();
8295
const blob = new Blob([arrayBuffer], {
8396
type: 'application/octet-stream',

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /