0:00 All right, so next up, we are gonna implement our find methods for 0:03 our repository. 0:04 And so for this, we're gonna need, just like we had for save, the 0:08 toPersistence method to turn an entity into a database 0:12 record. We need our toDomain method, as we did for products, to 0:16 turn the database record back into the domain model entity. 0:20 So for this, we'll follow the same pattern 0:22 and have our private static 0:24 toDomain method 0:26 that will take in the customer row, which is gonna be the 0:30 type of the customer inside of the database. 0:35 Now, we know we can use the Drizzle schema to 0:37 pull this off, but I'm actually 0:38 gonna create the type 0:40 CustomRow here to be 0:44 able to reuse it. So remember, this is type of customer schema. 0:48 We have the inferSelect property, 0:52 which will give us the shape, the TypeScript type for the data based 0:56 off of the schema we've defined for it, which is really the power of Drizzle ORM, 1:00 this nice type-safe ORM. 1:02 And so now inside of toDomain, all we have to do is 1:06 now return customer. On the customer entity, 1:10 we have the reconstitute method, which we've already implemented. 1:14 We know this is gonna call the constructor with the expected raw 1:17 properties, JavaScript properties. 1:20 So now we're gonna go ahead and pass in all of the 1:24 domain model types. So for example, our ID, we're gonna 1:27 create a new customer ID value object. 1:31 And again, we know this is okay because this 1:33 is a lower-level detail, in this case, 1:35 the adapter relying on a higher level. That's fine. 1:38 We don't want the inverse relationship, and our clean architecture 1:42 insulates us from this. 1:44 So we have the customer ID value object where we'll pass in now 1:48 the row ID 1:51 to get the value object created that the domain model will use
The rest of the transcript is for members.
Sign in