Hello and welcome to the Golang program language course in the previous session.
We could connect to the database, and in this session we want to perform crowd operations by writing
different functions.
First, we start by writing because related to the selected statement, so create the function to select
a student based student I.D. by sending an I.D. to the database as the input parameter off the select
metal and returning the student, whose idea is the same as the venue sent.
Now go to create our function.
Found.
Sit receiver for metal.
We assigned this metal to the DB initialize restaurants, all right.
DB in laser.
By the time Esther DBI initialized her and defined name of Mitchell, for the example, select a student.
They the.
And sit input parameter, this method accept an end value as AIDA variable because it will return a
student base IED, IED and 64
and return type is two values first in the student object and second is an error of value.
So we write
the Dart student and Arrow
Go to create body of the function.
Now, by calling DB initialize their variable, we will have access to the data object from the DB estimate
of gestural package.
And through it, we can call the query rule and executed.
The query that is expected to return at most won't rule.
Quitted rule function accepts obscure query statement as the string parameter and turns arrow object.
So define a variable like role
calling equals DB.
Initialize the Dot DB Dot query rule In this query, we want to fetch the student information whose
idea we have sent to the database as a query.
Input parameters.
All right.
Select a star from a student's their I.D. equals.
Set a question mark
and set either variable as input value.
OK, it's time to call on your skin function.
This function copies the columns from the matched the row into the values pointed at by destination.
So before working, disk and function first create an instance of the student model.
So we write.
Student Colin Equals
modern day art student.
Now calling a scan function by the role, and it will return as an interior object, so defined and
variable like error, the roll call equals roll dot scan and set a student field.
So we write and some student the art I.D. and emphasize the student
got me and ampersand student dot h.
Now, check our status,
if
not equals.
Neal,
if we have error returned from the function return student and of.
And now return values of the function, return student
and need reform of the called and save the project.
Now we could define the function name, select a student based I.D. that return a student of a student
table in person database by the select statement based I.D. number in order not to prolong the time
of decision.
We will finish it and we will continue the content in the next session.
Goodbye.