-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.ts
64 lines (57 loc) · 1.43 KB
/
mysql.ts
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
class Mysql {
querry:string ='';
constructor() {}
/**
* select
*/
public select(...columnNames: string[]) :Mysql{
this.querry = 'SELECT';
if(columnNames.length==0 || columnNames.indexOf('*')!=-1){
this.querry += ' *';
}else{
columnNames.forEach(column=>{
this.querry += ` ${column},`;
})
}
return this;
}
/**
* from
*/
public from(tableName:string):Mysql {
if(!tableName){
throw new Error("Plese select table");
}else{
this.querry += `\nFROM ${tableName}`;
}
return this;
}
/**
* where
*/
public where(...properties:any):Mysql {
this.querry += '\nWHERE';
if (!properties.length) {
throw new Error("You Entered where clause without specifying column and value");
}else{
for (const key in properties) {
const element = properties[key];
this.querry += ` ${element}`;
}
}
return this;
}
/**
* execute
*/
public execute():string {
this.querry += ';'
return this.querry;
}
}
// let my = new Mysql().querry;
// my.select().from('Users').where('id=10').querry();
// console.log(my.querry);
let newq = new Mysql();
let que = newq.select().from('Users').where('id==10').execute();
console.log(que);