Skip to content

Commit 372ce91

Browse files
committed
(#3) Added TRUNCATE RTINDEX
1 parent a8a258a commit 372ce91

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/QueryBuilder.ts

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import TransactionStatement from './Statements/TransactionStatement';
55
import UpdateStatement from './Statements/UpdateStatement';
66
import DeleteStatement from './Statements/DeleteStatement';
77
import AttachIndexStatement from './Statements/AttachIndexStatement';
8+
import TruncateStatement from './Statements/TruncateStatement';
89

910
export default class QueryBuilder {
1011
// protected type: QueryType;
@@ -55,6 +56,10 @@ export default class QueryBuilder {
5556
return new AttachIndexStatement(this.connection, diskIndex);
5657
}
5758

59+
public truncate(rtIndex: string): TruncateStatement {
60+
return new TruncateStatement(this.connection, rtIndex);
61+
}
62+
5863
get transaction(): TransactionStatement {
5964
return new TransactionStatement(this.connection);
6065
}

src/Statements/AttachIndexStatement.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ export default class AttachIndexStatement {
4646
execute(): Promise<any> {
4747
return this.connection.execute(this.generate(), []);
4848
}
49-
}
49+
}

src/Statements/TruncateStatement.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import ClientInterface from '../ClientInterface';
2+
3+
/**
4+
* TRUNCATE RTINDEX rtindex [WITH RECONFIGURE]
5+
*/
6+
export default class TruncateStatement {
7+
protected reconfigure: boolean = false;
8+
9+
public constructor(protected connection: ClientInterface, protected rtIndex: string) {}
10+
11+
/**
12+
* When RECONFIGURE option is used new tokenization, morphology,
13+
* and other text processing settings from config take effect
14+
* right after index got cleared. This allows to make operations atomic.
15+
*/
16+
public withReconfigure(): TruncateStatement {
17+
this.reconfigure = true;
18+
return this;
19+
}
20+
21+
/**
22+
* Generates the string statement.
23+
*/
24+
generate(): string {
25+
let expression: string = `TRUNCATE RTINDEX ${this.rtIndex}`;
26+
if (this.reconfigure) {
27+
expression += ` WITH RECONFIGURE`;
28+
}
29+
30+
return expression;
31+
}
32+
33+
/**
34+
* Run the query and returns a promise that can be accepted or rejected.
35+
*/
36+
execute(): Promise<any> {
37+
return this.connection.execute(this.generate(), []);
38+
}
39+
}

0 commit comments

Comments
 (0)