-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexe3.js
More file actions
30 lines (29 loc) · 993 Bytes
/
exe3.js
File metadata and controls
30 lines (29 loc) · 993 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
25
26
27
28
29
30
const database = {
tables: {},
createTable: function (command) {
const regExp = /create table ([a-z]+) \((.+)\)/;
const regExpResult = regExp.exec(command);
const tableName = regExpResult[1];
const commandColumns = regExpResult[2];
const columns = commandColumns.split(', ');
this.tables = {
[tableName]: {
columns: {}
},
data: []
};
for (const column of columns) {
const item = column.split(" ");
const col = item[0];
const tipo = item[1];
this.tables[tableName].columns[col] = tipo;
}
return this;
},
execute: function (command) {
if (command.startsWith('create table')) {
return this.createTable(command);
}
}
}
console.log(JSON.stringify(database.execute("create table author (id number, name string, age number, city string, state string, country string)")));