@steedos/odata-v4-typeorm 1.20.0 → 2.2.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +125 -125
- package/config/default.json +6 -6
- package/{build/lib → lib}/createFilter.d.ts +13 -13
- package/{build/lib → lib}/createFilter.js +17 -15
- package/lib/createFilter.js.map +1 -0
- package/{build/lib → lib}/createQuery.d.ts +13 -13
- package/{build/lib → lib}/createQuery.js +14 -12
- package/lib/createQuery.js.map +1 -0
- package/{build/lib → lib}/executeQuery.d.ts +5 -5
- package/{build/lib → lib}/executeQuery.js +277 -268
- package/lib/executeQuery.js.map +1 -0
- package/{build/lib → lib}/index.d.ts +6 -6
- package/lib/index.js +14 -0
- package/lib/index.js.map +1 -0
- package/{build/lib → lib}/odataQueryMiddleware.d.ts +3 -3
- package/{build/lib → lib}/odataQueryMiddleware.js +29 -26
- package/lib/odataQueryMiddleware.js.map +1 -0
- package/{build/lib → lib}/sqlOptions.d.ts +7 -7
- package/lib/sqlOptions.js +3 -0
- package/{build/lib → lib}/sqlOptions.js.map +1 -1
- package/{build/lib → lib}/visitor.d.ts +20 -20
- package/{build/lib → lib}/visitor.js +308 -302
- package/lib/visitor.js.map +1 -0
- package/package.json +40 -52
- package/src/{lib/createFilter.ts → createFilter.ts} +26 -26
- package/src/{lib/createQuery.ts → createQuery.ts} +22 -22
- package/src/{lib/executeQuery.ts → executeQuery.ts} +291 -282
- package/src/{lib/index.ts → index.ts} +6 -6
- package/src/{lib/odataQueryMiddleware.ts → odataQueryMiddleware.ts} +17 -17
- package/src/{lib/sqlOptions.ts → sqlOptions.ts} +7 -7
- package/src/{lib/visitor.ts → visitor.ts} +301 -298
- package/tsconfig.json +11 -10
- package/build/example/sql.d.ts +0 -0
- package/build/example/sql.js +0 -131
- package/build/example/sql.js.map +0 -1
- package/build/lib/createFilter.js.map +0 -1
- package/build/lib/createQuery.js.map +0 -1
- package/build/lib/executeQuery.js.map +0 -1
- package/build/lib/index.js +0 -12
- package/build/lib/index.js.map +0 -1
- package/build/lib/odataQueryMiddleware.js.map +0 -1
- package/build/lib/sqlOptions.js +0 -2
- package/build/lib/visitor.js.map +0 -1
- package/src/example/sql.ts +0 -82
- package/src/example/world.sql +0 -5388
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Andriy
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Andriy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
# OData V4 Service modules - TYPEORM Connector
|
|
2
|
-
|
|
3
|
-
Service OData v4 requests from a TYPEORM.
|
|
4
|
-
|
|
5
|
-
## Synopsis
|
|
6
|
-
The OData V4 TYPEORM Connector provides functionality to convert the various types of OData segments
|
|
7
|
-
into SQL query statements, that you can execute over a TYPEORM.
|
|
8
|
-
|
|
9
|
-
## Potential usage scenarios
|
|
10
|
-
|
|
11
|
-
- Create high speed, standard compliant data sharing APIs
|
|
12
|
-
|
|
13
|
-
## Usage as server - TypeScript
|
|
14
|
-
//example request: GET /api/users?$filter=id eq 42&$select=id,name
|
|
15
|
-
### odataQuery
|
|
16
|
-
```typescript
|
|
17
|
-
import express from 'express';
|
|
18
|
-
import { odataQuery } from 'odata-v4-typeorm';
|
|
19
|
-
import { getRepository } from 'typeorm';
|
|
20
|
-
import { User } from '../entities/user';
|
|
21
|
-
|
|
22
|
-
const app = express();
|
|
23
|
-
const usersRepository = getRepository(User);
|
|
24
|
-
|
|
25
|
-
app.get('/api/users', odataQuery(usersRepository));
|
|
26
|
-
|
|
27
|
-
const port = 3001;
|
|
28
|
-
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### executeQuery by repository
|
|
32
|
-
```typescript
|
|
33
|
-
import express from 'express';
|
|
34
|
-
import { executeQuery } from 'odata-v4-typeorm';
|
|
35
|
-
import { getRepository } from 'typeorm';
|
|
36
|
-
import { User } from '../entities/user';
|
|
37
|
-
|
|
38
|
-
const app = express();
|
|
39
|
-
|
|
40
|
-
app.get('/api/users', async (req, res) => {
|
|
41
|
-
try {
|
|
42
|
-
const usersRepository = getRepository(User);
|
|
43
|
-
const data = await executeQuery(usersRepository, req.query);
|
|
44
|
-
return res.status(200).json(data);
|
|
45
|
-
} catch (e) {
|
|
46
|
-
return res.status(500).json({message: 'Internal server error.'});
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const port = 3001;
|
|
51
|
-
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### executeQuery by queryBuilder
|
|
55
|
-
```typescript
|
|
56
|
-
import express from 'express';
|
|
57
|
-
import { executeQuery } from 'odata-v4-typeorm';
|
|
58
|
-
import { getRepository } from 'typeorm';
|
|
59
|
-
import { User } from '../entities/user';
|
|
60
|
-
|
|
61
|
-
const app = express();
|
|
62
|
-
|
|
63
|
-
app.get('/api/users', async (req, res) => {
|
|
64
|
-
try {
|
|
65
|
-
const queryBuilder = getRepository(User)
|
|
66
|
-
.createQueryBuilder("user")
|
|
67
|
-
.where("user.roleName = :roleName", { roleName: 'admin' });
|
|
68
|
-
const data = await executeQuery(queryBuilder, req.query);
|
|
69
|
-
return res.status(200).json(data);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
return res.status(500).json({message: 'Internal server error.'});
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const port = 3001;
|
|
76
|
-
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### createFilter
|
|
80
|
-
```javascript
|
|
81
|
-
import { createFilter } from 'odata-v4-typeorm'
|
|
82
|
-
|
|
83
|
-
//example request: GET /api/Users?$filter=Id eq 42
|
|
84
|
-
app.get("/api/Users", (req: Request, res: Response) => {
|
|
85
|
-
const filter = createFilter(req.query.$filter);
|
|
86
|
-
// connection instance from pg module
|
|
87
|
-
connection.query(`SELECT * FROM Users WHERE ${filter.where}`, filter.parameters, function(err, result){
|
|
88
|
-
res.json({
|
|
89
|
-
'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#Users',
|
|
90
|
-
value: result.rows
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Advanced TypeScript example available [here](https://raw.githubusercontent.com/jaystack/odata-v4-mysql/master/src/example/sql.ts).
|
|
97
|
-
|
|
98
|
-
## Usage ES5
|
|
99
|
-
```javascript
|
|
100
|
-
var createFilter = require('odata-v4-typeorm').createFilter;
|
|
101
|
-
|
|
102
|
-
app.get("/api/Users", function(req, res) {
|
|
103
|
-
var filter = createFilter(req.query.$filter);
|
|
104
|
-
// connection instance from pg module
|
|
105
|
-
connection.query(filter.from("Users"), filter.parameters, function(err, result){
|
|
106
|
-
res.json({
|
|
107
|
-
'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#Users',
|
|
108
|
-
value: result.rows
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
})
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
## Supported OData segments
|
|
115
|
-
|
|
116
|
-
* $filter
|
|
117
|
-
* $select
|
|
118
|
-
* $skip
|
|
119
|
-
* $top
|
|
120
|
-
* $orderby
|
|
121
|
-
* $expand
|
|
122
|
-
* $count
|
|
123
|
-
|
|
124
|
-
If you have any questions, please don’t hesitate to contact me.
|
|
125
|
-
* skype: andryuha49.
|
|
1
|
+
# OData V4 Service modules - TYPEORM Connector
|
|
2
|
+
|
|
3
|
+
Service OData v4 requests from a TYPEORM.
|
|
4
|
+
|
|
5
|
+
## Synopsis
|
|
6
|
+
The OData V4 TYPEORM Connector provides functionality to convert the various types of OData segments
|
|
7
|
+
into SQL query statements, that you can execute over a TYPEORM.
|
|
8
|
+
|
|
9
|
+
## Potential usage scenarios
|
|
10
|
+
|
|
11
|
+
- Create high speed, standard compliant data sharing APIs
|
|
12
|
+
|
|
13
|
+
## Usage as server - TypeScript
|
|
14
|
+
//example request: GET /api/users?$filter=id eq 42&$select=id,name
|
|
15
|
+
### odataQuery
|
|
16
|
+
```typescript
|
|
17
|
+
import express from 'express';
|
|
18
|
+
import { odataQuery } from 'odata-v4-typeorm';
|
|
19
|
+
import { getRepository } from 'typeorm';
|
|
20
|
+
import { User } from '../entities/user';
|
|
21
|
+
|
|
22
|
+
const app = express();
|
|
23
|
+
const usersRepository = getRepository(User);
|
|
24
|
+
|
|
25
|
+
app.get('/api/users', odataQuery(usersRepository));
|
|
26
|
+
|
|
27
|
+
const port = 3001;
|
|
28
|
+
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### executeQuery by repository
|
|
32
|
+
```typescript
|
|
33
|
+
import express from 'express';
|
|
34
|
+
import { executeQuery } from 'odata-v4-typeorm';
|
|
35
|
+
import { getRepository } from 'typeorm';
|
|
36
|
+
import { User } from '../entities/user';
|
|
37
|
+
|
|
38
|
+
const app = express();
|
|
39
|
+
|
|
40
|
+
app.get('/api/users', async (req, res) => {
|
|
41
|
+
try {
|
|
42
|
+
const usersRepository = getRepository(User);
|
|
43
|
+
const data = await executeQuery(usersRepository, req.query);
|
|
44
|
+
return res.status(200).json(data);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return res.status(500).json({message: 'Internal server error.'});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const port = 3001;
|
|
51
|
+
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### executeQuery by queryBuilder
|
|
55
|
+
```typescript
|
|
56
|
+
import express from 'express';
|
|
57
|
+
import { executeQuery } from 'odata-v4-typeorm';
|
|
58
|
+
import { getRepository } from 'typeorm';
|
|
59
|
+
import { User } from '../entities/user';
|
|
60
|
+
|
|
61
|
+
const app = express();
|
|
62
|
+
|
|
63
|
+
app.get('/api/users', async (req, res) => {
|
|
64
|
+
try {
|
|
65
|
+
const queryBuilder = getRepository(User)
|
|
66
|
+
.createQueryBuilder("user")
|
|
67
|
+
.where("user.roleName = :roleName", { roleName: 'admin' });
|
|
68
|
+
const data = await executeQuery(queryBuilder, req.query);
|
|
69
|
+
return res.status(200).json(data);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
return res.status(500).json({message: 'Internal server error.'});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const port = 3001;
|
|
76
|
+
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### createFilter
|
|
80
|
+
```javascript
|
|
81
|
+
import { createFilter } from 'odata-v4-typeorm'
|
|
82
|
+
|
|
83
|
+
//example request: GET /api/Users?$filter=Id eq 42
|
|
84
|
+
app.get("/api/Users", (req: Request, res: Response) => {
|
|
85
|
+
const filter = createFilter(req.query.$filter);
|
|
86
|
+
// connection instance from pg module
|
|
87
|
+
connection.query(`SELECT * FROM Users WHERE ${filter.where}`, filter.parameters, function(err, result){
|
|
88
|
+
res.json({
|
|
89
|
+
'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#Users',
|
|
90
|
+
value: result.rows
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Advanced TypeScript example available [here](https://raw.githubusercontent.com/jaystack/odata-v4-mysql/master/src/example/sql.ts).
|
|
97
|
+
|
|
98
|
+
## Usage ES5
|
|
99
|
+
```javascript
|
|
100
|
+
var createFilter = require('odata-v4-typeorm').createFilter;
|
|
101
|
+
|
|
102
|
+
app.get("/api/Users", function(req, res) {
|
|
103
|
+
var filter = createFilter(req.query.$filter);
|
|
104
|
+
// connection instance from pg module
|
|
105
|
+
connection.query(filter.from("Users"), filter.parameters, function(err, result){
|
|
106
|
+
res.json({
|
|
107
|
+
'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#Users',
|
|
108
|
+
value: result.rows
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Supported OData segments
|
|
115
|
+
|
|
116
|
+
* $filter
|
|
117
|
+
* $select
|
|
118
|
+
* $skip
|
|
119
|
+
* $top
|
|
120
|
+
* $orderby
|
|
121
|
+
* $expand
|
|
122
|
+
* $count
|
|
123
|
+
|
|
124
|
+
If you have any questions, please don’t hesitate to contact me.
|
|
125
|
+
* skype: andryuha49.
|
|
126
126
|
* https://www.linkedin.com/in/andriy-zherdiy/
|
package/config/default.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"sqlConfig": {
|
|
3
|
-
"user": "db",
|
|
4
|
-
"password": "***",
|
|
5
|
-
"database": "world"
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"sqlConfig": {
|
|
3
|
+
"user": "db",
|
|
4
|
+
"password": "***",
|
|
5
|
+
"database": "world"
|
|
6
|
+
}
|
|
7
7
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { TypeOrmVisitor as Visitor } from './visitor';
|
|
2
|
-
import { Token } from 'odata-v4-parser/lib/lexer';
|
|
3
|
-
import { SqlOptions } from './sqlOptions';
|
|
4
|
-
/**
|
|
5
|
-
* Creates an SQL WHERE clause from an OData filter expression string
|
|
6
|
-
* @param {string} odataFilter - A filter expression in OData $filter format
|
|
7
|
-
* @return {string} SQL WHERE clause
|
|
8
|
-
* @example
|
|
9
|
-
* const filter = createFilter("Size eq 4 and Age gt 18");
|
|
10
|
-
* let sqlQuery = `SELECT * FROM table WHERE ${filter}`;
|
|
11
|
-
*/
|
|
12
|
-
export declare function createFilter(odataFilter: string, options?: SqlOptions): Visitor;
|
|
13
|
-
export declare function createFilter(odataFilter: Token, options?: SqlOptions): Visitor;
|
|
1
|
+
import { TypeOrmVisitor as Visitor } from './visitor';
|
|
2
|
+
import { Token } from 'odata-v4-parser/lib/lexer';
|
|
3
|
+
import { SqlOptions } from './sqlOptions';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an SQL WHERE clause from an OData filter expression string
|
|
6
|
+
* @param {string} odataFilter - A filter expression in OData $filter format
|
|
7
|
+
* @return {string} SQL WHERE clause
|
|
8
|
+
* @example
|
|
9
|
+
* const filter = createFilter("Size eq 4 and Age gt 18");
|
|
10
|
+
* let sqlQuery = `SELECT * FROM table WHERE ${filter}`;
|
|
11
|
+
*/
|
|
12
|
+
export declare function createFilter(odataFilter: string, options?: SqlOptions): Visitor;
|
|
13
|
+
export declare function createFilter(odataFilter: Token, options?: SqlOptions): Visitor;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFilter = void 0;
|
|
4
|
+
const visitor_1 = require("./visitor");
|
|
5
|
+
const odata_v4_parser_1 = require("odata-v4-parser");
|
|
6
|
+
const odata_v4_sql_1 = require("odata-v4-sql");
|
|
7
|
+
function createFilter(odataFilter, options = {}) {
|
|
8
|
+
if (!options.type) {
|
|
9
|
+
options.type = odata_v4_sql_1.SQLLang.Oracle;
|
|
10
|
+
}
|
|
11
|
+
let ast = (typeof odataFilter == 'string' ? (0, odata_v4_parser_1.filter)(odataFilter) : odataFilter);
|
|
12
|
+
const visitor = new visitor_1.TypeOrmVisitor(options);
|
|
13
|
+
const visit = visitor.Visit(ast);
|
|
14
|
+
const type = visit.asType();
|
|
15
|
+
return type;
|
|
16
|
+
}
|
|
17
|
+
exports.createFilter = createFilter;
|
|
16
18
|
//# sourceMappingURL=createFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFilter.js","sourceRoot":"","sources":["../src/createFilter.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AAGpD,qDAAuC;AACvC,+CAAqC;AAYrC,SAAgB,YAAY,CAAC,WAA2B,EAAE,UAAsB,EAAE;IAChF,IAAI,CAAC,OAAO,CAAC,IAAI,EAAC;QAChB,OAAO,CAAC,IAAI,GAAG,sBAAO,CAAC,MAAM,CAAC;KAC/B;IACD,IAAI,GAAG,GAAiB,CAAC,OAAO,WAAW,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAA,wBAAM,EAAS,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACrG,MAAM,OAAO,GAAG,IAAI,wBAAO,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;IAC5B,OAAO,IAAI,CAAC;AAEd,CAAC;AAVD,oCAUC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { TypeOrmVisitor as Visitor } from './visitor';
|
|
2
|
-
import { Token } from 'odata-v4-parser/lib/lexer';
|
|
3
|
-
import { SqlOptions } from './sqlOptions';
|
|
4
|
-
/**
|
|
5
|
-
* Creates an SQL query descriptor from an OData query string
|
|
6
|
-
* @param {string} odataQuery - An OData query string
|
|
7
|
-
* @return {string} SQL query descriptor
|
|
8
|
-
* @example
|
|
9
|
-
* const filter = createQuery("$filter=Size eq 4 and Age gt 18");
|
|
10
|
-
* let sqlQuery = `SELECT * FROM table WHERE ${filter.where}`;
|
|
11
|
-
*/
|
|
12
|
-
export declare function createQuery(odataQuery: string, options?: SqlOptions): Visitor;
|
|
13
|
-
export declare function createQuery(odataQuery: Token, options?: SqlOptions): Visitor;
|
|
1
|
+
import { TypeOrmVisitor as Visitor } from './visitor';
|
|
2
|
+
import { Token } from 'odata-v4-parser/lib/lexer';
|
|
3
|
+
import { SqlOptions } from './sqlOptions';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an SQL query descriptor from an OData query string
|
|
6
|
+
* @param {string} odataQuery - An OData query string
|
|
7
|
+
* @return {string} SQL query descriptor
|
|
8
|
+
* @example
|
|
9
|
+
* const filter = createQuery("$filter=Size eq 4 and Age gt 18");
|
|
10
|
+
* let sqlQuery = `SELECT * FROM table WHERE ${filter.where}`;
|
|
11
|
+
*/
|
|
12
|
+
export declare function createQuery(odataQuery: string, options?: SqlOptions): Visitor;
|
|
13
|
+
export declare function createQuery(odataQuery: Token, options?: SqlOptions): Visitor;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createQuery = void 0;
|
|
4
|
+
const visitor_1 = require("./visitor");
|
|
5
|
+
const odata_v4_parser_1 = require("odata-v4-parser");
|
|
6
|
+
const odata_v4_sql_1 = require("odata-v4-sql");
|
|
7
|
+
function createQuery(odataQuery, options = {}) {
|
|
8
|
+
if (!options.type) {
|
|
9
|
+
options.type = odata_v4_sql_1.SQLLang.Oracle;
|
|
10
|
+
}
|
|
11
|
+
let ast = (typeof odataQuery == 'string' ? (0, odata_v4_parser_1.query)(odataQuery) : odataQuery);
|
|
12
|
+
return new visitor_1.TypeOrmVisitor(options).Visit(ast).asType();
|
|
13
|
+
}
|
|
14
|
+
exports.createQuery = createQuery;
|
|
13
15
|
//# sourceMappingURL=createQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQuery.js","sourceRoot":"","sources":["../src/createQuery.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AAEpD,qDAAsC;AACtC,+CAAqC;AAarC,SAAgB,WAAW,CAAC,UAA0B,EAAE,UAAsB,EAAE;IAC9E,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACjB,OAAO,CAAC,IAAI,GAAG,sBAAO,CAAC,MAAM,CAAC;KAC/B;IACD,IAAI,GAAG,GAAiB,CAAC,OAAO,UAAU,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAA,uBAAK,EAAS,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACjG,OAAO,IAAI,wBAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;AAClD,CAAC;AAND,kCAMC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SqlOptions } from './sqlOptions';
|
|
2
|
-
declare const executeQuery: (repositoryOrQueryBuilder: any, query: any, options: SqlOptions) => Promise<any>;
|
|
3
|
-
declare const executeCountQuery: (repositoryOrQueryBuilder: any, query: any, options: SqlOptions) => Promise<any>;
|
|
4
|
-
declare const getExecuteQuerySQL: (repositoryOrQueryBuilder: any, query: any, options: SqlOptions) => Promise<any>;
|
|
5
|
-
export { executeQuery, executeCountQuery, getExecuteQuerySQL };
|
|
1
|
+
import { SqlOptions } from './sqlOptions';
|
|
2
|
+
declare const executeQuery: (repositoryOrQueryBuilder: any, query: any, options: SqlOptions) => Promise<any>;
|
|
3
|
+
declare const executeCountQuery: (repositoryOrQueryBuilder: any, query: any, options: SqlOptions) => Promise<any>;
|
|
4
|
+
declare const getExecuteQuerySQL: (repositoryOrQueryBuilder: any, query: any, options: SqlOptions) => Promise<any>;
|
|
5
|
+
export { executeQuery, executeCountQuery, getExecuteQuerySQL };
|