1 | const Raw = require('./raw');
|
2 |
|
3 | class Ref extends Raw {
|
4 | constructor(client, ref) {
|
5 | super(client);
|
6 |
|
7 | this.ref = ref;
|
8 | this._schema = null;
|
9 | this._alias = null;
|
10 | }
|
11 |
|
12 | withSchema(schema) {
|
13 | this._schema = schema;
|
14 |
|
15 | return this;
|
16 | }
|
17 |
|
18 | as(alias) {
|
19 | this._alias = alias;
|
20 |
|
21 | return this;
|
22 | }
|
23 |
|
24 | toSQL() {
|
25 | const string = this._schema ? `${this._schema}.${this.ref}` : this.ref;
|
26 |
|
27 | const formatter = this.client.formatter(this);
|
28 |
|
29 | const ref = formatter.columnize(string);
|
30 |
|
31 | const sql = this._alias ? `${ref} as ${formatter.wrap(this._alias)}` : ref;
|
32 |
|
33 | this.set(sql, []);
|
34 |
|
35 | return super.toSQL(...arguments);
|
36 | }
|
37 | }
|
38 |
|
39 | module.exports = Ref;
|