0:00 Now, before we implement our find functionality 0:03 inside of our Drizzle product repository, let's go ahead and create the 0:07 opposite side of our toPersistence method. 0:11 Now we need to go ahead and create the private static 0:14 toDomain method, which is gonna do the opposite, simply take in 0:18 a row from our table. And so as we saw earlier, 0:22 to get access to the type of the database row, 0:27 we can use our typeof and then reference the product schema 0:31 directly and use the helper inferSelect method, 0:35 inferSelectProperty, and we'll go ahead and return 0:39 back the product entity. 0:42 So now all we're gonna do is then call 0:44 product.reconstitute, which if you recall, 0:48 we already implemented on the product entity 0:51 itself, where we pass in the expected product 0:55 props, and then this will call our internal 0:58 constructor with 0:59 those props, which will assign our properties. 1:02 So now instead of reconstitute, we have to translate our database 1:06 row into the domain model properties. 1:09 So let's start with the ID. And so here we're gonna make new product 1:14 ID, which is our value object for the product 1:16 ID, and we can 1:18 pass in the string for the constructor. 1:20 So that's the 1:21 row.idValue. 1:25 So in this case, we'll be using the passed-in value instead 1:28 of generating a 1:29 UUID. 1:31 Then next up we have name, so that's row.name. 1:35 Description is simply row.description. 1:37 These are just simple string values. 1:40 Because we don't have any explicit functionality to enact on the 1:43 value, we don't create a new value object for 1:46 these properties. 1:48 Instead, these are just saved directly on the 1:50 entity. 1:50 So this is a good way to tell when it's time to create a value object 1:54 off of some data, is when you have a method to act on it. 1:57 But in our case, that's not so for these properties.
The rest of the transcript is for members.
Sign in