-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexe2.js
More file actions
24 lines (19 loc) · 735 Bytes
/
exe2.js
File metadata and controls
24 lines (19 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let command = "create table author (id number, name string, age number, city string, state string, country string)";
const regExp = /create table ([a-z]+) \((.+)\)/;
const regExpResult = regExp.exec(command);
// console.log(regExpResult);
const tableName = regExpResult[1];
let commandColumns = regExpResult[2];
// console.log(tableName);
// console.log(commandColumns);
let columns = commandColumns.split(', ');
// console.log(columns);
let tables = {};
tables[tableName] = {"columns": {}};
for (const column of columns) {
let item = column.split(" ");
tables[tableName]["columns"][item[0]] = item[1];
}
tables[tableName]["data"] = [];
let database = {"tables": tables};
console.log(JSON.stringify(database, null, " "));