-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Query for null #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
as a temporary solution until this feature merged, you could use server.jsconst jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();
router.render = (req, res) => {
let data = res.locals.data;
// a very dirty way to check if there is a filter by date and the response is an array
if(req.query.date_is_null && typeof data !== 'function' && data.length ) {
res.send(data.filter(d => !d.date))
}
}
//default json-server middlewares
server.use(middlewares);
// json-server's magic
server.use(router);
server.listen(3000, () => {
console.log('http://localhost:3000');
}); run it: node server.js Please test the code as I wrote it without running it, so it could have some syntax errors |
thanks will do that |
could you please elaborate more? So I tried creating a new file called server.js in the same directory where the db is located and copied the above code and ran the cammand node server.js in the same dir internal/modules/cjs/loader.js:638 Error: Cannot find module 'json-server' |
Uh oh!
There was an error while loading. Please reload this page.
This is a question, something that i didn't manage to find in documentation.
However it seems like a basic functionality and I'm sure that there must be a simple solution/workaround.
I've got a requirement to get all records where date is null, tried
http://localhost:3000/entity_name?date=null
with no luck as it does not return any records.
Had a look at the following issue and i can see that author suggested adding new _is_null operator.
#510
However not sure if this was added.
Any help would be appreciated.
MK
The text was updated successfully, but these errors were encountered: