* Convert SELECT to SQL string representation
()
| 30 | * Convert SELECT to SQL string representation |
| 31 | */ |
| 32 | toString() { |
| 33 | let s = 'SELECT '; |
| 34 | if (this.distinct) { |
| 35 | s += 'DISTINCT '; |
| 36 | } |
| 37 | if (this.columns && this.columns.length > 0) { |
| 38 | s += this.columns |
| 39 | .map(col => { |
| 40 | let cs = col.toString ? col.toString() : String(col); |
| 41 | if (col.as) { |
| 42 | cs += ' AS ' + col.as; |
| 43 | } |
| 44 | return cs; |
| 45 | }) |
| 46 | .join(', '); |
| 47 | } else { |
| 48 | s += '*'; |
| 49 | } |
| 50 | if (this.from) { |
| 51 | s += |
| 52 | ' FROM ' + |
| 53 | this.from |
| 54 | .map(f => { |
| 55 | let fs = f.toString ? f.toString() : String(f); |
| 56 | if (f.as) { |
| 57 | fs += ' AS ' + f.as; |
| 58 | } |
| 59 | return fs; |
| 60 | }) |
| 61 | .join(', '); |
| 62 | } |
| 63 | if (this.where) { |
| 64 | s += ' WHERE ' + (this.where.toString ? this.where.toString() : String(this.where)); |
| 65 | } |
| 66 | if (this.group) { |
| 67 | s += ' GROUP BY ' + this.group.map(g => g.toString()).join(', '); |
| 68 | } |
| 69 | if (this.having) { |
| 70 | s += ' HAVING ' + this.having.toString(); |
| 71 | } |
| 72 | if (this.order) { |
| 73 | s += ' ORDER BY ' + this.order.map(o => o.toString()).join(', '); |
| 74 | } |
| 75 | if (this.limit !== null) { |
| 76 | s += ' LIMIT ' + this.limit; |
| 77 | } |
| 78 | if (this.offset !== null) { |
| 79 | s += ' OFFSET ' + this.offset; |
| 80 | } |
| 81 | return s; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
no outgoing calls
no test coverage detected