1
+ import { ObjectId } from 'mongodb'
2
+
3
+ /**
4
+ * DAO Interface
5
+ * @seed Boot/Reboot a table, collection, or key and insert a list of elements
6
+ * @getOne Retrieve one element from a table, collection, or key
7
+ * @getAll Retrieve all elements from a table, collection, or key
8
+ * @setOne Insert an element into a table, collection, or key
9
+ * @setMany Insert a list of elements into a table, collection, or key
10
+ * @updateOne Update one element from a table, collection, or key
11
+ * @deleteOne Delete one element from a table, collection, or key
12
+ * @deleteAll Delete all elements from a table, collection, or key
13
+ */
14
+ export interface DAO
15
+ {
16
+
17
+ /**
18
+ * Boot/Reboot a table, collection, or key and insert a list of elements
19
+ * @param target Name of the target table, collection, or key
20
+ * @param elements List of elements to insert
21
+ * @param callback Process to execute on response (optional)
22
+ */
23
+ seed : ( target : string , elements : DataElement [ ] , callback ?: Callback ) => void
24
+
25
+ /**
26
+ * Retrieve one element from a table, collection, or key
27
+ * @param target Name of the target table, collection, or key
28
+ * @param id Target element's ID
29
+ * @param callback Process to execute on response's element or error
30
+ */
31
+ getOne : ( target : string , id : number | string , callback : Callback ) => void
32
+
33
+ /**
34
+ * Retrieve all elements from a table, collection, or key
35
+ * @param target Name of the target table, collection, or key
36
+ * @param callback Process to execute on response's list of elements or error
37
+ */
38
+ getAll : ( target : string , callback : Callback ) => void
39
+
40
+ /**
41
+ * Insert an element into a table, collection, or key
42
+ * @param target Name of the target table, collection, or key
43
+ * @param element Element to insert
44
+ * @param callback Process to execute on response (optional)
45
+ */
46
+ setOne : ( target : string , element : DataElement , callback ?: Callback ) => void
47
+
48
+ /**
49
+ * Insert a list of elements into a table, collection, or key
50
+ * @param target Name of the target table, collection, or key
51
+ * @param elements List of elements to insert
52
+ * @param callback Process to execute on response (optional)
53
+ */
54
+ setMany : ( target : string , elements : DataElement [ ] , callback ?: Callback ) => void
55
+
56
+ /**
57
+ * Update one element from a table, collection, or key
58
+ * @param target Name of the target table, collection, or key
59
+ * @param element Updated element
60
+ * @param callback Process to execute on response (optional)
61
+ */
62
+ updateOne : ( target : string , element : DataElement , callback ?: Callback ) => void
63
+
64
+ /**
65
+ * Delete one element from a table, collection, or key
66
+ * @param target Name of the target table, collection, or key
67
+ * @param id Target element's ID
68
+ * @param callback Process to execute on response (optional)
69
+ */
70
+ deleteOne : ( target : string , id : number | string , callback ?: Callback ) => void
71
+
72
+ /**
73
+ * Delete all elements from a table, collection, or key
74
+ * @param target Name of the target table, collection, or key
75
+ * @param callback Process to execute on response (optional)
76
+ */
77
+ deleteAll : ( target : string , callback ?: Callback ) => void
78
+
79
+ }
80
+
81
+ /** Standard DAO Connector type */
82
+ export type Connector = {
83
+ driver : string ,
84
+ user : string ,
85
+ password : string ,
86
+ host : string ,
87
+ port ?: number | string ,
88
+ database : string ,
89
+ params ?: ConnectorParams
90
+ }
91
+
92
+ /** Standard DAO Connector parameters type */
93
+ export type ConnectorParams = {
94
+ [ key : string ] : any
95
+ }
96
+
97
+ /** Standard DAO DataElement type */
98
+ export type DataElement = {
99
+ id ?: number | string ,
100
+ _id ?: ObjectId | string ,
101
+ [ key : string ] : any
102
+ }
103
+
104
+ /** Standard DAO Callback type */
105
+ export type Callback = ( ...arg : any ) => void
106
+
107
+ // export { DAO, Callback, DataElement, Connection }
0 commit comments