WEBVTT 00:01.160 --> 00:05.630 So now that we have a query that seems to do the job we need to right the database function, that actually 00:05.630 --> 00:10.640 uses that query, but of course, our query, although we're querying the orders table, we're actually 00:10.640 --> 00:14.220 including transaction widget and customer information. 00:14.480 --> 00:20.300 So that means here in models go, we need somewhere to put that information so we can just add members 00:20.780 --> 00:23.690 or fields to the order struct to the type order. 00:24.140 --> 00:27.040 So we'll add one for widget, which I'll call widget. 00:27.710 --> 00:28.820 It's a type of widget. 00:29.270 --> 00:37.400 And in Jason I'll call it widget little lower case and I'll duplicate that twice and I'll add transaction, 00:39.470 --> 00:40.910 which is a type transaction. 00:42.380 --> 00:44.410 And in JSON I'll call the transaction. 00:45.950 --> 00:57.160 And finally, customer of type customer and in JSON we'll call the customer, let's call my office. 00:57.860 --> 01:01.220 And now let's go to the very bottom of this file or anywhere else in this file. 01:01.230 --> 01:06.410 But I'll put mine at the bottom and let's write a function that uses the query we just wrote. 01:07.160 --> 01:16.640 So func and the receiver type DB model and I'll call this get all orders and it takes no parameters 01:16.640 --> 01:25.250 right now and it returns a slice and I'll return a slice of pointers to order and potentially an error. 01:28.130 --> 01:31.400 Now I'll copy my contact stuff from the function right above it. 01:31.460 --> 01:38.360 So I don't miss type it as I always do and I'll put in a place to store our result where I'll call it 01:38.360 --> 01:43.310 orders, which will be a slice of pointer to order. 01:44.510 --> 01:53.060 And then we'll have our query and I'll use the tactics so I can put my query on multiple lines and I'll 01:53.060 --> 01:57.740 go back to my database client where I have that query and copy it 02:00.740 --> 02:01.780 and paste it right in here. 02:02.720 --> 02:04.580 And just format things a little bit better. 02:05.930 --> 02:07.700 All right, so that's my query. 02:07.850 --> 02:09.250 Now let's execute that query. 02:09.920 --> 02:11.900 So we're going to get back rows potentially. 02:11.900 --> 02:18.520 There are assigned the value of IMG, GB, dot query context right there. 02:19.070 --> 02:26.090 We handed the context and we handed our query and we check for an error if error is not equal to nil. 02:28.240 --> 02:36.190 Then we return nil in the air, which is near and of course, we don't want a memory leak, so let's 02:36.190 --> 02:37.930 put in a deferrals close 02:42.460 --> 02:45.900 and we go through the results that we get from the database for Rose. 02:46.190 --> 02:55.420 Next, we'll create a temporary variable Varro of type order to store things in and we'll check for 02:55.420 --> 02:59.040 an error while we call Rose Dot School. 03:01.420 --> 03:05.530 And we're going to scan this into our variable. 03:05.530 --> 03:07.230 Oh, so ampersand. 03:07.280 --> 03:12.130 So first of all, we're getting the ID and then I'll duplicate this a few times just to save some typing. 03:13.540 --> 03:14.820 Next we get the widget ID. 03:18.400 --> 03:19.960 Next, forget the transaction and 03:23.080 --> 03:24.430 then we get the customer customary. 03:29.360 --> 03:30.780 Then we get the status and 03:34.430 --> 03:38.060 then we get the quantity and duplicate this a few more times, 03:41.390 --> 03:42.560 then we get the amount. 03:46.030 --> 03:47.020 Then we get created 03:50.530 --> 03:53.920 and updated up and duplicate, there's a few more times, 03:57.730 --> 04:02.380 then we get in the widget, which is now a member of this type, the ID 04:05.440 --> 04:06.550 and the widget name. 04:11.380 --> 04:18.520 Then the transaction, the I.D. and the transaction amount. 04:21.690 --> 04:22.590 And the currency 04:29.880 --> 04:31.020 and the last four 04:35.380 --> 04:41.460 and the expiring month when expire a year. 04:46.080 --> 04:47.250 And the payment intent. 04:51.420 --> 04:52.770 And the bank return code, 04:55.620 --> 04:56.640 then the customer 04:59.460 --> 05:03.450 I.D. and first name 05:06.900 --> 05:07.830 and last name 05:12.570 --> 05:13.410 and the email. 05:15.330 --> 05:18.060 And if we did it right, that should be everything for our scam. 05:19.860 --> 05:20.790 And we check for an error. 05:21.750 --> 05:26.940 If error is not equal to nil, no return nil. 05:26.970 --> 05:33.990 And the error otherwise we can say orders, which is the variable we created right at the beginning 05:33.990 --> 05:37.860 of this function, will append to that orders. 05:38.400 --> 05:43.890 And since we have a slice of pointers, we have to return ampersand or append ampersand. 05:44.970 --> 05:48.120 And that should be it, except for return orders. 05:48.330 --> 05:51.580 And so that functions now available to us. 05:51.960 --> 05:56.510 So in the next lecture, we'll create a handler that takes advantage of that function and returns. 05:56.520 --> 05:56.970 Jason.