I am very new to MVC
and Sails.js
. I just started learning it yesterday and tried to learn it by doing something. But I am having some confusions regarding Sails models.
After creating the application, I configured the database in config/connection.js
. Then I created a blueprint api
named user
. Next thing I did is I started the server and loaded following url:
http://localhost:1337/user/create?user=Mr.X
I didn't configure anything in api/models/user.js
. So it is not supposed to save any data in database. When I browse my database as expectedly I can't see any record. But when I load the following url:
http://localhost:1337/user/
I can see the record of Mr.X
there. And even if I restart the server the record of Mr.X
is still there. What I can't understand is, how is it happening? How is Sails saving this data without affecting the configured database? Is it normal thing in all MVC
frameworks or just Sails do that?
I am very new to MVC
and Sails.js
. I just started learning it yesterday and tried to learn it by doing something. But I am having some confusions regarding Sails models.
After creating the application, I configured the database in config/connection.js
. Then I created a blueprint api
named user
. Next thing I did is I started the server and loaded following url:
http://localhost:1337/user/create?user=Mr.X
I didn't configure anything in api/models/user.js
. So it is not supposed to save any data in database. When I browse my database as expectedly I can't see any record. But when I load the following url:
http://localhost:1337/user/
I can see the record of Mr.X
there. And even if I restart the server the record of Mr.X
is still there. What I can't understand is, how is it happening? How is Sails saving this data without affecting the configured database? Is it normal thing in all MVC
frameworks or just Sails do that?
2 Answers
Reset to default 7I'm guessing that you set up a connection in config/connections.js, but didn't specify a default connection in config/models.js, so your app is still using the default localDiskDb
connection. You can see this database by opening the .tmp/localDiskDb.db file in your project. It's a pretty handy development tool.
See the docs for config/models.js for more info on global model settings. You can also set a connection on a per-model by basis using the connection
property in the model's class file (e.g. api/models/User.js).
All your user data gets stored in localDiskDb.db by default. You can Use postman app for retrieval and insertion of records. Its better for you to first go through these videos. https://www.youtube./watch?v=60PaCpTP5L4&list=PLLxyAuVpwujMQjlsF9l_qojC31m83NOCG&index=2
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745093672a4610844.html
评论列表(0条)