@hot-updater/postgres 0.6.5 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -4
- package/dist/index.js +12 -4
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,10 @@ const postgres = (config, hooks)=>(_)=>{
|
|
|
39
39
|
dialect
|
|
40
40
|
});
|
|
41
41
|
let bundles = [];
|
|
42
|
+
const changedIds = new Set();
|
|
43
|
+
function markChanged(id) {
|
|
44
|
+
changedIds.add(id);
|
|
45
|
+
}
|
|
42
46
|
let isUnmount = false;
|
|
43
47
|
return {
|
|
44
48
|
name: "postgres",
|
|
@@ -46,10 +50,14 @@ const postgres = (config, hooks)=>(_)=>{
|
|
|
46
50
|
if (isUnmount) return;
|
|
47
51
|
isUnmount = true;
|
|
48
52
|
await pool.end();
|
|
53
|
+
changedIds.clear();
|
|
49
54
|
},
|
|
50
55
|
async commitBundle () {
|
|
56
|
+
if (0 === changedIds.size) return;
|
|
57
|
+
const changedBundles = bundles.filter((b)=>changedIds.has(b.id));
|
|
58
|
+
if (0 === changedBundles.length) return;
|
|
51
59
|
await db.transaction().execute(async (tx)=>{
|
|
52
|
-
for (const bundle of
|
|
60
|
+
for (const bundle of changedBundles)await tx.insertInto("bundles").values({
|
|
53
61
|
id: bundle.id,
|
|
54
62
|
enabled: bundle.enabled,
|
|
55
63
|
file_url: bundle.fileUrl,
|
|
@@ -70,6 +78,7 @@ const postgres = (config, hooks)=>(_)=>{
|
|
|
70
78
|
target_app_version: bundle.targetAppVersion
|
|
71
79
|
})).execute();
|
|
72
80
|
});
|
|
81
|
+
changedIds.clear();
|
|
73
82
|
hooks?.onDatabaseUpdated?.();
|
|
74
83
|
},
|
|
75
84
|
async updateBundle (targetBundleId, newBundle) {
|
|
@@ -77,13 +86,12 @@ const postgres = (config, hooks)=>(_)=>{
|
|
|
77
86
|
const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
|
|
78
87
|
if (-1 === targetIndex) throw new Error("target bundle version not found");
|
|
79
88
|
Object.assign(bundles[targetIndex], newBundle);
|
|
89
|
+
markChanged(targetBundleId);
|
|
80
90
|
},
|
|
81
91
|
async appendBundle (inputBundle) {
|
|
82
92
|
bundles = await this.getBundles();
|
|
83
93
|
bundles.unshift(inputBundle);
|
|
84
|
-
|
|
85
|
-
async setBundles (inputBundles) {
|
|
86
|
-
bundles = inputBundles;
|
|
94
|
+
markChanged(inputBundle.id);
|
|
87
95
|
},
|
|
88
96
|
async getBundleById (bundleId) {
|
|
89
97
|
const data = await db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,10 @@ const postgres = (config, hooks)=>(_)=>{
|
|
|
9
9
|
dialect
|
|
10
10
|
});
|
|
11
11
|
let bundles = [];
|
|
12
|
+
const changedIds = new Set();
|
|
13
|
+
function markChanged(id) {
|
|
14
|
+
changedIds.add(id);
|
|
15
|
+
}
|
|
12
16
|
let isUnmount = false;
|
|
13
17
|
return {
|
|
14
18
|
name: "postgres",
|
|
@@ -16,10 +20,14 @@ const postgres = (config, hooks)=>(_)=>{
|
|
|
16
20
|
if (isUnmount) return;
|
|
17
21
|
isUnmount = true;
|
|
18
22
|
await pool.end();
|
|
23
|
+
changedIds.clear();
|
|
19
24
|
},
|
|
20
25
|
async commitBundle () {
|
|
26
|
+
if (0 === changedIds.size) return;
|
|
27
|
+
const changedBundles = bundles.filter((b)=>changedIds.has(b.id));
|
|
28
|
+
if (0 === changedBundles.length) return;
|
|
21
29
|
await db.transaction().execute(async (tx)=>{
|
|
22
|
-
for (const bundle of
|
|
30
|
+
for (const bundle of changedBundles)await tx.insertInto("bundles").values({
|
|
23
31
|
id: bundle.id,
|
|
24
32
|
enabled: bundle.enabled,
|
|
25
33
|
file_url: bundle.fileUrl,
|
|
@@ -40,6 +48,7 @@ const postgres = (config, hooks)=>(_)=>{
|
|
|
40
48
|
target_app_version: bundle.targetAppVersion
|
|
41
49
|
})).execute();
|
|
42
50
|
});
|
|
51
|
+
changedIds.clear();
|
|
43
52
|
hooks?.onDatabaseUpdated?.();
|
|
44
53
|
},
|
|
45
54
|
async updateBundle (targetBundleId, newBundle) {
|
|
@@ -47,13 +56,12 @@ const postgres = (config, hooks)=>(_)=>{
|
|
|
47
56
|
const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
|
|
48
57
|
if (-1 === targetIndex) throw new Error("target bundle version not found");
|
|
49
58
|
Object.assign(bundles[targetIndex], newBundle);
|
|
59
|
+
markChanged(targetBundleId);
|
|
50
60
|
},
|
|
51
61
|
async appendBundle (inputBundle) {
|
|
52
62
|
bundles = await this.getBundles();
|
|
53
63
|
bundles.unshift(inputBundle);
|
|
54
|
-
|
|
55
|
-
async setBundles (inputBundles) {
|
|
56
|
-
bundles = inputBundles;
|
|
64
|
+
markChanged(inputBundle.id);
|
|
57
65
|
},
|
|
58
66
|
async getBundleById (bundleId) {
|
|
59
67
|
const data = await db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/postgres",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.7",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"package.json"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@hot-updater/core": "0.6.
|
|
33
|
-
"@hot-updater/plugin-core": "0.6.
|
|
32
|
+
"@hot-updater/core": "0.6.7",
|
|
33
|
+
"@hot-updater/plugin-core": "0.6.7",
|
|
34
34
|
"kysely": "^0.27.5",
|
|
35
35
|
"pg": "^8.13.1"
|
|
36
36
|
},
|