You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Import .jsonl file with events into the events table (#414)
* feat: add event import service with batch persistence
* feat: add CLI entrypoint for jsonl import
* test: add unit tests for event import service
* feat: add npm run import script
* docs: add jsonl import usage to README
* refactor: reuse EventRepository instead of raw queries in import service
* fix: enrich event metadata before persistence in import service
* fix: remove double onProgress call at end of import
@@ -187,6 +200,11 @@ export class EventRepository implements IEventRepository {
187
200
always(null),
188
201
),
189
202
})(event)
203
+
}
204
+
205
+
privateinsert(event: Event){
206
+
debug('inserting event: %o',event)
207
+
constrow=this.toInsertRow(event)
190
208
191
209
returnthis.masterDbClient('events')
192
210
.insert(row)
@@ -197,9 +215,50 @@ export class EventRepository implements IEventRepository {
197
215
publicupsert(event: Event): Promise<number>{
198
216
debug('upserting event: %o',event)
199
217
218
+
constrow=this.toUpsertRow(event)
219
+
220
+
constquery=this.masterDbClient('events')
221
+
.insert(row)
222
+
// NIP-16: Replaceable Events
223
+
// NIP-33: Parameterized Replaceable Events
224
+
.onConflict(
225
+
this.masterDbClient.raw(
226
+
'(event_pubkey, event_kind, event_deduplication) WHERE (event_kind = 0 OR event_kind = 3 OR event_kind = 41 OR (event_kind >= 10000 AND event_kind < 20000)) OR (event_kind >= 30000 AND event_kind < 40000)'
'(event_pubkey, event_kind, event_deduplication) WHERE (event_kind = 0 OR event_kind = 3 OR event_kind = 41 OR (event_kind >= 10000 AND event_kind < 20000)) OR (event_kind >= 30000 AND event_kind < 40000)'
@@ -220,24 +279,6 @@ export class EventRepository implements IEventRepository {
220
279
),
221
280
deleted_at: always(null),
222
281
})(event)
223
-
224
-
constquery=this.masterDbClient('events')
225
-
.insert(row)
226
-
// NIP-16: Replaceable Events
227
-
// NIP-33: Parameterized Replaceable Events
228
-
.onConflict(
229
-
this.masterDbClient.raw(
230
-
'(event_pubkey, event_kind, event_deduplication) WHERE (event_kind = 0 OR event_kind = 3 OR event_kind = 41 OR (event_kind >= 10000 AND event_kind < 20000)) OR (event_kind >= 30000 AND event_kind < 40000)'
0 commit comments