Hello and welcome to the Golang programming language course.
In the previous session, we could define the function name, select all a student that fits all students
from the database.
And in this time, we want to create a main function.
So we create a new package named Main and create a finding inside name main that goal.
And in this fine first, we create the main function to execute queries.
So go to Project Explorer and create a new package, for example, named Main and create a new file
inside it like name.
The article said the package main and create the main function for me.
Before we can access data in the MySQL database, we need to create a connection to the database.
Previously, we designed the method called König in the DB Tools package, which contains a method called
open from this school package.
This by taking two values of driver name and data source name creates a connection to the MySchool database.
We also previously saved driver name and data source name information inside the JSON file in the configuration
package.
Now it's time to use the information our JASON file to connect to the database for using the JSON file
weakening open function from Always Package that opens the named file from Reading.
If successful methods on the return file can be used for reading this function except fine pass as input
parameter and returns tool value.
First, not from file and the other an object from, you know.
So first, define two variables named file and or find and ETL columns equals calling.
Open function from Westpac is open function and Sanjay some file pass as input parameters as the string
type can be Grecian slash config that JS check error status.
Like the fat on air or God, views differ for closing the created final object, the author fired close.
Now, create this right on top of the main method that contains variables equivalent to the keys in
the JSON file that are used to map those keys to their data types in column.
So define airstrike like name, configuration,
type,
configuration
structure
and define value.
The driver name
type is string and using Jason.
Thank you, Jason, Colin and Seth.
Write your name to write a name.
Go to the next line and find another valuable four data source name data, source name five is a swing
and set Jason Tech.
Jason Collins.
Data source me.
OK, now go to the main function and create an object from this configuration estrogen.
So define a variable like con call and he calls new configuration.
Now, using the new decoder function of the Jason package, we sent the Jason fine to eat as a parameter
after opening it and through the decode method and read the next Jason encoded value from its input
and installs it in the values pointed to Archer created from the configuration.
So be right, Jason Dot, new decoder, said fine as argument.
And Colleen Deckard function and sit calm first and put perimeter.
OK.
This allowed us to sort of values inside the JSON, find in the variables in the configuration is not
object.
Now it's time to call the DB initialize method from the DB tools package to connect to the database
so the right DB tools dot db initialize.
Said Driver made from Kong object.
Com.
Dutch driver name and set data source name from conf object.
Com The data source name.
OK.
Each of the current methods uses a method called conic to communicate with the database, which requires
these two parameters that we were able to inject into the attitudes package.
Necessary conditions for communication with the MySchool database are provided.
Now it's time to call on the available methods to perform crowd Operation DB Tools package.
In this case, we want to select all the students in the person database, so we should use from select
all the students function from DB tools.
First, define a variable like a student, for instance, the needs of all students.
So we write a student's column he calls DB Tools Package Dart, calling Sediq all his students function
to iterate the values inside this student.
We use a range loop so that we can display the values inside each record separately for under a school
comma set the variable.
For example, a student column equals range in a student's.
And he printed information to display each record that fee I.D., Caller ID, student I.D..
Comma and set back list for create a ton of space that has less teeth and name calling the student name
and said another bike as close to.
Age, Colin and Student Start page reformat the cold and save the project, now execute the program,
go from Dot.
Thank you.
Slash main Maine Dot Go.
We can see the output.
Now we could select all a students from person database and display each record separately in order
not to prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.