@ultipa-graph/ultipa-driver
Version:
NodeJS SDK for ultipa-server 5.2
210 lines • 8.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IndexExtra = void 0;
const connection_base_1 = require("./connection.base");
const utils_1 = require("../../utils");
const types_1 = require("../../types/types");
const types_extra_1 = require("../../types/types.extra");
const { CommandList, SchemaStringWithDefault } = utils_1.UQLMAKER;
class IndexExtra extends connection_base_1.ConnectionBase {
/**
* Retrieves all indexes from the current graphset.
*/
async showIndex(config) {
let command = CommandList.showIndex;
let uqlMaker = new utils_1.UQLMAKER(command, config);
let res = await this.uql(uqlMaker.toString(), config);
let node_index = res.items[types_extra_1.ResponseTableName.NODE_INDEX].asIndexes();
let edge_index = res.items[types_extra_1.ResponseTableName.EDGE_INDEX].asIndexes();
return [...node_index, ...edge_index];
}
/**
* Show node or edge index
*/
async showNodeOrEdgeIndex(dbType, config) {
let command = dbType === types_1.DBType.DBNODE
? CommandList.showNodeIndex
: CommandList.showEdgeIndex;
let uqlMaker = new utils_1.UQLMAKER(command, config);
let res = this.uql(uqlMaker.toString(), config);
return res;
}
/**
* List all node indexes
*/
async showNodeIndex(config) {
let command = CommandList.showNodeIndex;
let uqlMaker = new utils_1.UQLMAKER(command, config);
let res = await this.uql(uqlMaker.toString(), config);
let node_index = res.items[types_extra_1.ResponseTableName.NODE_INDEX].asIndexes();
// let edge_index = res.items.get(ResponseTableName.EDGE_INDEX).asIndexes();
return [...node_index];
}
/**
* List all edge indexes
*/
async showEdgeIndex(config) {
let command = CommandList.showEdgeIndex;
let uqlMaker = new utils_1.UQLMAKER(command, config);
let res = await this.uql(uqlMaker.toString(), config);
// let node_index = res.items.get(ResponseTableName.NODE_INDEX).asIndexes();
let edge_index = res.items[types_extra_1.ResponseTableName.EDGE_INDEX].asIndexes();
return [...edge_index];
}
/**
* Drop indexes in the current graphset.
*/
async dropIndex(dbType, indexName, config) {
let command = dbType === types_1.DBType.DBNODE
? CommandList.dropNodeIndex
: CommandList.dropEdgeIndex;
let uqlMaker = new utils_1.UQLMAKER(command, config, indexName);
let res = await this.uql(uqlMaker.toString(), config);
return res;
}
/**
* Drop node indexes in the current graphset.
* @param indexName
* @param config
* @returns
*/
async dropNodeIndex(indexName, config) {
return this.dropIndex(types_1.DBType.DBNODE, indexName, config);
}
/**
* Drop edge indexes in the current graphset.
* @param indexName
* @param config
* @returns
*/
async dropEdgeIndex(indexName, config) {
return this.dropIndex(types_1.DBType.DBEDGE, indexName, config);
}
/**
* Create a new index in the current graphset.
*/
async createIndex(
// req: RequestType.CreateIndex,
dbType, source, indexName, config) {
let command = dbType === types_1.DBType.DBNODE
? CommandList.createNodeIndex
: CommandList.createEdgeIndex;
let uqlMaker = new utils_1.UQLMAKER(command, config, [source, indexName]);
let res = await this.uql(uqlMaker.toString(), config);
return {
statisics: res.statistics,
status: res.status,
jobId: res.items[types_extra_1.ResponseTableName.JOB_RESULT].asTable().toKV().pop().new_job_id
};
}
/**
* Create a new node index in the current graphset.
* @param source
* @param indexName
* @param config
* @returns
*/
async createNodeIndex(source, indexName, config) {
return this.createIndex(types_1.DBType.DBNODE, source, indexName, config);
}
/**
* Create a new edge index in the current graphset.
* @param source
* @param indexName
* @param config
* @returns
*/
async createEdgeIndex(source, indexName, config) {
let command = CommandList.createEdgeIndex;
let commandParams = [source, indexName];
let uqlMaker = new utils_1.UQLMAKER(command, config, commandParams);
return this.uqlJobResponse(uqlMaker, config);
}
/**
* Show fulltext
*/
async showFulltextBase(dbType, config) {
let command = CommandList.showFulltext;
if (dbType === types_1.DBType.DBNODE) {
command = CommandList.showNodeFulltext;
}
else if (dbType === types_1.DBType.DBEDGE) {
command = CommandList.showEdgeFulltext;
}
let uqlMaker = new utils_1.UQLMAKER(command, config);
let res = await this.uql(uqlMaker.toString(), config);
let node_fulltext = res.aliases.find(a => a.name === types_extra_1.ResponseTableName.NODE_FULLTEXT) ? res.items[types_extra_1.ResponseTableName.NODE_FULLTEXT].asIndexes() : [];
let edge_fulltext = res.aliases.find(a => a.name === types_extra_1.ResponseTableName.EDGE_FULLTEXT) ? res.items[types_extra_1.ResponseTableName.EDGE_FULLTEXT].asIndexes() : [];
let fulltexts = [...node_fulltext, ...edge_fulltext];
return fulltexts;
}
/**
* Show all fulltext
*/
async showFulltext(config) {
return this.showFulltextBase(null, config);
}
/**
* Show node fulltext
* @param config
*/
async showNodeFulltext(config) {
return this.showFulltextBase(types_1.DBType.DBNODE, config);
}
/**
* Show edge fulltext
* @param config
*/
async showEdgeFulltext(config) {
return this.showFulltextBase(types_1.DBType.DBEDGE, config);
}
/**
* Create a new fulltext index in the current graphset.
*/
async createFulltext(dbType, schemaName, propertyName, fulltextName, config) {
let command = dbType === types_1.DBType.DBNODE
? CommandList.createNodeFulltext
: CommandList.createEdgeFulltext;
let uqlMaker = new utils_1.UQLMAKER(command, config, [SchemaStringWithDefault(schemaName, propertyName), fulltextName,]);
let res = await this.uql(uqlMaker.toString(), config);
return {
statisics: res.statistics,
status: res.status,
jobId: res.items[types_extra_1.ResponseTableName.JOB_RESULT].asTable().toKV().pop().new_job_id
};
}
/**
* Retrieves all fulltext indexes of node properties from the current graphset.
* @param schemaName
* @param propertyName
* @param indexName
* @param config
* @returns
*/
async createNodeFulltext(schemaName, propertyName, fulltextName, config) {
return this.createFulltext(types_1.DBType.DBNODE, schemaName, propertyName, fulltextName, config);
}
/**
* Retrieves all fulltext indexes of edge properties from the current graphset.
* @param schemaName
* @param propertyName
* @param indexName
* @param config
* @returns
*/
async createEdgeFulltext(schemaName, propertyName, fulltextName, config) {
return this.createFulltext(types_1.DBType.DBEDGE, schemaName, propertyName, fulltextName, config);
}
/**
* Drop a fulltext index in the current graphset.
*/
async dropFulltext(dbType, fulltextName, config) {
let command = dbType === types_1.DBType.DBNODE
? CommandList.dropNodeFulltext
: CommandList.dropEdgeFulltext;
let uqlMaker = new utils_1.UQLMAKER(command, config, fulltextName);
return this.uql(uqlMaker.toString(), config);
}
}
exports.IndexExtra = IndexExtra;
//# sourceMappingURL=index.extra.js.map