-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.js
More file actions
71 lines (71 loc) · 1.85 KB
/
mysql.js
File metadata and controls
71 lines (71 loc) · 1.85 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var Mysql = /** @class */ (function () {
function Mysql() {
this.querry = '';
}
/**
* select
*/
Mysql.prototype.select = function () {
var _this = this;
var columnNames = [];
for (var _i = 0; _i < arguments.length; _i++) {
columnNames[_i] = arguments[_i];
}
this.querry = 'SELECT';
if (columnNames.length == 0 || columnNames.indexOf('*') != -1) {
this.querry += ' *';
}
else {
columnNames.forEach(function (column) {
_this.querry += " " + column + ",";
});
}
return this;
};
/**
* from
*/
Mysql.prototype.from = function (tableName) {
if (!tableName) {
throw new Error("Plese select table");
}
else {
this.querry += "\nFROM " + tableName;
}
return this;
};
/**
* where
*/
Mysql.prototype.where = function () {
var properties = [];
for (var _i = 0; _i < arguments.length; _i++) {
properties[_i] = arguments[_i];
}
this.querry += '\nWHERE';
if (!properties.length) {
throw new Error("You Entered where clause without specifying column and value");
}
else {
for (var key in properties) {
var element = properties[key];
this.querry += " " + element;
}
}
return this;
};
/**
* execute
*/
Mysql.prototype.execute = function () {
this.querry += ';';
return this.querry;
};
return Mysql;
}());
// let my = new Mysql().querry;
// my.select().from('Users').where('id=10').querry();
// console.log(my.querry);
var newq = new Mysql();
var que = newq.select().from('Users').where('id==10').execute();
console.log(que);