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'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.com/watch?v=60PaCpTP5L4&list=PLLxyAuVpwujMQjlsF9l_qojC31m83NOCG&index=2
Related
I have already found many answers about this like link
But I don't think it really solves my problem,
I still can easily get my database instance in client side:
firebase.initilizeApp(config);
db = firebase.firestore();//db can be considered as an instance
Then simply type code in Chrome console:
db.collection("abc").where("id","===","1").get().then(function(){//do something})
to get my data.
However I still want the client side is able to do CRUD but only through the page events like click or drag or something else.
So in such situation, is it possible to achieve it?
When you add a website to your firebase project where you would like to access the database, you're defining which URL cann access the database...
Checking authentication and integrity needs to be managed by the database rules though.
Therefore, once you've connected to the app and can fetch data, you can of course also do CRUD operations and create/read/update/delete data in there...
If you want to, you can of course also utilize Firebase functions as a bridge between website and database... there you could define REST-Calls that write or read from the database. However, you need to make sure to add authentication stuff there as well to prevent unallowed access.
I'm using passport.js and MongoDB for user login and postAPI authentications. However whenever I deploy my node server to another AWS instance, I need to go through the signup process, do the login and get a new token.
I know I can see the saved users and their jwt tokens from MongoDB. Are there anyway that I can copy the token and, when initialize new database, save the same username-jwttoken pair by default, so I can use the same token string (not with password, though it is more easily to be done) to pass the passport authentication test?
Thanks!
It sounds like your deployment process involves tearing everything (application and MongoDB) down & rebuilding from zero, possibly with some seed data but without any of the "live" data in the AWS instance. Here are a couple of ideas:
copy all the data from the old MongoDB instance to the new one as part of your deployment process. This will ensure that the users are present on the new instance and (should) ensure that users don't have to go through the signup process again. I'm not too familiar with MongoDB so I don't know how to do this, but I'm sure there's a way - maybe you can copy the data files from one to the other?
set up your environment with two servers: a MongoDB server and an application server. This way you can tear down your application and create a new AWS instance just for the application without touching your MongoDB server. Just update the MongoDB connection configuration in your new application instance to point to the same MongoDB server you've been using.
The first option is more suitable if you have a very small application without too much data. If your database gets too large, you're going to experience long periods of downtime during deployment as you take the application down, copy the data out of the old Mongo instance, copy the data into the new Mongo instance, and bring the application back up.
The second option is probably the better one, although it does require some knowledge of networking and securing MongoDB so that only your application has access to your data.
I work on a web app which store projects data. Data are saved in a couchDb database A. The app pull and push data with a local pouchDb database B, which is sync with A.
So the app can also work offline. When user has connection back, changes made on localDb B during offline time are sent to A using a classic replication.
I store 1 document per project in couchDb, it is a big JSON object with lot of data (project todos, collaborators, advancements, risks, problems, etc...).
It is working like a charm, but I have some problems, and it seems I use pouchDb in wrong way. Situation example:
User A is offline and he adds a todo on project 1.
User B is online and he adds a new collaborator on project 1.
User B changes are pushed to couchDb by the automatic sync.
The project 1 _rev has been incremented.
User B pulls its own changes from couchDb, because the app downloads all documents on any couchDb changes detected. Weird... Idk how to prevent that. But the app still work fine so it's not a big problem.
User A gets its connection back.
User A changes are ignored because of older _rev. But the user did a modification on a different project property, can couchDb detect that himself and merge with newer _rev ?
I clearly see my problem is I'm using 1 document per project. I could use thousands documents to store each properties of each project and my problem woudn't happens, but it seems quite weird: To retrieve all data of a project I would fully scan my database, check document type (collaborator, todos, ...?), and check if the document is linked to the project by adding a new _projectId property to any document.
Currently I just have to request one document, which contains all project data, then I manipulate my JSON easily. It's quite convenient to handle.
How to manage this ? A project may contains averagely 10 to 10 000 properties that multiple users can edit being online or offline.
But the user did a modification on a different project property, can couchDb detect that himself and merge with newer _rev ?
PouchDB/CouchDB conflict handling is described in the PouchDB guide: http://pouchdb.com/guides/conflicts.html
the app downloads all documents on any couchDb changes detected. Weird... Idk how to prevent that.
This is standard PouchDB/CouchDB behavior - you asked it to sync the whole database, so it synced the whole database. :) You can prevent it by using filtered-replication: http://pouchdb.com/api.html#filtered-replication.
How to manage this ? A project may contains averagely 10 to 10 000 properties that multiple users can edit being online or offline.
It really really depends on your data, how frequently it may change, what the unique identifier of a single "property" is... Storing 10,000 separate documents in PouchDB/CouchDB is not a crazy idea, though, and may help you out when it comes to conflicts, since only those individual documents can ever be in conflict.
In general, I'd recommend you read the guide to conflict resolution as described above and review your options. There's also a plugin that may help you with conflict resolution: https://github.com/jo/pouch-resolve-conflicts
I am working on application which uses GWT as front end and Hibernate 4.0 Framework. I am using SQL 2008 (R2). My application is purely DB Driven. And the application would get launch at multiple portals simultaneously with different DB. Right now, the problem which I am facing is, I have to deploy as many wars as many DBs are there for each Portal. Is there any way with Hibernate to make it configurable? Means After loading my Homepage after entering db name, db user_name and db password it gets connected to the DB.
I would also bring you notice that my Homepage gets loaded in JSP. And after login it is calling GWT Entrypoint.
As said by #ToddMurray in the comments, you should use a configurable JNDI dataSource. It's the preferred way to go with containers like JBoss. See here for a config example.
Another way to go is with Hibernate properties: read the documentation here.
I have to create a Windows Phone 7 app as part of a research project. The app needs to:
Allow the user to login by connecting to an sql server database (stored locally for the purpose of this project)
If login successful, return a list of products associated with the user (i.e. in product table where UserID=x)
User can click on an item in the list, and then add photos for that item. This can be done offline as well (using HTML5 offline storage)
When an internet connection is available again, user can click 'Upload' (or automatically synced, but not necessary) and the images are all uploaded to the Images table with the correct ProductID as Foreign key
Since this is the first time I am doing any mobile programming, I am not sure what is the best approach. I am especially unsure of how I am going to connect to the database. I'm not really interested in learning Silverlight, so the app should use mainly HTML5 and javascript, I also am looking into JQueryMobile.
I have already installed PhoneGap and am trying it out, but my main concern is how to connect the app to the database as I am having trouble finding the 'proper' way of doing this e.g. using some kind of web service or directly through javascript (read it can be done but is not recommended). If anyone could recommend or suggest a good approach of doing this that would be great!
SqlServer is only available on the phone via LinqToSql which you need to expose via a service or a DAL. I dont think that its possible to make calls directly from Javascript to LinqToSql on the phone.
If you're not set on the idea that the DB needs to be on the phone, you can just make service calls via ajax to a server and access the db that way. I recently did a blog post exposing a db via a WCF Data service and consuming it on the phone. It doesn't cover calling it via ajax but should help get you started.
http://www.ritzcovan.com/2012/02/building-a-simple-windows-phone-apppart-4/
If you want to store data within the WP7 database, use the PhoneGap storage APIs.