zackyang000 / node-odata Goto Github PK
View Code? Open in Web Editor NEWA library for easily create OData REST API, abide by OData protocol.
Home Page: http://zackyang000.github.io/node-odata/en/
License: MIT License
A library for easily create OData REST API, abide by OData protocol.
Home Page: http://zackyang000.github.io/node-odata/en/
License: MIT License
odata.set('maxTop', 10)
and
odata.register({options: {maxTop: 10}})
Both not work.
odata.resource.register(params)
->
odata.resource(params)
odata.function.register(params)
->
odata.get(params)
odata.put(params)
odata.del(params)
odata.post(params)
see detail.
I have quite a complex model:
server.resource('subscriptionConfigurations', {
user: String,
topics: [{
name : String,
situationDescriptions : [{
criteria : {
stocks : {
enabled : Boolean,
exchange : String,
stockChangeAmount : Number,
stockChangeDirection : String,
stockChangeUnit : String,
symbol : String
},
tweets : {
enabled : Boolean,
hashtags : Array,
keywords : Array,
operator : String,
tweetNumber : Number,
tweetOperator : String,
users : Array
},
periodNumber : Number,
periodUnit : String
}
}]
}]
});
Here, updating a document with PUT fails. The response of the PUT returns exactly what I have put into the request payload, however when I do a get on the document or get all documents, the document that should have been updated is still in the old version.
I only can circumvent this by deleting the document and POSTing it again. Can you please look at it?
put().before(function(entity){
entity.name='test';
})
执行后数据库中的name没有变化
version:0.7.4
Is there a mysql example?
The live demo links http://books.zackyang.com/book
on the README.md are not working. They deliver the following error:
502 Bad Gateway
nginx/1.4.6 (Ubuntu)
Error:
http://localhost:3000/book?$filter=indexOf(title, 'x') gt 0
Success:
http://localhost:3000/book?$filter=indexOf(title,'x') gt 0
在阿里云服务器上安装node-odata模块时,报错
module.js:341
throw err;
^
Error: Cannot find module './Resource'
在这个环境下测试了express,运行没有问题
比如直接 get /books
会得到所有的 books,但是有时候如果 book 太多的话(比如有几万本)一个 json
明显太大了,可以直接通过 $top=10
返回前 10 本书。但是我想不通过这个 top
查询,而是直接类似
这样 http://services.odata.org/V2/Northwind/Northwind.svc/Customers?%24format=JSON 有一个 "__next" 属性,这样就可以得到下面 20 个人的信息了,主要是比较方便前端处理。请问这样的 "__next" 功能如何通过 node-odata 实现呢?
Example:
odata
.all()
.auth(function(){...})
.delete()
.before(function(){...})
.resource
.create()
.url('/book')
.model(model)
.all()
.auth(function(){...})
.get()
.after(function(){...})
.delete()
.before(function(){...})
.post()
.action('50-off')
.handle(function(){...})
.options()
.orderby('date desc')
_id
is a built-in field by MongoDB
, the need to remove its dependence. Change to id looks like more general.
1. 'or' is not work
http://localhost:3000/book?$filter=price gt 30 or price lt 30
is same as
http://localhost:3000/book?$filter=price gt 30 and price lt 30
This is a mistake. It's should return something when use 'or' to query.
2. 'and' is not correct when $filter same field
http://localhost:3000/book?$filter=price eq 44.95 and price eq 36.95
This query will return 2 result both include 44.95 and 36.95.
我要在post方法执行前后记录日志信息,按照api文档中关于before,after的用法,发现before方法没有被执行,请问如何实现。
Eg: .bodyParse, query, methodOverride, CORS.
When I query for objects, the internal ID of the MongoDB document is not returned.
Request: http://localhost:3000/subscriptionConfigurations
Response-Body:
{
"value": [
{
"id": "2016-04-28T13:19:09.907Z",
"text": "foo bar 32"
}
]
}
However: in the DB, the object has the internal id _id : d30b54e9-12a2-49ba-8da0-87b3c1500aab
I can also request it directly:
Request: http://localhost:3000/subscriptionConfigurations(d30b54e9-12a2-49ba-8da0-87b3c1500aab)
Response:
{
"id": "2016-04-28T13:19:09.907Z",
"text": "foo bar 32"
}
In my server code, I use:
server.resource('subscriptionConfigurations', {
_id: String,
id: Date,
text: String
});
Why is _id not returned?
When I try in the server code
server.resource('subscriptionConfigurations', {
_id: require('mongoose').Schema.ObjectId,
id: Date,
text: String
});
... I get this error message:
Cast to ObjectId failed for value "d30b54e9-12a2-49ba-8da0-87b3c1500aab" at path "_id"
I'm using MongoDB version 3.0.11
您好,最近我在使用你的 node-odata 提供 API,ember.js 做前端,碰到了 cros 的问题,
于是我上 SO 提了一个问题:http://stackoverflow.com/questions/30147362/access-control-allow-origin-error-when-using-ember-jswith-ember-cli
回答者说不是 ember 的问题,需要在 服务器端 3000 端口激活 CORS,并给出了链接 http://enable-cors.org/server_expressjs.html
对于 express 我不是很熟,请问在使用 node-odata 的时候如何激活这个 CORS 呢?
非常感谢!
Are you guys still working on this ? What about future updates and some production ready version ?
In this case, the parser believes that I am concatenating another and expression. My model is:
Product
name: String
code: String
category: String
brand: String
The query:
?$filter=name eq '600ml Bottle' and brand eq 'Pepsi'
...results in:
500 - Syntax error at 'br'.
If I rename the property to bran or something, it works.
I would like to query: ?$filter=bran_ eq null
.
This is supported? or is there any way to do the same?
Thanks!
Use
var dataSchema = new Schema({..}, { collection: 'data' })
#27 referred to the problem.
我post的时候按照schema格式 制作body 如下:
{
custom: {
id: "1",
name: "john"
},
orderItems: [{
quantity: 10,
product: {
id: "1",
name: "com",
price: 2.1
}
}]
}
但是返回错误:
SyntaxError: Unexpected token c
at Object.parse (native)
at parse (/home/wxd/node/test-odata/node_modules/body-parser/lib/types/json.js:88:17)
at /home/wxd/node/test-odata/node_modules/body-parser/lib/read.js:108:18
at invokeCallback (/home/wxd/node/test-odata/node_modules/raw-body/index.js:262:16)
at done (/home/wxd/node/test-odata/node_modules/raw-body/index.js:251:7)
at IncomingMessage.onEnd (/home/wxd/node/test-odata/node_modules/raw-body/index.js:308:7)
at emitNone (events.js:67:13)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:913:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
直接配置数据库不可用。
如果不调用set方法,则无法连接db,因为没有调用mongoose.connect(value)
see config.coffee.
作者你好,我用这个API查找对应ID的资源怎么总是返回404呢?我确定数据库里面有对应资源。不同的ID值查询总是返回相同的结果,DELETE以ID值为查询也是404
package.json 里写的是 "node": "0.10.x", "npm": "1.4.x",会不会太老了点?
Hi,
It would be useful to be able set a different mongooseModel when registering a new resource rather than use the url parameter as the name of the mongoDB collection:
server.resources.register({
url: '/libri',
mongooseModel: '/books',
model: {
title: String,
price: Number
}
});
node-odata is currently at an alpha stage, it is stable but not 100% feature complete. node-odata is written by CoffeeScript then compiled to Javascript.
node-odata is written by CoffeeScript then compiled to Javascript.
CoffeeScript
why :(
server.use(bodyParser.json({limit: '100mb'}));
Not working.
When receiving large post request entity.
Consider to use HTTP Header: If-None-Match, If-Unmodified-Since
Should add a way to set authorization for odata-functions.
Remove prefix when request is OData function, because he will confuse the boundaries resource and function.
Hi there,
first: Thank you for this great project. It looks promising.
But why are you using the books/:id
url route instead the defined Odata way books(:id)
? I also don't like this syntax that much, but it is set as the standard and your server should support it. Or what do you think?
greetings
Jan
eg.
books = new Resource({title: String});
books.post.auth = ...;
books.actions['50-off'] = ...;
books.maxTop = ...;
所以我只能用 _year 之类的。那么包括未支持的那些方法名也是函数名,无法在model中使用。
hi
how can I reference the resource to another resource?
(reference document to another)
for example:
server.resource('books', {
title: String,
price: Number
});
server.resource('authors', {
name: String,
books: [ reference to book ]
});
I noticed that the _id is generated by type string and every time I use {type: String, ref: 'books'} the inserted data is {name: "foo", books: ["[object Object]"]}
is there a way to use reference?
thanks
// 配置 POST /resource
.post().before(req)方法会执行2次before方法
The __v is:
The versionKey is a property set on each document when first created by Mongoose. This keys value contains the internal revision of the document. The name of this document property is configurable. The default is __v.
mongoose dependence should be remove.
node-data is a pretty good tool. I was very happy to find it, then I have seen that you don't create standard $metadata.
I need to call the webservice from my OpenUI5 application, so I can't use it. What a pitty!
嗯目前我是直接改 node_modules/node-odata/lib/index.coffee
里的内容的,我把这个文件里面直接加上
cors = require('cors')
// ...此处省略一大段
app.use(cors())
虽然这样就能用了,但是当然我知道直接改这样不太好的。。
我在我的 index.js 尝试这样改:
var cors = require('cors');
var odata = require('node-odata');
var server = odata('mongodb://localhost/odata_ember');
server.resources.register({
url: '/articles',
model: {
title: String,
content: String,
category: String
}
});
server.use(cors());
server.listen(3000);
当然这样是不行的,请问具体改怎样做呢?谢谢!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.