-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.js
41 lines (34 loc) · 1.06 KB
/
node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Sqomplexity } from 'sqomplexity';
import defaultWeights from 'sqomplexity/src/weights.js';
(async() => {
const queries = [
'SELECT id FROM users WHERE role = "admin"',
'SELECT COUNT(*) FROM users WHERE creation_date > "2023-01-01 00:00:00" GROUP BY id'
];
// Optional: assign your own weight scores:
const weights = defaultWeights;
// Create a new instance with the given queries:
const sqomplexity = new Sqomplexity(queries, weights);
// Calculate just the complexity score for each query:
console.log(
await sqomplexity.score()
);
// Result: [ 7.876953, 10.001953 ]
// Calculate the complexity score and extra metadata:
console.log(
await sqomplexity.analyze()
);
// Result: [{
// complexity: 7.876953,
// dialect: string,
// query: string,
// stats: object,
// ast: object
// }, {
// complexity: 10.001953,
// dialect: string,
// query: string,
// stats: object,
// ast: object
// }]
})();