-
Notifications
You must be signed in to change notification settings - Fork 34
/
stupid.mjs
executable file
·35 lines (32 loc) · 960 Bytes
/
stupid.mjs
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
#!/usr/bin/env node
import * as fs from 'fs';
import { SplitQueries } from './parser/SplitQueries.mjs';
import {
select, from, outerJoin, innerJoin, orderBy, groupBy, insert, deleteFrom, deleteId,
updateFrom, updateId, count, database
} from './lib/fake-sql.mjs';
import { users } from './lib/users-database.mjs';
import { heroes } from './lib/heroes-database.mjs';
database['users'] = users
database['heroes'] = heroes
const readScriptFromFile = (file) => {
return new Promise((resolve, reject) => {
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
reject(err)
} else {
resolve(data)
}
})
})
}
const parseScriptWithSplitQueries = (script) => {
return SplitQueries(script)
}
const script = await readScriptFromFile('test.sql');
const parsed = parseScriptWithSplitQueries(script);
parsed.forEach(query => {
console.log(`running: ${query}`);
const result = eval(query);
console.table(result);
})