我最近有点讨厌使用JSON/Rest服务,并在服务器上手动键入在数据库上执行基本CRUD操作的方法。
我想做的是,在javascript (基于ajax的应用程序)中做一些形式
var allStudents = students.getAllStudents(); // returns all items of the students table
var student = new student();
student.name = "Joe";
student.address = "123 Sesame st";
students.add(student); // commits it to the students table
var student = students.getStudentById(57);现在,就像任何ORM一样,所有这些方法都会自动/为我编写。
还要注意,我并不是说Javascript应该直接与数据库对话。它仍然会进行Restful调用(在后台对服务器进行调用)。但我只希望这些crud操作对我来说是自动化的和透明的,这样我就不需要在服务器上手动写出这些操作。
你们知道有什么框架可以帮助实现这一点吗?
我的主要后端是Java/Spring3MVC。但我也想听听可能使用Node.js的想法。
发布于 2012-08-01 06:52:51
我还不确定与简单地编写Dojo请求相比,这是否节省了时间,但是我见过的一种解决方案是RESTful的JsonRest store,它的工作方式与您所描述的类似。就我个人而言,我发现显式编写ajax请求更具可读性,但是如果您不介意遵循Dojo关于如何构造请求的哲学,您可能会喜欢这样。无论如何,下面是文档页面中的一些代码:
require(["dojo/store/JsonRest"], function(JsonRestStore){
var store = new JsonRestStore({target: "/Table/" });
store.get(3).then(function(object){
// use the object with the identity of 3
});
store.query("foo=bar").then(function(results){
// use the query results returned from the server
});
store.put({ foo: "bar" }, { id: 3 }); // store the object with the given identity
store.remove(3); // delete the object
});发布于 2012-08-01 06:52:48
如果您可以使用像Backbone.js或Can.js (推荐)这样的东西来设计接口,并通过RESTfull服务与数据库无缝通信,那么如果您以前没有见过它,您会对此印象深刻。
http://backbonejs.org/ http://canjs.us/
两者都使用MVC结构,非常容易设置。看一下演示和示例。
发布于 2015-02-18 07:17:53
在寻找同样的东西时,我偶然发现了sproutcore records。看起来像javascript orm解决方案。
https://stackoverflow.com/questions/11750019
复制相似问题