WEBVTT 00:01.940 --> 00:07.700 So let's start the database function to save a transaction, and I've actually split my ed into two 00:07.700 --> 00:12.760 so I can see the transaction model just to save switching back and forth between this and the database. 00:13.280 --> 00:19.280 So in Model Stojko, I'm going to create a new function here, which I'll call functional and will have 00:19.280 --> 00:25.310 the M DB model receiver and I'll call insert transaction. 00:26.330 --> 00:33.770 And it will take one argument, which I call t taxon and it's a type transaction and it will return 00:33.770 --> 00:39.320 and have potentially an error and the end will be the ID of the newly inserted transaction. 00:40.280 --> 00:45.680 And I'm going to copy the context from the above function just to save some typing and I'll pace that 00:45.680 --> 00:48.370 in here and I'll create a statement. 00:48.740 --> 00:55.910 So scroll up, give myself some room statement, EMT a sign the value of and I can all use back just 00:55.910 --> 01:05.270 to make the school readable insert into transactions and we're going to insert the amount which is the 01:05.270 --> 01:17.120 mouth lowercase currency, which is a string last four, which is a string bank return code, which 01:17.120 --> 01:19.340 is a string return ticket on the next one 01:21.950 --> 01:32.330 transaction that are still a transaction status ID created and updated at. 01:35.970 --> 01:43.620 And then on the next line, values, and there are one, two, three, four, five, six, seven, one, 01:43.800 --> 01:49.020 two, three, four, five, six and seven. 01:51.750 --> 01:52.870 So that'll be our statement. 01:53.820 --> 02:01.550 So let's insert that and we'll get a result from our insert and potentially air, and that's a sign 02:01.560 --> 02:05.780 the value of an DB not. 02:07.570 --> 02:16.480 Exact context, because we're using the context, so we handed the context and the statement, first 02:16.480 --> 02:29.110 of all, to send that out to send currency, and I'll just duplicate that a couple of times and then 02:29.110 --> 02:38.830 the last four and then the bank return code, I'll duplicate that and the transaction status. 02:41.230 --> 02:44.860 And since this is being created right now, time now. 02:48.020 --> 02:53.870 And the same thing for updater, so once that executes, we check for an error. 02:55.640 --> 03:03.380 If error is not equal Kinnell, then we'll return zero and the error. 03:06.140 --> 03:13.160 Otherwise, we need to get the last insert ID, so I.D. and error are assigned a value of from the result. 03:13.190 --> 03:22.100 We just got last insert idee and if error is not equal to nil again, we'll return zero and the error. 03:22.910 --> 03:28.080 Otherwise we return the ID, which we have to convert to an aunt. 03:30.790 --> 03:34.420 And nowhere and let's give this a comment, 03:38.530 --> 03:45.880 insert transaction inserts a new transaction tax and returns its. 03:47.380 --> 03:50.800 OK, so that's our insert function and we'll be using that momentarily. 03:50.830 --> 03:52.510 But we also need to save the order. 03:52.870 --> 03:56.410 So we'll take care of the insert order in the next lecture.