fase(4): crawling infrastructure with migrated code
This commit is contained in:
72
dist/modules/crawling/infrastructure/repositories/KyselyStateRepository.js
vendored
Normal file
72
dist/modules/crawling/infrastructure/repositories/KyselyStateRepository.js
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.KyselyStateRepository = void 0;
|
||||
const CrawlState_1 = require("../../domain/entities/CrawlState");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
class KyselyStateRepository {
|
||||
constructor(db) {
|
||||
this.db = db;
|
||||
}
|
||||
async save(state) {
|
||||
const row = {
|
||||
id: state.id.toString(),
|
||||
session_id: state.sessionId,
|
||||
url: state.url,
|
||||
title: state.title,
|
||||
dom_snapshot_path: null,
|
||||
visit_count: state.visitCount,
|
||||
discovered_at: Date.now(),
|
||||
};
|
||||
await this.db
|
||||
.insertInto('states')
|
||||
.values(row)
|
||||
.execute();
|
||||
}
|
||||
async findById(id) {
|
||||
const row = await this.db
|
||||
.selectFrom('states')
|
||||
.selectAll()
|
||||
.where('id', '=', id.toString())
|
||||
.executeTakeFirst();
|
||||
if (!row)
|
||||
return null;
|
||||
return this.toDomain(row);
|
||||
}
|
||||
async findAll() {
|
||||
const rows = await this.db
|
||||
.selectFrom('states')
|
||||
.selectAll()
|
||||
.execute();
|
||||
return rows.map((row) => this.toDomain(row));
|
||||
}
|
||||
async findBySessionId(sessionId) {
|
||||
const rows = await this.db
|
||||
.selectFrom('states')
|
||||
.selectAll()
|
||||
.where('session_id', '=', sessionId)
|
||||
.execute();
|
||||
return rows.map((row) => this.toDomain(row));
|
||||
}
|
||||
async update(state) {
|
||||
await this.db
|
||||
.updateTable('states')
|
||||
.set({
|
||||
visit_count: state.visitCount,
|
||||
url: state.url,
|
||||
title: state.title,
|
||||
})
|
||||
.where('id', '=', state.id.toString())
|
||||
.execute();
|
||||
}
|
||||
toDomain(row) {
|
||||
return CrawlState_1.CrawlState.create({
|
||||
url: row.url,
|
||||
title: row.title,
|
||||
domSnapshot: '',
|
||||
visitCount: row.visit_count,
|
||||
stateId: row.id,
|
||||
sessionId: row.session_id,
|
||||
}, UniqueId_1.UniqueId.from(row.id));
|
||||
}
|
||||
}
|
||||
exports.KyselyStateRepository = KyselyStateRepository;
|
||||
Reference in New Issue
Block a user