@xriss/weerss 0.0.21 → 0.0.22
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/db.js +24 -19
- package/package.json +1 -1
package/db.js
CHANGED
|
@@ -16,9 +16,9 @@ db.test=async function()
|
|
|
16
16
|
await db.setup()
|
|
17
17
|
await db.set(null,"hello","world")
|
|
18
18
|
await db.set(null,"hell","{world:poop}")
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
console.log( await db.list() )
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
await db.close()
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -41,63 +41,63 @@ db.setup=async function()
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
await db.handle.run(`
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
CREATE TABLE IF NOT EXISTS keyval
|
|
46
46
|
(
|
|
47
47
|
key STRING PRIMARY KEY ,
|
|
48
48
|
value JSONB NOT NULL
|
|
49
49
|
);
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
`);
|
|
52
52
|
|
|
53
53
|
await db.handle.run(`
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
CREATE TABLE IF NOT EXISTS hoard
|
|
56
56
|
(
|
|
57
57
|
key STRING PRIMARY KEY ,
|
|
58
58
|
value JSONB NOT NULL
|
|
59
59
|
);
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
`);
|
|
62
62
|
|
|
63
63
|
await db.handle.run(`
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
CREATE TABLE IF NOT EXISTS feeds
|
|
66
66
|
(
|
|
67
67
|
key STRING PRIMARY KEY ,
|
|
68
68
|
value JSONB NOT NULL
|
|
69
69
|
);
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
`);
|
|
72
72
|
|
|
73
73
|
await db.handle.run(`
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
CREATE TABLE IF NOT EXISTS items
|
|
76
76
|
(
|
|
77
77
|
key STRING PRIMARY KEY ,
|
|
78
78
|
value JSONB NOT NULL
|
|
79
79
|
);
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
`);
|
|
82
82
|
|
|
83
83
|
await db.handle.run(`
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
CREATE TABLE IF NOT EXISTS torrents
|
|
86
86
|
(
|
|
87
87
|
key STRING PRIMARY KEY ,
|
|
88
88
|
value JSONB NOT NULL
|
|
89
89
|
);
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
`);
|
|
92
92
|
|
|
93
93
|
await db.handle.run(`
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
CREATE TABLE IF NOT EXISTS shows
|
|
96
96
|
(
|
|
97
97
|
key STRING PRIMARY KEY ,
|
|
98
98
|
value JSONB NOT NULL
|
|
99
99
|
);
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
`);
|
|
102
102
|
|
|
103
103
|
}
|
|
@@ -128,7 +128,7 @@ db.set=async function(table,key,value)
|
|
|
128
128
|
INSERT INTO ${table} (key,value)
|
|
129
129
|
VALUES ($key,$value)
|
|
130
130
|
ON CONFLICT (key)
|
|
131
|
-
DO
|
|
131
|
+
DO
|
|
132
132
|
UPDATE SET value = $value
|
|
133
133
|
WHERE key = $key;
|
|
134
134
|
|
|
@@ -171,7 +171,7 @@ db.list=async function(table,filter)
|
|
|
171
171
|
table=table||"keyval"
|
|
172
172
|
filter=filter || {}
|
|
173
173
|
let rs=[]
|
|
174
|
-
|
|
174
|
+
|
|
175
175
|
let filters=[]
|
|
176
176
|
for(let fb in filter)
|
|
177
177
|
{
|
|
@@ -240,15 +240,20 @@ db.list=async function(table,filter)
|
|
|
240
240
|
filters="WHERE "+filters.join(" AND\n")
|
|
241
241
|
}
|
|
242
242
|
// console.log(filters)
|
|
243
|
-
|
|
243
|
+
|
|
244
244
|
await db.handle.each(`
|
|
245
|
-
|
|
245
|
+
|
|
246
246
|
SELECT * FROM ${table}
|
|
247
247
|
${filters}
|
|
248
248
|
|
|
249
249
|
`,{},function(row)
|
|
250
250
|
{
|
|
251
|
-
|
|
251
|
+
try{
|
|
252
|
+
rs.push(JSON.parse(row.value))
|
|
253
|
+
}catch(e){
|
|
254
|
+
console.log(row.value)
|
|
255
|
+
console.log(e)
|
|
256
|
+
}
|
|
252
257
|
})
|
|
253
258
|
|
|
254
259
|
return rs // filtered only, sorted by date
|