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
{{ message }}
This repository was archived by the owner on Feb 7, 2021. It is now read-only.
This method takes in a `Partial<T>` as we do not always know the `id` for a record when we are creating. If we leave off the `id` property the service will automatically generate an `id` for us. Upon successful creation, the method returns the record with the newly generated `id`.
11
+
This method takes in a `Partial<T>` as we do not always know the `id` for a record when we are creating. If we leave off the `id` property the service will automatically generate an `id` for us. Upon successful creation, the method returns the record with the newly generated `id`. An optional parameter of `getNextId` can be used to pass a function that returns a `string` and will be used by the service to get the next id. By default this uses the `uuid` npm package.
This method takes in an array of `Partial<T>` as we do not always know the `id` for records when we are creating. If we leave off the `id` properties the service will automatically generate `id`s for us. Upon successful creation, the method returns the an array of records with the newly generated `id`s.
35
+
This method takes in an array of `Partial<T>` as we do not always know the `id` for records when we are creating. If we leave off the `id` properties the service will automatically generate `id`s for us. Upon successful creation, the method returns the an array of records with the newly generated `id`s. An optional parameter of `getNextId` can be used to pass a function that returns a `string` and will be used by the service to get the next id. By default this uses the `uuid` npm package.
36
36
37
37
Example Usage:
38
38
@@ -81,31 +81,31 @@ this.userService.update({
81
81
});
82
82
```
83
83
84
-
**`public delete(id: number): void`**
84
+
**`public delete(id: string): void`**
85
85
86
-
This method takes in a `id: number` and deletes the record from the `records` array based on the `id` in the object. This method does not return a value.
86
+
This method takes in a `id: string` and deletes the record from the `records` array based on the `id` in the object. This method does not return a value.
87
87
88
88
Example Usage:
89
89
90
90
```typescript
91
-
this.userService.delete(1);
91
+
this.userService.delete('1');
92
92
```
93
93
94
-
**`public get(id: number): T`**
94
+
**`public get(id: string): T`**
95
95
96
-
This method takes in a `id: number` and returns the record from the `records` array based on the `id` in the object.
96
+
This method takes in a `id: string` and returns the record from the `records` array based on the `id` in the object.
-`records: T[]` - This is the in-memory array used in all crud and read operations for the service. Please access with care.
176
176
177
-
## `InMemoryEntity`
177
+
## `InMemoryDBEntity`
178
178
179
179
This is an interface used by the `InMemoryDBService` for intellisense and type-safety. Do not use this interface directly. Rather, implement your own `interface` that `extends` this.
This is the service that provides the in-memory database. All methods interact with a `records` array and implement `generics` to provide type-safety and intellisense based on the `T extends InMemoryDBV1Entity` passed in.
6
+
7
+
### Public Methods
8
+
9
+
**`public create(record: Partial<T>): T`**
10
+
11
+
This method takes in a `Partial<T>` as we do not always know the `id` for a record when we are creating. If we leave off the `id` property the service will automatically generate an `id` for us. Upon successful creation, the method returns the record with the newly generated `id`.
This method takes in an array of `Partial<T>` as we do not always know the `id` for records when we are creating. If we leave off the `id` properties the service will automatically generate `id`s for us. Upon successful creation, the method returns the an array of records with the newly generated `id`s.
This method takes in a `T` record object and updates the record in the `records` array based on the `id` in the object. This method does not return a value.
73
+
74
+
Example Usage:
75
+
76
+
```typescript
77
+
this.userService.update({
78
+
id: 1,
79
+
firstName: 'Other',
80
+
lastName: 'Person',
81
+
});
82
+
```
83
+
84
+
**`public delete(id: number): void`**
85
+
86
+
This method takes in a `id: number` and deletes the record from the `records` array based on the `id` in the object. This method does not return a value.
87
+
88
+
Example Usage:
89
+
90
+
```typescript
91
+
this.userService.delete(1);
92
+
```
93
+
94
+
**`public get(id: number): T`**
95
+
96
+
This method takes in a `id: number` and returns the record from the `records` array based on the `id` in the object.
97
+
98
+
Example Usage:
99
+
100
+
```typescript
101
+
const foundUser =this.userService.get(1);
102
+
103
+
console.log({ foundUser });
104
+
105
+
// logs out
106
+
// {
107
+
// foundUser: {
108
+
// id:1,
109
+
// firstName: 'Some',
110
+
// lastName: 'Person'
111
+
// }
112
+
// }
113
+
```
114
+
115
+
**`public getAll(): T[]`**
116
+
117
+
This method has no parameters and returns the all from the `records` array.
This method has takes in a `record: T` predicate and returns all from the `records` array that meet that predicate's requirements.
146
+
147
+
Example Usage:
148
+
149
+
```typescript
150
+
const foundUsers =this.userService.query(
151
+
(record) =>record.lastName==='Person',
152
+
);
153
+
154
+
console.log({ foundUsers });
155
+
156
+
// logs out
157
+
// {
158
+
// allUsers: [
159
+
// {
160
+
// id: 1,
161
+
// firstName: 'Some',
162
+
// lastName: 'Person'
163
+
// },
164
+
// {
165
+
// id: 2,
166
+
// firstName: 'Other',
167
+
// lastName: 'Person'
168
+
// }
169
+
// ];
170
+
// }
171
+
```
172
+
173
+
### Public Properties
174
+
175
+
-`records: T[]` - This is the in-memory array used in all crud and read operations for the service. Please access with care.
176
+
177
+
## `InMemoryDBV1Entity`
178
+
179
+
This is an interface used by the `InMemoryDBV1Service` for intellisense and type-safety. Do not use this interface directly. Rather, implement your own `interface` that `extends` this.
0 commit comments