clawlet 0.5.1 → 0.5.2
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/package.json +1 -1
- package/src/storage.ts +23 -57
package/package.json
CHANGED
package/src/storage.ts
CHANGED
|
@@ -104,23 +104,8 @@ export class LibSqlListStorage<T = any> {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
async replaceAll(name: string, items: T[]): Promise<void> {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
await tx.execute({
|
|
110
|
-
sql: `DELETE FROM ${this.tableName} WHERE name = ?`,
|
|
111
|
-
args: [name],
|
|
112
|
-
});
|
|
113
|
-
for (const item of items) {
|
|
114
|
-
await tx.execute({
|
|
115
|
-
sql: `INSERT INTO ${this.tableName} (name, item) VALUES (?, ?)`,
|
|
116
|
-
args: [name, JSON.stringify(item)]
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
await tx.commit();
|
|
120
|
-
} catch (e) {
|
|
121
|
-
await tx.rollback();
|
|
122
|
-
throw e;
|
|
123
|
-
}
|
|
107
|
+
this.clear(name);
|
|
108
|
+
this.pushMany(name, items);
|
|
124
109
|
}
|
|
125
110
|
|
|
126
111
|
async getAll(name: string): Promise<T[]> {
|
|
@@ -181,19 +166,9 @@ export class LibSqlFiFoStorage<T> {
|
|
|
181
166
|
}
|
|
182
167
|
|
|
183
168
|
public async pushMany(queue: string, items: T[]): Promise<void> {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
await tx.execute({
|
|
188
|
-
sql: `INSERT INTO ${this.tableName} (queue_name, value) VALUES (?, ?)`,
|
|
189
|
-
args: [queue, JSON.stringify(item)],
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
await tx.commit();
|
|
193
|
-
} catch (e) {
|
|
194
|
-
await tx.rollback();
|
|
195
|
-
throw e;
|
|
196
|
-
}
|
|
169
|
+
for (const item of items) {
|
|
170
|
+
this.push(queue, item);
|
|
171
|
+
}
|
|
197
172
|
}
|
|
198
173
|
|
|
199
174
|
public async empty(queue: string): Promise<boolean> {
|
|
@@ -201,33 +176,24 @@ export class LibSqlFiFoStorage<T> {
|
|
|
201
176
|
}
|
|
202
177
|
|
|
203
178
|
public async pop(queue: string): Promise<T | null> {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
await tx.commit();
|
|
225
|
-
|
|
226
|
-
return JSON.parse(row.value as string) as T;
|
|
227
|
-
} catch (e) {
|
|
228
|
-
await tx.rollback();
|
|
229
|
-
throw e;
|
|
230
|
-
}
|
|
179
|
+
const rs = await this.client.execute({
|
|
180
|
+
sql: `SELECT id, value FROM ${this.tableName} WHERE queue_name = ? ORDER BY id ASC LIMIT 1`,
|
|
181
|
+
args: [queue],
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
if (rs.rows.length === 0) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const row = rs.rows[0] as any;
|
|
189
|
+
const id = row.id;
|
|
190
|
+
|
|
191
|
+
await this.client.execute({
|
|
192
|
+
sql: `DELETE FROM ${this.tableName} WHERE id = ?`,
|
|
193
|
+
args: [id!],
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
return JSON.parse(row.value as string) as T;
|
|
231
197
|
}
|
|
232
198
|
|
|
233
199
|
public async count(queue: string): Promise<number> {
|