-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepository.interface.ts
More file actions
75 lines (63 loc) · 2 KB
/
Copy pathrepository.interface.ts
File metadata and controls
75 lines (63 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Type representing find options for querying entities.
* @template Entity - The type of the entity being queried.
*/
export type FindOptions<Entity> = {
/**
* Conditions to filter the results.
*/
where?: FindWhere<Entity>;
/**
* Array of properties to select from the entity.
*/
select?: Array<keyof Entity>;
/**
* Ordering options for sorting the results.
*/
order?: FindOrder<Entity>;
/**
* The maximum number of results to return.
*/
take?: number;
/**
* The number of results to skip.
*/
skip?: number;
};
export type FindOrder<Entity> = {
[Key in keyof Entity]?: "ASC" | "DESC"
}
export type FindWhere<Entity> = {
[Key in keyof Entity]?: Entity[Key]
}
export interface RepositoryInterface<Entity> {
/**
* Init repository
*/
init(): Promise<void>
/**
* Finds entities in the table based on the provided options.
* @param options Options for the query.
* @returns A Promise containing an array of entities.
*/
find(options?: { where?: FindWhere<Entity>, select?: Array<keyof Entity> }): Promise<Entity[]>;
/**
* Saves a new entity to the table.
* @param data The entity to be saved.
* @returns A Promise containing the ID of the inserted entity.
*/
save(data: Entity): Promise<number | undefined>;
/**
* Updates an entity in the table based on its ID.
* @param id The ID of the entity to be updated.
* @param update An object containing fields and values to be updated.
* @returns A Promise containing the number of rows affected by the update.
*/
update(id: number, update: FindWhere<Entity>): Promise<{ rowsAffected: number } | undefined>;
/**
* Deletes an entity from the table based on its ID.
* @param id The ID of the entity to be deleted.
* @returns A Promise containing the number of rows affected by the deletion.
*/
delete(id: number): Promise<{ rowsAffected: number } | undefined>;
}