https://github.com/dresende/node-sqlaudit
NodeJS SQL Audit language
https://github.com/dresende/node-sqlaudit
audit nodejs sql
Last synced: 9 months ago
JSON representation
NodeJS SQL Audit language
- Host: GitHub
- URL: https://github.com/dresende/node-sqlaudit
- Owner: dresende
- Created: 2019-01-28T11:08:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-12-07T15:12:00.000Z (about 1 year ago)
- Last Synced: 2025-01-02T02:44:36.256Z (about 1 year ago)
- Topics: audit, nodejs, sql
- Language: JavaScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## NodeJS SQL Audit
This is a module that accepts a specific language that you can use to simplify
auditing of SQL data.
## Example
```js
const sqlaudit = require("sqlaudit");
const audit = new sqlaudit({
db : "mysql://user:password@host/database",
});
// there's also an audit.runFile(filename, next)
audit.runCode(`
for users[age < 18] {
// users under age must have no logins
total_logins = 0
total_logins = user_logins[user_id = id].count()
}
`, (err, result) => {
if (err) throw err;
console.log(result);
});
```
## Language
### Query
A query is the most important component of the language. It is strongly based on CSS
query syntax.
```js
table[prop1 > value1, prop2 != value2].sum(value3)
```
This basically selects from table `table` based on those 2 conditions (`prop1` and
`prop2`) and agregates using `SUM()` based on `value3`.
In this specific case, we're selecting a single value. You can also select a row.
```js
table[prop1 = value]:order(-prop2):first()
```
This selects from table `table` order descending (that's what the minus sign is for)
by `prop2` and returns the first row (this is the same as `:limit(1)`).
You can also use this query and then select a specific property:
```js
table[prop1 = value]:order(-prop2):first().prop2
```
### COMMENT
```js
// comment
```
### FOR (loop)
```js
for {
...
}
```
### IF (condition)
```js
if {
...
}
```