最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How does Sails.js manages data without saving in database - Stack Overflow

programmeradmin1浏览0评论

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?

Share Improve this question asked Aug 27, 2014 at 12:57 taufiquetaufique 2,7711 gold badge31 silver badges40 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

I'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

发布评论

评论列表(0)

  1. 暂无评论