Hello and welcome to the Golang programming language course in this session.
We want to create another function to delete a student from a student hated in-person database.
First, go to the DV connection.
Five
Define the function name delete that receives the idea of the recall to be deleted as an input parameter
and delete the records from the database and return the number of rows affected.
So we write, func delete, sit and eat value like idea as input parameter idea and and return and 64
type in 64.
OK, now calling conic function for initializing MySQL driver naming data source name.
This function returns a DB object from a school package DB call and he calls calling connect function
defer to closing the creator DB object.
After creating a deep object from a school package, we invoked PRETER method that creates a prepared
statement for later queries or execution.
This function returns to values.
First is team to object from a school package that is a prepared statement, and the other is an enrolled
object.
So first define two variables like delete and add or delete comma error.
Cullen equals and calling prepare function on DB optic db dot preter.
Right, sweet email query for delete an object.
Delete that on is still there and set very close as condition there IDG calls and sit question marks
instead of value for IED check error status locked at all and without an.
Now calling exec -- or throwing a Stewart package and executes a prepared statement with the given
arguments and return a result summarizing the effect of the statement.
This method returns to values first analogical reasoning their faith and the other is an error object.
So first, define two variables like result and error resolved comma l equals and column execute method
and delete object delete dot execute, said the student ideas condition for work laws that we received
it as input from three.
Instead, question marks prepare a statement idea first error a status, if at all, like that of error
dot and are now calling rose effect that function from a school package that returns a number of roles
affected by an update.
Insert or delete.
Not every database or database driver may support this.
This function returns to values first in N64 value, and the other is an error object.
So first, define two variables like rows affected and add all roles
affected.
Comma error call equals
resolved that roles affected check error status, if at all like dot, fatal error, dot arrow
and now return roles affected as a return value retailer rose, it reformat the code and saved the project.
Now we could define the function name, delete that, accept student ideas parameter and delete that
record from the student table in person database and returns the roles affected.
No.
Now go to my school database and see a student table execute the select query.
Now we can see the student table.
In this case, we want to delete a student in-person database.
For example, we see I.D. five name is Jack and ages 40.
We want to delete this record.
Now go to the school program and continue.
So we should use front delete function from DB tools that accept the student I.D. to be deleted as the
input parameter.
Go to the main function.
First, clear the last code.
First, define the variable roles affected.
Rows affected column equals and calling delete function from DevTools Paquet DevTools package and column
delete function and send a student I.D. to be deleted as argument for the example.
Set I.D.
Five.
Go to the next line and display rows affected value if the rows affected and set rows affected variable
rows affected.
Reformat the code and save the project and execute the program.
Go wrong.
Got lists.
Main main dot go.
Now we can see the output rose affected one, go to the Maya Stuart and see the changes before we execute
the select query.
We see I.D. number five name is Jack and age is 40.
Now execute the select query.
Now we see the student by I.D. number five was removed from the person database and one row is affected.
OK.
In this part of the tutorial, we first talked about the database and its related concepts.
And we were able to do crowd operations both inside the MySchool database and inside the go programming
language in designing this example.
We tried to separate the layers so that we could design the program as an object oriented or microservices
program.
For example, the database layer and the modeler and the Marlar are separate, and these features causes
each part of the program to have its own place, and the layers are separated from each other and our
courts are arranged in the beautiful order.
And it will be possible to use your layer in other applications, and you can use each layer if necessary
by calling it.
And we don't have to implement all your programs in one layer.
We have reached the end of decision.
I hope you have taken full advantage of this session until next session.
Goodbye.