1 00:00:12,800 --> 00:00:16,340 Hello and welcome to the Golang programming language course. 2 00:00:16,880 --> 00:00:23,450 In the previous session, we talked about rest APIs concept, and in this session we want to talk about 3 00:00:23,450 --> 00:00:24,500 the other concept. 4 00:00:30,260 --> 00:00:37,190 Now, it's time to do a project in decision to practice this section. 5 00:00:37,460 --> 00:00:43,250 We want to establish a connection between the client and the server and the database through the rest 6 00:00:43,280 --> 00:00:45,040 APIs and go link. 7 00:00:46,910 --> 00:00:53,600 It is important to note that the client cannot communicate directly with the database, but the client 8 00:00:53,600 --> 00:00:58,430 is connected to the server and the server is directly connected to the database. 9 00:00:59,630 --> 00:01:07,070 The client sends its request to the server and the server analyzes Dan and sends the appreciated request 10 00:01:07,070 --> 00:01:13,760 to the database and receives the response from the database and sends its response to the client. 11 00:01:14,840 --> 00:01:21,230 This program consists of two main layers a database layer and the rest layer. 12 00:01:22,550 --> 00:01:29,840 In this example, we have a person database that contains a student table, which contains table information 13 00:01:29,840 --> 00:01:36,830 like Aidid name and age that we have to perform crowd operation using my school database. 14 00:01:38,030 --> 00:01:43,610 Therefore, we will use the student table in the person database that we created in previous courses 15 00:01:43,610 --> 00:01:45,350 to connect to the GO program. 16 00:01:47,420 --> 00:01:51,770 Now let's go to the school program to implement this project. 17 00:01:52,130 --> 00:01:58,910 First, go to Package Explorer and go to the source folder and create a project folder named like Rest. 18 00:02:04,190 --> 00:02:07,580 Because in this tutorial, we use school database. 19 00:02:07,820 --> 00:02:10,580 We need a driver to connect to my school. 20 00:02:11,000 --> 00:02:16,190 So first, we should prepare and install my school drive in our project. 21 00:02:16,790 --> 00:02:22,040 So run the MySchool Driver installation comment and turn first. 22 00:02:22,040 --> 00:02:23,690 Go to Project Folder. 23 00:02:23,780 --> 00:02:25,640 See the list. 24 00:02:27,200 --> 00:02:33,590 Go get dash you key top. 25 00:02:36,040 --> 00:02:39,700 That call is let's go. 26 00:02:40,540 --> 00:02:43,660 That's Samuel Dash Driver. 27 00:02:44,920 --> 00:02:46,270 This les my cue. 28 00:02:57,500 --> 00:02:57,840 OK. 29 00:02:57,860 --> 00:02:58,950 The driver has in the. 30 00:03:00,320 --> 00:03:08,600 It's time go to create database live, so go to Project Folder and create another folder name like database. 31 00:03:11,900 --> 00:03:13,430 Later this. 32 00:03:18,770 --> 00:03:26,060 We want to create the database connection settings as a Jason Fine, so go to the database folder and 33 00:03:26,060 --> 00:03:29,420 create another folder named like configuration. 34 00:03:33,580 --> 00:03:35,350 And the reason. 35 00:03:39,130 --> 00:03:47,050 And inside the configuration folder, we create the find called config with the JSON extension, which 36 00:03:47,050 --> 00:03:53,890 is supposed to include the settings for the connection of the Go program with the MySchool database. 37 00:03:56,170 --> 00:03:58,150 We got Jace. 38 00:04:02,780 --> 00:04:07,250 The program requires two main settings to connect to the database. 39 00:04:07,790 --> 00:04:11,810 First is driver name and second is data source name. 40 00:04:12,950 --> 00:04:20,900 Driver name is my secure and data source name is a combination of username, password and database name 41 00:04:21,200 --> 00:04:22,850 that we want to connect it. 42 00:04:24,230 --> 00:04:30,440 The pattern of the data source name is database username, column database passport. 43 00:04:30,770 --> 00:04:40,070 Assign this database name, so overwrite adjacent file for settings of database calibrations. 44 00:04:41,570 --> 00:04:42,380 Driver name 45 00:04:46,550 --> 00:04:56,810 column In this case, my driver name is Mica said on and go to next line and data source name data. 46 00:04:57,380 --> 00:05:05,480 Source two Main column My database username is root 47 00:05:08,570 --> 00:05:10,380 and my database passport. 48 00:05:10,400 --> 00:05:11,420 Here is Oracle. 49 00:05:15,200 --> 00:05:20,960 At Sign Class and database name person, 50 00:05:23,930 --> 00:05:28,580 now we could create a JSON file for connection to my skill database savings. 51 00:05:30,950 --> 00:05:37,670 It's time go to create a model, so in database folder, create another folder name like model. 52 00:05:42,540 --> 00:05:52,500 Model in model folder, we create a file like named a student or go inside it, and we are going to 53 00:05:52,500 --> 00:05:58,080 create a structure equivalent to a student, tailored my Oscar database. 54 00:05:58,530 --> 00:06:04,080 So create a fine line student that go. 55 00:06:08,850 --> 00:06:16,230 So go to a student, find and create this, try and name a student with fields such as fields are stored 56 00:06:16,230 --> 00:06:17,940 inside the MySchool database. 57 00:06:17,940 --> 00:06:19,920 So right package 58 00:06:24,210 --> 00:06:24,780 model 59 00:06:28,320 --> 00:06:33,370 type student strong. 60 00:06:36,810 --> 00:06:39,750 Set a common for this as strong as exporter. 61 00:06:43,870 --> 00:06:44,680 Student. 62 00:06:47,550 --> 00:06:57,210 And define false I.D. prices in name type is strange. 63 00:07:01,480 --> 00:07:13,630 And each time is it's OK now it's time to implement database methods in project folder, go to database 64 00:07:13,630 --> 00:07:22,090 layer and create another folder named like DV tools and create a file inside it like named DB Connection 65 00:07:22,090 --> 00:07:22,690 that go. 66 00:07:22,930 --> 00:07:33,400 That file contains methods to interact with the database, create a folder like DV tools and create 67 00:07:33,400 --> 00:07:36,880 a file like DV connection. 68 00:07:37,120 --> 00:07:40,540 DV connection that glue. 69 00:07:44,900 --> 00:07:48,440 Before creating any connection, there are two things to do. 70 00:07:48,980 --> 00:07:55,220 First, import MySchool driver, top of database tools package, so the right package. 71 00:07:58,190 --> 00:07:59,390 Database 72 00:08:02,090 --> 00:08:02,780 import. 73 00:08:06,550 --> 00:08:12,700 Underlying guitar dot com. 74 00:08:13,450 --> 00:08:14,950 Let's let's go. 75 00:08:14,980 --> 00:08:22,000 Dash secure dash driver discussion my skewered 76 00:08:26,590 --> 00:08:35,980 second define global variable named driver name and data source name as Airstream type, that driver 77 00:08:36,640 --> 00:08:48,460 made history and their data source named as best. 78 00:08:52,840 --> 00:09:01,000 Now create and initialize a function to be able to initialize these two variables from other packages. 79 00:09:01,660 --> 00:09:10,060 This method receives two values of driver name and data source name as input parameters and uses them 80 00:09:10,060 --> 00:09:17,020 to initialize the global variable of package until that other function can access their values. 81 00:09:17,320 --> 00:09:23,980 So right, func db initialize. 82 00:09:28,740 --> 00:09:40,950 RD and as driver name and D as an as driver soul's name by the time is string. 83 00:09:45,710 --> 00:09:59,270 Initialize the global variable, but this variable driver name equals DNA, and in the next line, data 84 00:09:59,270 --> 00:10:03,540 source name equals the S10. 85 00:10:05,600 --> 00:10:13,970 Now we want to design a method whose task is to connect the program to the MySQL database and return 86 00:10:13,970 --> 00:10:17,240 a database object from IS to a package. 87 00:10:18,680 --> 00:10:26,120 For example, we create the function named Connect that is stored by the lowercase character because 88 00:10:26,120 --> 00:10:31,850 we want to use this function just to this package, and we don't use it to either package. 89 00:10:32,060 --> 00:10:33,110 So we write 90 00:10:35,540 --> 00:10:36,140 phone 91 00:10:39,110 --> 00:10:39,770 next. 92 00:10:44,500 --> 00:10:56,680 And return type is the object by the time it's El DB DB point of secure that 93 00:10:59,710 --> 00:11:00,070 theory. 94 00:11:05,300 --> 00:11:11,750 The required metal to connect to the database is the open function of the school package. 95 00:11:12,140 --> 00:11:19,670 So we should import the school package up function opens a database is specified by its database driver 96 00:11:19,670 --> 00:11:26,900 name and a driver specific data source name usually consisting of apps list a database name, connection 97 00:11:26,900 --> 00:11:36,980 information and it returns VB object and it will so first define two variables like Debbie and Arrow. 98 00:11:37,490 --> 00:11:43,580 Calling equals in calling open function from a school package and set driver name and data source name 99 00:11:43,580 --> 00:11:44,750 and parameters. 100 00:11:45,210 --> 00:11:53,840 School that open and set driver name and data source may. 101 00:11:59,900 --> 00:12:02,030 Now, check your status if 102 00:12:04,670 --> 00:12:09,350 error not equals mean, lock the fatal 103 00:12:11,960 --> 00:12:12,980 error darts. 104 00:12:17,050 --> 00:12:17,440 Terror. 105 00:12:23,130 --> 00:12:29,850 And return Creedy object as return type, return de. 106 00:12:35,290 --> 00:12:35,650 OK. 107 00:12:36,100 --> 00:12:41,740 In order not to prolong the time of decision, we will finish it and we will continue the content in 108 00:12:41,740 --> 00:12:42,730 the next session. 109 00:12:43,010 --> 00:12:43,540 Goodbye.