Service OData v4 requests from a MySQL data store.
The OData V4 MySQL Connector provides functionality to convert the various types of OData segments into SQL query statements, that you can execute over a MySQL database.
- Create high speed, standard compliant data sharing APIs
import { createFilter } from 'odata-v4-mysql'
//example request: GET /api/Users?$filter=Id eq 42
app.get("/api/Users", (req: Request, res: Response) => {
const filter = createFilter(req.query.$filter);
// connection instance from mysql module
connection.query(`SELECT * FROM Users WHERE ${filter.where}`, filter.parameters, function(err, data){
res.json({
'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#Users',
value: data
});
});
});
Advanced TypeScript example available here.
var createFilter = require('odata-v4-mysql').createFilter;
app.get("/api/Users", function(req, res) {
var filter = createFilter(req.query.$filter);
// connection instance from mysql module
connection.query(filter.from("Users"), filter.parameters, function(err, data){
res.json({
'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#Users',
value: data
});
});
})
- $filter
- $select
- $skip
- $top
- $orderby
- $expand