Hello and welcome to the Golang programming language course in this session.
We want to create another select function.
We want to fetch a student by a connection, otherwise we create a query by workless for these Sampat.
We want to define the function that returns a student base I.D. number.
So first, define the function name.
Select a student based I.D. that exit an integer parameter as I.D number and return a student based
that idea.
Not so first.
Go to DB connection and create our function.
Find Select a student base I.D..
And set a variable like IED as input parameter by the type of end
and defined a student as return type model.
The student
now cutting connect function for initializing my school driver name and data source name.
This function returns a DV object from a school package, which gives us access to the metals contained
in that package to perform cloud operations.
So define a variable like DV call equals and calling connect function
after creating a DV object from a school package.
The invoked Queretaro method that it executes a query that is expected to return at most one rule quit
enrollment or office returns and none nil.
Value and awards are deferred until rose is scanned.
Method is called.
If the query select no roads, the roads are scanned.
Her return error no rules.
Otherwise, the roads.
The scan is Cairns, the first selected row and this cost the rest.
So define a variable like roll and roll method.
Roll.
Column E equaled and calling query row method from TBE Optic DB Dot Query Law.
In this case, we want to select a student in student table by based on the given either number, and
we should use select query parameter.
We are very close and so writes that a query has a string parameter.
Select the star from the student and set very close condition based IED their IED equals instead of
the IED value put a question mark and as the second parameter, we received the IED value from inside
the method.
So we write IED.
OK, we use defer for closing the created object d4 d without clothes.
Now we create an object from a student, a strong student calling equals model of the student.
And calling Eskin Mitchell on roll resolve to lead record defying and already able and invoke, yes,
can't function.
They're all calling equals roll dots can sit A-student ideas pointer percent student I.D. Karma.
So the student, the undersigned student, the last name and set age and person, a student dot H.
S can converse.
Collins read from the database and to the following comment Go tights and ESPECIE.
All types provided by the rescue package.
Check in order status
now.
Return your student as return value off function.
If the student is not available, the NOL value will be returned with the select Ike Return student.
Now we could define a function named select students based idea that the return student of students
made that in-person database by the select statement based I.D. number.
Now we go to the main function to use this query statement.
First, clear the last code.
In this case, we want to select a student base I.D. number, so we should use from select a student
based I.D. function from DV tools that accept their student ideas input arguments.
So first, define a variable like a student calling equals and calling selected student based I.D. function
from DB tools.
For example, you set I.D. number three, go to the next line and the displayed is student variables.
If P
I.D. caller
student
I.D..
Backsplash and
name calling.
Student that name.
And I kiss slash and.
Age column, student, the age reform, reforming the code and save the project and go to execute the
program, go Ronald Reagan, slash Maine, Maine Dot Go.
Now we can see the output.
And it is expected that the information about a student whose I.D. number is three will be returned.
Now we could select a student based I.D. number from person database and display it in order not to
prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.