Experimenting with backbone-relational; I'm using Indexeddb to store all my data, is it possible to use backbone-relational without a backend and just let it talk to Indexeddb?
Thanks in advance,
James
Here is link to a similar question.
TL/DR: If you don't need to retrieve or store data on the server side there is no need for backend logic development.
Backend is not required.
Backbone can fully work without any backend if your application
doesn't require one.
That depends on your application. If you want to retrieve value of
some inputs and calculate a result then Backbone won't do that for
you - it will help you structure your code. If you app is simple and
don't need support for models, views and collections or routing,
then there is no point in using Backbone. Hard to answer this
question.
Related
I'm currently writing a program that is a To-Do list that just runs locally on my machine in the terminal screen(written in node.js, no extra dependencies). I've set up everything and it works totally fine, but I have never actually used any databases other than just session cookies on the browser. What would you all suggest I use when all I want to do is learn how to store some simple data in a database and then be able to manipulate it in the same fashion.
Any help would be greatly appreciated on this one! I'm really just looking for suggestions on a good database, as well as a bit of guidance on the best way to use that particular technology. I'm familiar with SQL and NoSQL databases, but like I said, I have never even used one on an actual application.
Thanks in advance.
In my view, You can use mongodb which is easy to configure and manipulate data. It helps you to work on json objects directly from database. Use express to create your RESTful endpoints and exposed data. Sometime back i use it for angular application, repo link is below for your reference :
AngularJs, ExpressJs, MongoDB application
Hope this helps.
Cheers
You can use sqlite which provides a good SQL API but keeps things very simple by simply using a file on your disk and accessing it through code directly in your application. You don't need to start another server and take care of configuring it.
For a simple To-Do list that should be more than adequate for storing your data whilst keeping your configuration simple and easy.
Here's a tutorial on how to set it up:
http://www.sqlitetutorial.net/sqlite-nodejs/
You'll essentially be using the sqlite3 npm package: https://www.npmjs.com/package/sqlite3
That page also comes with brief usage instructions.
Nodejs has client libraries for database interaction
Ex.
For SQL database:
postgresql : https://github.com/brianc/node-postgres
For NoSQL db:
mongodb : https://github.com/Automattic/mongoose
You can also create pool of db connections
I'm developing an app for Firefox OS and I need to retrieve/sent data from/to my DB. I also need to use this data in my logic implementation which is in JS.
I've been told that I cannot implement PHP in Firefox OS, so is there any other way to retrieve the data and use it?
PS: This is my first app that I'm developing, so my programming skills are kind of rough.
You can use a local database in JS, e.g. PouchDB, TaffyDB, PersistenceJS, LokiJS or jStorage.
You can also save data to a backend server e.g. Parse or Firebase, using their APIs.
Or you can deploy your own backend storage and save data to it using REST.
You should hold on the basic communication paradigms when sending/receiving data from/to a DB. In your case you need to pass data to a DB via web and application.
Never, ever let an app communicate with your DB directly!
So what you need to do first is to implement a wrapper application to give controlled access to your DB. Thats for example often done in PHP. Your PHP application then offers the interfaces by which external applications (like your FFOS app) can communicate with the DB.
Since this goes to very basic programming knowledge, please give an idea of how much you know about programming at all. I then consider offering further details.
It might be a bit harder to do than you expect but it can be easier than you think. Using mysql as a backend has serious implication. For example, mysql doesn't provide any http interfaces as far as I know. In other words, for most SQL based databases, you'll have to use some kind of middleware to connect your application to the database.
Usually the middleware is a server that publish some kind of http api probably in a rest way or even rpc such as JSONrpc. The language in which you'll write the middleware doesn't really matter. The serious problem you'll face with such variant is to restrict data. Prevent other users to access data to which they shouldn't have access.
There is also an other variant, I'd say if you want to have a database + synchronization on the server. CouchDB + PouchDB gives you that for free. I mean it's really easy to setup but you'll have to redesign some part of your application. If your application does a lot of data changes it might end up filling your disks but if you're just starting, it's possible that this setup will be more than enough.
I am using Sequelize as my server side ORM. Is there a recommended approach towards sharing the Model code (especially the validations) with my client application ?
Please don't recommend solutions which require me to move to a NoSQL database. Currently that is not an option for me. While I really Sequelize as an ORM, I am willing to move onto some other model implementation if it is beneficial.
Persistencejs, but it doesn't appear to be as well maintained as Sequelize:
https://github.com/zefhemel/persistencejs
At present there does not seem to be an end to end solution ie. a model library which you could just require in either browser or server and define your models - where methods like save, update would be polymorphic requiring the developer to just extend standard model classes and use them on either client or server.
However, for people looking for a similar solution - I recommend using JSON schema validators, which are quite hassle free and provide a simple means to share your validation logic between client and server.
I apologize if this question is not specific enough, but I do need some help understanding this concept. I've been researching many Javascript libraries including JQuery, MooTools, Backbone, Underscore, Handlebars, Mustache, etc - also Node.js and Meteor (I know all those serve different purposes). I have a basic idea of what each does, but my question is mainly focused on the templating libraries.
I think the general idea is that the template will be filled by a JSON object that's retrieved from the server. However, i'm confused by how that JSON object is formed, and if it can go the other way to the backend to update the database. Please correct me if this is incorrect.
For a more solid example, let's say I have Apache running on Linux, and am using MongoDB as the database and python as my primary language. How do all these components interact with the templating library and each other?
For example, if I have an HTML file with a form in it and the action will be set to some python script; will that script have to retrieve the fields, validate them, and then update them in the DB? If it's MySQL I'd have to write a SQL statement to update it, but with Mongo wouldn't it be different/easier since it's BSON/JSON based?
And for the other example, let's say I have a view-account.html page that will need to pull up user information from the DB, in what form will it pull the information out and how will it fill it into the template? I'm guessing i'd have to have a python script that pulls the information from the DB, create a JSON object, and use it to populate the fields in the html template.
I am aware there are web frameworks that will ease this process, and please suggest any that you would recommend; however, I'm really interested in understanding the concepts of how these components interact.
Thanks!!
There are obviously many ways this can all work together, but it sounds like you have the (a) right idea. Generally the frontend deals with JSON, and the server provides JSON. What's consuming or providing those responses is irrelevant; you shouldn't need to worry that Mongo is your database, or that underscore is handling your templates.
Think of your frontend and backend as two totally separate applications (this is pretty much true). Ignore the fact that your frontend code and templates are probably delivered from the same machine that's handling the backend. Your backend is in the business of persisting data, and your frontend in the business of displaying it.
RE: Mongo using JSON/BSON; The fact it uses the same language as your frontend to communicate is a red herring. Your DB layer should abstract this away anyway, so you're just using Python dicts/tuples/etc to talk to the database.
I'm guessing i'd have to have a python script that pulls the information from the DB, create a JSON object, and use it to populate the fields in the html template.
Spot on :)
I am just getting into backbone.js and am finding progress a little slow. My main problem is working out how to keep my client and server side models in sync using socket-io (technically I am using now.js but the same principal should apply).
I think the best way is to override the sync method but some simple advice would be really welcome.
Simply overwrite Backbone.sync so that it sends messages down socket.io and tells the relevant backbonejs models on the server to alter state.
The interesting part of this solution is setting up the master-master relationship. You need to insure that for any client they can only "update" the state of models on the server that they have "ownership" of to avoid hackers and server-side state corruption.
So for each client they have a set M where that client is the master of all models in M and has a set S where that client has slaves of all the models in S.
It can only force updating on the server of models in M and only one client should have a particular model in M (or you need to implement a solid locking / merging implementation).
Whenever a model on the server is updated you simply push out to any client who has that model in S. (and push to any client who has that model in M if the model is in M for multiple clients).
A lot of thought needs to go into control / permissions and ownership that is normally handled by the MVC controller once a client POST/PUT/DELETE some data.
Check out backbone.iobind: https://github.com/noveogroup/backbone.iobind
It overrides Backbone.sync for you.
A much better approach is event-driven architecture using an event aggregator. Great read on the subject is the following Derick Bailey's article => Decoupling Backbone Apps From WebSockets
It keeps stuff highly decoupled, enables easier testing and changing websockets lib, and on top of it all, it doesn't mess up with overriding Backbone's internals like sync()
Maybe this excellent tuto will help you:
https://blog.andyet.com/2011/02/15/re-using-backbonejs-models-on-the-server-with-node