Hello and welcome to the gold and programming language course in the previous session.
We were able to create the political ball from messages and air pieces services and create equivalent
gold angus stratifying.
Now it's time to design the database layer to communicate the connection between the database and the
server.
Now go to Project Folder and create a folder named Launch Model
in Model Folder.
Recreate the file like named A-student that go inside it.
Right click and create a new file like the.
That's cool.
Now we are going to create a structure equivalent to a student table in the MySchool database in design.
So we create a strike name student with fields such as fields is taught inside the MySchool database.
So right first package modern and tried is to then instruct
and write the fields.
I'd buy the type in 64 and name by string type and age by end 32.
He format the code and save the project.
Now go to Project Folder and create another folder name like configuration, which is supposed to include
the settings for the connection of the Go program with the MySchool database, so right click on the
project folder.
Create a folder like Come Figuration.
We want to create a database connection settings as a JSON file, so inside the configuration folder,
we create the phone call config with the JSON extension.
Right click on the Configuration folder and create the file.
I can fix that.
Jason The program requires two main settings to connect to the database.
First, its driver name and second is data source name.
Driver name is my school and data source.
Name is a combination of username, password and database name that we want.
Connect it.
So right adjacent five four sittings off database, open and closed braces and dry key and venue between
them, so bright.
First, derive her name as key and set venue for it, my skewer sitcom and go to the next line, said
another key like data, source name and set value for it.
My database username is Ruth, Colin and my database passport use or I care
outside this line and database name is person
reformat the code and say if the project could create the JSON file for connection to my school database.
Now it's project folder and create another folder named like DBI tools and create the file inside it
like name the connection that go.
That file contains metals to interact with the database.
Now go to the Project Explorer and write on the project folder.
Create another folder like the web tools and inside it.
Create another fight like DV connection that go before doing anything.
We must first import the MySchool database driver in our package.
So first package give you tools and import
underscore
get dot com slash go dash discuter dash driver slash my skewered.
Okay, now if you want to create the connection to the database.
So first, create, extract and define an instance of a strike from a secured package for communicate
the connection.
For example, we named it didn't initialize the sole right time D.B. initialize or the struct and define
a variable like DB
from type of a skew of dot db.
Now we want to design the middle, whose task is to connect to the minuscule that is access to input
parameters as driver name and data sourcing by this string type and return it to initialize rests like
the instance, an error is thus, for example, you name it, connect function.
So right, fine connect.
City's string variable as driver me.
And sit and other string as data source names like data source, the frank and set return tied first
is a pointer of DB a Lazarus, right?
So B right
pointer off DV initial either.
And second is a of.
Go to create the body of iconic function, the requirement or to connect to the database is the open
function of the actual package.
So we should import a school package.
Open function opens a database is defined by its database driver name and the driver is specified source
name, usually consisting of at least the database name and connection information, and it returns
the object and or so first defined two variables like the connection and or DB connection, and they're
all calling vehicles, calling open function from a secure package and set driver name and data source
name as parameters.
School thought or her driver name and datasource name?
OK, now check it or a status if they're not equals.
Neil from the package like calling fat wallet phones.
And since it all starts, there are OK, and we should set two values as return time.
First, an instance of Debbie Initialise restaurant and second is an indoor object as return type.
So in this case, we the Debbie Initialise restaurant instance in line and initialize Debbie Field of
Debbie initializes struck by the Debbie connection that created from open function.
So we write her return.
Ampersand dealing shall either.
And initialize Dib Field by DB connection, DB field by DB Connection and CIP mean as inner value
reformat the code and save the project.
OK, we could create a connect function to communicate with database 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.