So let's start the database function to save a transaction, and I've actually split my ed into two
so I can see the transaction model just to save switching back and forth between this and the database.
So in Model Stojko, I'm going to create a new function here, which I'll call functional and will have
the M DB model receiver and I'll call insert transaction.
And it will take one argument, which I call t taxon and it's a type transaction and it will return
and have potentially an error and the end will be the ID of the newly inserted transaction.
And I'm going to copy the context from the above function just to save some typing and I'll pace that
in here and I'll create a statement.
So scroll up, give myself some room statement, EMT a sign the value of and I can all use back just
to make the school readable insert into transactions and we're going to insert the amount which is the
mouth lowercase currency, which is a string last four, which is a string bank return code, which
is a string return ticket on the next one
transaction that are still a transaction status ID created and updated at.
And then on the next line, values, and there are one, two, three, four, five, six, seven, one,
two, three, four, five, six and seven.
So that'll be our statement.
So let's insert that and we'll get a result from our insert and potentially air, and that's a sign
the value of an DB not.
Exact context, because we're using the context, so we handed the context and the statement, first
of all, to send that out to send currency, and I'll just duplicate that a couple of times and then
the last four and then the bank return code, I'll duplicate that and the transaction status.
And since this is being created right now, time now.
And the same thing for updater, so once that executes, we check for an error.
If error is not equal Kinnell, then we'll return zero and the error.
Otherwise, we need to get the last insert ID, so I.D. and error are assigned a value of from the result.
We just got last insert idee and if error is not equal to nil again, we'll return zero and the error.
Otherwise we return the ID, which we have to convert to an aunt.
And nowhere and let's give this a comment,
insert transaction inserts a new transaction tax and returns its.
OK, so that's our insert function and we'll be using that momentarily.
But we also need to save the order.
So we'll take care of the insert order in the next lecture.