You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: module3-crud-and-data-models/r1-schema-and-data-models/README.md
-25Lines changed: 0 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,20 +2,7 @@
2
2
3
3
A database schema is a blueprint or architecture of how our data will look. It doesn’t hold data itself, but instead describes the shape of the data and how it might relate to other tables or models.
4
4
5
-
<<<<<<< HEAD
6
5
For example, this is a `customer` schema in MongoDB using mongoose.
7
-
=======
8
-
A database model is a type of data model that determines the logical structure of a database. It is the high level design which defines the kind of tables, the `fields` in those tables and the `relations` between different tables.
9
-
10
-
The most popular example of a database model is the relational model, which uses a table-based format, which is the one we use in most SQL databases.
11
-
12
-
### What are database schemas?
13
-
14
-
A database schema is a `blueprint` or `architecture` of how our data will look. It doesn’t hold data itself, but instead describes the shape of the data and how it might relate to other tables or models.
15
-
16
-
For example, This is a `Customer` schema in mongoDB using mongoose.
Copy file name to clipboardExpand all lines: module3-crud-and-data-models/r3-model-view-controller/README.md
+15-4Lines changed: 15 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@
2
2
3
3
## Introduction to MVC projects
4
4
5
-
When beginning a new project, there are several different methods that can be used to set up the overall file structure and flow. One of the most commonly used architectural patterns is called MVC. This is an acronym for `Model`, `View`, `Controller`.
6
-
This pattern is favored because of its alignment with the computer science design principle, Separation of Concerns. By dividing up responsibilities within our file structure, we can encapsulate information to be referred to via abstraction and maintain cleaner codebases.
5
+
When beginning a new project (especially, when using express), there are several different methods that can be used to set up the overall file structure and flow. One of the most commonly used architectural patterns is called MVC. this acronym stands for "Model, View, Controller".
6
+
This pattern is favored because of its alignment with the computer science design principle, [**separation of concerns**](https://en.wikipedia.org/wiki/Separation_of_concerns). By dividing up responsibilities within our file structure, for example, we can have our db connection work in one file and api routes in another file, ...etc.
7
7
8
8
```
9
9
app-name-here
@@ -17,9 +17,17 @@ package.json
17
17
package-lock.json
18
18
```
19
19
20
+
### Components Of MVC
21
+
22
+
**Model:** This consists of the structure of our data and handle the database.
23
+
24
+
**View:** The part of our application which is shown to the user.
25
+
26
+
**Controller:** Controller has all the logic to control and respond to the action, the user performs using the views.
27
+
20
28
### Models
21
29
22
-
In the models folder, the files will contain our schema definition and expected fields for the model.
30
+
In this folder, you can write the functionality & logics related to the Database (if you aren't using ORM) like insert, fetch, update, delete queries. It takes the query request from the controller & sends the response back to the controller.
23
31
The naming convention for the model files is: `name-here-model.js`.
24
32
25
33
Here’s an example model using JavaScript and mongoose.
Controllers are the layer between the Model and the View. the views can use the controllers to `add`, `read`, `delete`, ...etc data.
64
+
In controllers, you can write the functionality & logic to develop dynamic web applications. It takes the data request from the views & sends it to the model and sends the response back to the views.
56
65
The naming convention for the model files is: `name-here-controller.js`.
In a back-end application, views are usually not implemented and rather we create a front-end app using maybe `React` to call our `api` end-points to manipulate the data in the back-end.
88
+
In this folder, you can write HTML code for displaying a web page on the web browser. You can send the data from the controller to view for displaying data dynamically.
89
+
In a back-end application, views are usually not implemented and rather we create a front-end app using maybe `React` to call our `api` end-points to manipulate and dispaly the data in the back-end.
80
90
81
91
## Resources
82
92
83
93
-[MVC Architecture with NodeJS and mongoose](https://medium.com/geekculture/mvc-architecture-with-express-server-e35aedfe7889)
To update an item, we need to first make sure it exist by using the id to find it and then updating it, using the`findByIdAndUpdate()`, and then save the new item in the database.
0 commit comments