@steedos/odata-v4-sql
TypeScript icon, indicating that this package has built-in type declarations

2.7.10 • Public • Published

OData V4 Service modules - SQL Connector

Service OData v4 requests from an SQL data store.

Synopsis

The OData V4 SQL Connector provides functionality to convert the various types of OData segments into SQL query statements, that you can execute over an SQL database.

Potential usage scenarios

  • Create high speed, standard compliant data sharing APIs

Usage as server - TypeScript

import { createFilter } from '@steedos/odata-v4-sql'

//example request:  GET /api/Users?$filter=Id eq 42
app.get("/api/Users", (req: Request, res: Response) => {
    const filter = createFilter(req.query.$filter);
    // request instance from mssql module
    request.query(`SELECT * FROM Users WHERE ${filter.where}`, function(err, data){
        res.json({
        	'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#Users',
        	value: data
        });
    });
});

Advanced TypeScript example available here.

Usage ES5

var createFilter = require('@steedos/odata-v4-sql').createFilter;

app.get("/api/Users", function(req, res) {
    var filter = createFilter(req.query.$filter);
    // request instance from mssql module
    request.query(filter.from("Users"), function(err, data){
        res.json({
        	'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#Users',
        	value: data
        });
    });
})

Supported OData segments

  • $filter
  • $select
  • $skip
  • $top
  • $orderby
  • $expand

Dependents (2)

Package Sidebar

Install

npm i @steedos/odata-v4-sql

Weekly Downloads

19,311

Version

2.7.10

License

MIT

Unpacked Size

109 kB

Total Files

17

Last publish

Collaborators

  • steedos-zhuangjianguo
  • steedos-baozhoutao
  • chenzhipei
  • yinlianghui
  • steedos-sunhaolin