I'm currently learning angularjs and trying to build a listapp.
I'm struggling with deciding which method of storage I should be using while building the prototype.
Currently I'm using an object that I bind to the scope but it's not working very well for me.
Listname
List type
List item
text
done
I want to be able to add, delete and edit from the storage.
Any suggestions, links, tutorials, guidance or whatever is appreciated!
Also I'm planning to move over to firebase later (I feel it just adds an extra layer of complexity atm while I'm learning angular).
For learning/prototyping you can use MongoLab database as a storage (up to 500 MB it's free). As MongoLab database is hosted, you don't have to care about configuring your development environment (i.e. installing database server, database client, or anything else). You just create some simple database on the web page (via GUI admin tool) and then use an URL in angularjs code like:
var url = "https://api.mongolab.com/api/1/databases/angularjs-intro/collections/users?apiKey=terrPcifZzn01_ImGsFOIZ96SwvSXgN9";
return $http.get(url);
See how it was used in this AngularJS tutorial.
if you're just learning/prototyping, local storage should suit your needs.
localStorage.setItem('key', 'value');
localStorage.getItem('key'); // returns 'value'
Related
I have a local container created with Docker with MongoDB & an express node server
What is the recommended way to populate it with new data?
1) Use the cli
2) Using Mongoose
3) Use a GUI such as Compass
Thanks!
I don't know if there's a 'correct' way to do this, but I've run a couple of 'seeds' files for my projects:
https://github.com/rmgreenstreet/surfShop/blob/master/seeds.js
https://github.com/rmgreenstreet/yelpcamp/blob/master/seeds.js
https://github.com/rmgreenstreet/custom-forms/blob/master/seeds.js
I almost wish there was some kind of niche field/need/position for being able to generate fake data!
The point is that you'll need to set and understand the structure of your data and essentially go through a bunch of nested loops for any connected/dependent data types.
Now if you're working with a SQL database, I'm totally clueless. That's next on my "things to learn" once I feel more comfortable with Javascript/NoSQL.
This would possibly depend on the usecase here,
Answer would be:
MONGOOSE : If you are planning to deploy an application using express. As mongoose goes hand in hand with express. (https://medium.com/#SigniorGratiano/mongoose-and-express-68994fcfdeff) As in many stacks like MEAN, MERN.
GUI like Compass: When you have to visualise the data or do ONE TIME OPERATIONS.
I want to make a JavaScript PhoneGap app being able to store information, like log in data or for a savegame, but obviously I'm not able to write into files with JavaScript ansd since this is supposed to work offline I am also not able to run a server script that manages it for me.
I'm pretty sure there is a way to do this and I'd be very thankful for your help!
You can use local storage. Local storage only stores strings, so you'll probably want to serialize JSON when saving to local storage. See is a breakdown of local storage size by browser.
var myData = { foo: "bar" };
localStorage.setItem("myData", JSON.stringify(myData));
var retrievedDataString = localStorage.getItem("myData");
var retrievedData = JSON.parse(myDataString);
Just like "dfsq" sayed, have you tried localStorage?
localStorage.userToken = "SomeData";
But remember, localStorage can only storage a max of 5mb of data and all the data is stored as String, for more than this or more flexibility with the type you will need another solution for your problem.
You better use a database. One of the good options are Firebase. https://www.firebase.com/ . Try its tutorial. It gives you offline capability as well. Also its FREE. ( For 50 concurrent connections )
What about using SQlite plugin for phonegap/cordova?
Cordova SQLite plugin
Many users, many solutions. In my mind the best way to do this would be with a WebSQL Database. You may have a look at http://www.html5rocks.com/de/features/storage - i know this site is in german but the graphic displayed there will give you a little overview. You'll see where you can use what kinds of databases.
WebSQL works like a charme and every of my apps with databases uses webSQL Databases. Its not just a good solution, it is the best one to be consistency. Normally you're using a MySQL DB on a WebServer for Logindata etc. if you have already all your data localy stored inside a WebSQL Database, you have also consistency of your
The question is about the general approach. For me, I try to present the problem using AngularJS with ngStorage.
Let's say I have something like this saved in local storage:
$scope.$storage = $localStorage;
$scope.$storage.food = { type: 'candy', eaten: false }
With this way, I've saved this in local storage. So next time a user visit my page, I know if he/she has eaten the candy. However, in the future, I change my app and change the structure of food.
So how should I update this? Two things must be took care of are:
Notify client of new structure for storing.
Integrate that change with the old storage.
My approach is using a version field to indicate changes, and upon seeing that, reset all clients storage.
This process is called "data migration" (i.e. upgrading a data structure as the application evolves). It's a well-known problem from the database world (and before that for config/preferences files).
The usual approach is to add a version in the header of the data structure. That means the header is always the same (or just changes in backwards-compatible ways) while the payload (the actual data) can change as much as it needs.
A simple solution just checks the version and uses defaults when the version doesn't match. More elaborate schemes contain migration code which can upgrade a data structure from version N to N+1. Control code will then apply all the migration steps necessary to upgrade all data structures to the latest version.
We have an SQLite database lying around, which is curerntly filled from an external batch job. The database is not very complex (essentially two tables in a 1:n relationship and some "catalog tables" holding lookup values).
We now have to add a user-frontend as well as some reporting. At one moment in time only one user is using the frontend, however, this should be possible from everywhere in our network (= wherever access to the SQLite file is possible).
What's the easiest way to create an easy-to-use frontend with as little effort as possible? I thought about using HTML/JS, but haven't found out how to access a local SQLite DB with JS (is this even possible? we could grant the application such access rights of course, however, do browsers even support this?)
If HTML/JS is not an option without a dedicated server, is there any other possiblity to get this done with little effort? We do not want to end up with MS Access... :(
Use the HTA application if not afraid of safety problems. Rename your html file to *.hta, make ODBC connection to your database then:
var Connection = new ActiveXObject ('ADODB.Connection');
Connection.Open (<ODBC-name>);
var Records = new ActiveXObject ('ADODB.Recordset');
Records.Open (Sql, Connection, 0, 2);
See the Properties & Methods for ADO Recordset Object.
I am playing around with CouchDB to test if it is "possible" [1] to store scientific data (simulated and experimental raw data + metadata). A big pro is the schema-less approach of CouchDB: we have to be very flexible with the metadata, as the set of parameters changes very often.
Up to now I have some code to feed raw data, plots (both as attachments), and hierarchical metadata (as JSON) into CouchDB documents, and have written some prototype Javascript for filtering and showing. But the filtering is done on the client side (a.k.a. browser): The map function simply returns everything.
How could I change the (or push a second) map function of a specific _design-document with simple browser-JS?
I do not think that a temporary view would yield any performance gain...
Thanks for your time and answers.
[1]: of course it is possible, but is it also useful? feasible? reasonable?
[added]
Ah, the jquery.couch.js (version 0.9.0) provides a saveDoc() function, which could update the _design document with the new map function.
But I also tried out the query function, which uses a temporary view. Okay, "do not use this in the real product, only during development"... But scientific research is steady development, right?
Temporary views are getting cached, as I noticed, and it works well for ~1000 documents per DB. A second plus: all users (think of 1 to 3, so a big user management is quit of an overkill) can work with their own temporary view.
Never ever use temporary views. They are really only there for dev and debugging purposes. For more information, see http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views (specifically the bold "NOTE").
And yes, because design documents are really just documents with special powers, you can run you GET/POST/PUT/DELETE methods on them. However, you will usually need admin privileges to do this. So, if you are allowing a client side piece of software to do that, you are making your entire database public for read/write access - this may be fine for your application, but is important to remember.
Ex., if you restrict access to your database, but put the username and password in client side javascript, then anyone can see that username and password.
Cheers.
I´ve written an helper functions for jquery.couch and design docs, take a look at:
https://github.com/grischaandreew/jquery.couch.js