-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Samika Kashyap
committed
May 17, 2024
1 parent
9e952f0
commit 0c3fb85
Showing
6 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Knex } from 'knex' | ||
import { Request } from '../models/request' | ||
import { CID } from 'multiformats/cid' | ||
import { Config } from 'node-config-ts' | ||
|
||
export class ReplicationRequestRepository { | ||
static make = make | ||
private readonly connection: Knex | ||
|
||
constructor(connection: Knex) { | ||
this.connection = connection | ||
} | ||
|
||
/** | ||
* Finds a request with the given CID if exists using the replica database. | ||
* @param cid CID the request is for | ||
* @returns Promise for the associated request | ||
*/ | ||
async findByCid(cid: CID | string): Promise<Request | undefined> { | ||
const found = await this.connection | ||
.table('requests') | ||
.where({ cid: String(cid) }) | ||
.first() | ||
if (found) { | ||
return new Request(found) | ||
} | ||
return undefined | ||
} | ||
|
||
// Add more methods that utilize the replica connection here | ||
} | ||
|
||
/** | ||
* Injection factory. | ||
*/ | ||
function make(config: Config, replicaConnection: Knex) { | ||
return new ReplicationRequestRepository(replicaConnection) | ||
} | ||
|
||
make.inject = ['config', 'replicaDbConnection'] as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters