1 00:00:12,190 --> 00:00:17,440 Hello and welcome to the Golang programming language course in this session. 2 00:00:17,470 --> 00:00:23,830 We want to create another function to delete a student from a student hated in-person database. 3 00:00:25,390 --> 00:00:27,310 First, go to the DV connection. 4 00:00:27,310 --> 00:00:27,880 Five 5 00:00:31,180 --> 00:00:38,920 Define the function name delete that receives the idea of the recall to be deleted as an input parameter 6 00:00:38,920 --> 00:00:43,900 and delete the records from the database and return the number of rows affected. 7 00:00:44,230 --> 00:01:02,110 So we write, func delete, sit and eat value like idea as input parameter idea and and return and 64 8 00:01:02,120 --> 00:01:05,200 type in 64. 9 00:01:06,700 --> 00:01:13,330 OK, now calling conic function for initializing MySQL driver naming data source name. 10 00:01:13,810 --> 00:01:22,060 This function returns a DB object from a school package DB call and he calls calling connect function 11 00:01:24,790 --> 00:01:27,310 defer to closing the creator DB object. 12 00:01:33,340 --> 00:01:39,520 After creating a deep object from a school package, we invoked PRETER method that creates a prepared 13 00:01:39,520 --> 00:01:42,460 statement for later queries or execution. 14 00:01:43,810 --> 00:01:45,850 This function returns to values. 15 00:01:45,850 --> 00:01:52,360 First is team to object from a school package that is a prepared statement, and the other is an enrolled 16 00:01:52,360 --> 00:01:52,870 object. 17 00:01:53,110 --> 00:02:01,540 So first define two variables like delete and add or delete comma error. 18 00:02:01,660 --> 00:02:08,200 Cullen equals and calling prepare function on DB optic db dot preter. 19 00:02:10,640 --> 00:02:13,190 Right, sweet email query for delete an object. 20 00:02:13,280 --> 00:02:24,920 Delete that on is still there and set very close as condition there IDG calls and sit question marks 21 00:02:25,100 --> 00:02:37,400 instead of value for IED check error status locked at all and without an. 22 00:02:41,760 --> 00:02:47,490 Now calling exec -- or throwing a Stewart package and executes a prepared statement with the given 23 00:02:47,500 --> 00:02:51,940 arguments and return a result summarizing the effect of the statement. 24 00:02:52,500 --> 00:02:58,500 This method returns to values first analogical reasoning their faith and the other is an error object. 25 00:02:58,920 --> 00:03:09,390 So first, define two variables like result and error resolved comma l equals and column execute method 26 00:03:09,390 --> 00:03:17,820 and delete object delete dot execute, said the student ideas condition for work laws that we received 27 00:03:17,850 --> 00:03:19,410 it as input from three. 28 00:03:19,410 --> 00:03:31,860 Instead, question marks prepare a statement idea first error a status, if at all, like that of error 29 00:03:31,860 --> 00:03:39,510 dot and are now calling rose effect that function from a school package that returns a number of roles 30 00:03:39,510 --> 00:03:41,130 affected by an update. 31 00:03:41,130 --> 00:03:42,210 Insert or delete. 32 00:03:42,510 --> 00:03:45,870 Not every database or database driver may support this. 33 00:03:46,260 --> 00:03:52,230 This function returns to values first in N64 value, and the other is an error object. 34 00:03:52,590 --> 00:03:58,230 So first, define two variables like rows affected and add all roles 35 00:04:00,540 --> 00:04:01,440 affected. 36 00:04:01,830 --> 00:04:03,750 Comma error call equals 37 00:04:06,180 --> 00:04:18,150 resolved that roles affected check error status, if at all like dot, fatal error, dot arrow 38 00:04:21,270 --> 00:04:32,970 and now return roles affected as a return value retailer rose, it reformat the code and saved the project. 39 00:04:33,300 --> 00:04:40,080 Now we could define the function name, delete that, accept student ideas parameter and delete that 40 00:04:40,080 --> 00:04:44,540 record from the student table in person database and returns the roles affected. 41 00:04:44,550 --> 00:04:45,090 No. 42 00:04:47,130 --> 00:04:54,660 Now go to my school database and see a student table execute the select query. 43 00:04:55,740 --> 00:04:58,110 Now we can see the student table. 44 00:04:58,740 --> 00:05:01,980 In this case, we want to delete a student in-person database. 45 00:05:02,220 --> 00:05:08,520 For example, we see I.D. five name is Jack and ages 40. 46 00:05:08,760 --> 00:05:10,260 We want to delete this record. 47 00:05:10,530 --> 00:05:13,290 Now go to the school program and continue. 48 00:05:13,830 --> 00:05:20,280 So we should use front delete function from DB tools that accept the student I.D. to be deleted as the 49 00:05:20,280 --> 00:05:21,690 input parameter. 50 00:05:23,280 --> 00:05:25,050 Go to the main function. 51 00:05:25,830 --> 00:05:27,600 First, clear the last code. 52 00:05:30,510 --> 00:05:33,300 First, define the variable roles affected. 53 00:05:33,300 --> 00:05:44,670 Rows affected column equals and calling delete function from DevTools Paquet DevTools package and column 54 00:05:44,670 --> 00:05:52,730 delete function and send a student I.D. to be deleted as argument for the example. 55 00:05:52,740 --> 00:05:53,790 Set I.D. 56 00:05:54,090 --> 00:05:54,690 Five. 57 00:05:56,430 --> 00:06:10,260 Go to the next line and display rows affected value if the rows affected and set rows affected variable 58 00:06:10,470 --> 00:06:12,630 rows affected. 59 00:06:12,630 --> 00:06:17,580 Reformat the code and save the project and execute the program. 60 00:06:17,850 --> 00:06:19,500 Go wrong. 61 00:06:19,560 --> 00:06:20,760 Got lists. 62 00:06:20,790 --> 00:06:24,330 Main main dot go. 63 00:06:27,730 --> 00:06:36,040 Now we can see the output rose affected one, go to the Maya Stuart and see the changes before we execute 64 00:06:36,040 --> 00:06:36,940 the select query. 65 00:06:37,060 --> 00:06:41,590 We see I.D. number five name is Jack and age is 40. 66 00:06:42,730 --> 00:06:44,710 Now execute the select query. 67 00:06:45,880 --> 00:06:53,500 Now we see the student by I.D. number five was removed from the person database and one row is affected. 68 00:06:55,780 --> 00:06:56,200 OK. 69 00:06:56,650 --> 00:07:02,530 In this part of the tutorial, we first talked about the database and its related concepts. 70 00:07:02,830 --> 00:07:09,370 And we were able to do crowd operations both inside the MySchool database and inside the go programming 71 00:07:09,370 --> 00:07:12,760 language in designing this example. 72 00:07:12,940 --> 00:07:19,600 We tried to separate the layers so that we could design the program as an object oriented or microservices 73 00:07:19,600 --> 00:07:20,080 program. 74 00:07:20,950 --> 00:07:28,030 For example, the database layer and the modeler and the Marlar are separate, and these features causes 75 00:07:28,030 --> 00:07:34,750 each part of the program to have its own place, and the layers are separated from each other and our 76 00:07:34,750 --> 00:07:37,210 courts are arranged in the beautiful order. 77 00:07:37,510 --> 00:07:44,680 And it will be possible to use your layer in other applications, and you can use each layer if necessary 78 00:07:44,680 --> 00:07:45,760 by calling it. 79 00:07:46,030 --> 00:07:50,590 And we don't have to implement all your programs in one layer. 80 00:07:51,160 --> 00:07:52,930 We have reached the end of decision. 81 00:07:53,050 --> 00:07:57,130 I hope you have taken full advantage of this session until next session. 82 00:07:57,160 --> 00:07:57,760 Goodbye.