Hello and welcome to the Golang programming language course.
In the previous session, we could update a singular student using single update function.
And in this session, we want to update multiple students.
So go to the DB connection and define a function named multiple update FAJ
multiple updates.
This function accept three parameters.
First parameter is an empty interface, which indicates that an instance of an strike is to be passed
to this function.
And second is a very closest string for condition, and third parameter is a map which to update information
is sent to the function.
Also, this function returns the number of records that have been affected by the update operation at
the end of the watch.
So we write object into the interface.
Where?
Close the string and set a name like data for define and map data.
Map Sid Key by the time is string
and search value y the type and interface because we don't know what type of the value is sent to the
function and the interface and set and 64 as return type and 64.
OK now calling connect function for initializing MySchool data source name.
This function returns ADP object from Guérin package so defined a variable like DB calling equals and
calling connect fonts.
After creating a DV object, found gore and package the involved model function on the DBI object and
set object instance and arguments for it before calling it first defined and valuable like reasons for
the return type model function is specify the model you would like to run operations.
So we right resolved Colin equals DB dot model.
And said opticals arguments to its object.
And more in work, their function and sit their close object as an argument to it, their function at
conditions, so be right there and said workloads close the object as argument to it.
They're close.
And more in look up this function and set data object as a map, our human state updates, function
updates, attributes with callbacks.
So we write all this
and set Data's argument to it.
Now invoking Rose effect, that field from recent return value that we showed up the Earth records,
so we right Rita, result that rose affected, reformat the code and save the project.
Now you have succeeded in designing a method to receive a strike, the instance from the outside and
update the values of this object, according to the values given below the map sent.
Now we go to the main function to use this query statement first to your last quote.
In this case, we want to audit all the students who have a special condition in the database, so we
should use from multiple update function from DevTools first define a condition has very close arguments.
Consider that we want to update students based on the Durm names, so define the condition for base
name.
First, define a variable like name, and we want to say that every record whose name had this value
for the example name calling equals key
and set another variable for writing.
Our call like name were close to name their close call and equals and write condition for query name
equals single code
plus name variable plus double quotation mark and set single code between each.
Now define and my variable for send new data after updating, or in other words, we want to say that
the values of name and age are changed to these values based on the above name or close condition.
So we write data column equals man and city string as key and sit empty in your face as value
and sit value for main
column.
For example, daily
and sit age by the value.
50.
And now, even with multiple update function from DevTools package and sent created a student object
as first are human and main very close, a second argument for the condition and data, and third are
human to it and fetch RO effect that so first define a variable like Rose, Collins equals colleague
multiple lot8 function from DB Tools Package, DevTools Dart multiple update and set model Dot A-student
student as first argument model student.
And sit Namer to lose a second argument, mean their clothes and sit they till after argument
now display return type as role variable the all right 50 roles affected and said Rosemary to
reformat the cord and save the furniture.
Before on the program, go to the database and see the name and age values of the records whose name
is Kim.
OK, now we can see names off the records by the I.D. five and seven are keen.
Go back to school and execute the program, go wrong.
That's backslash Maine and Maine dot gov.
Now we can see the output rose effect, it is to now go to the database again and execute, select,
query and see the changes.
Execute the query.
OK.
Names and ages of the records by the i5 and sitting has changed to David and 50 now go to the escort
program and continue what define another condition as very close arguments.
Consider that we want to update as students based on their ages.
So define and condition based age first clear the last quote.
First, define a value of light age, and we want to say that every record whose age had this value
for the example, age column equals 13 and set another variable for writing our query light age, work
loss, age where close
calling equals and right condition for query age equals.
We use this command to convert time of errors from integer to a string value and paste it into the continuation
of our string plus SDR column
dot IED or a end set age as argument.
And now define and map barrier built for sand, new data after updating, or in other words, if you
want to say that the values of name and age are changed to these values based on the above age were
close condition sold.
The right data Cullen equals map sit is starring as key and sit empty in your face as value.
Full name.
Set a value like.
John?
And set for age revenue like twenty five
and now invokes multiple update function from debate tools package and sent created student object as
first argument and age workloads, a second argument for the condition and data.
Third are human to eat and fetch ro affected.
So first, define a variable like roles calling equals and calling multiple update functions from DB
tools, package DB tools, dot multiple updates and set model dot student.
As first argument and error is very close, a second arguments and set data expert arguments and now
display return time as roles variable that saw the right FP rows affected and set variables roles.
Reformat the code and save the project before on the program.
Go to the database and see the name and age values of the records whose ages 30.
OK, we can see the ages of the record by the idea.
Three and eight are 30.
Now go back to the Waskow program and execute the project.
Go from Dot Package Slash Main and main dot go.
Now we can see the output rose affected to now go to the database again and executes select query and
see the changes execute the query.
Now we can see name and age of students is opted chronically in the person database and names and ages
of the records by the idea three and eight has changed to John and five.
In order not to prolong the time of decision, we will finish it and we will continue the content in
the next session until next session.
Goodbye.