axiodb
Version:
The Pure JavaScript Alternative to SQLite. Embedded NoSQL database for Node.js with MongoDB-style queries, zero native dependencies, built-in InMemoryCache, and web GUI. Perfect for desktop apps, CLI tools, and embedded systems. No compilation, no platfor
121 lines • 4.41 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_types_1 = require("../tcp/types/command.types");
const ReaderProxy_1 = __importDefault(require("./ReaderProxy"));
const UpdateOperationProxy_1 = __importDefault(require("./UpdateOperationProxy"));
const DeleteOperationProxy_1 = __importDefault(require("./DeleteOperationProxy"));
const AggregationProxy_1 = __importDefault(require("./AggregationProxy"));
/**
* Collection Proxy - Remote proxy for Collection operations
* Mirrors the Collection class API
*/
class CollectionProxy {
constructor(client, dbName, collectionName) {
this.client = client;
this.dbName = dbName;
this.collectionName = collectionName;
}
/**
* Insert a single document
*/
insert(data) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.client.sendCommand(command_types_1.CommandType.INSERT_DOCUMENT, {
dbName: this.dbName,
collectionName: this.collectionName,
data,
});
});
}
/**
* Insert many documents
*/
insertMany(documents) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.client.sendCommand(command_types_1.CommandType.INSERT_MANY_DOCUMENTS, {
dbName: this.dbName,
collectionName: this.collectionName,
documents,
});
});
}
/**
* Query documents - returns a query builder
*/
query(query) {
return new ReaderProxy_1.default(this.client, this.dbName, this.collectionName, query);
}
/**
* Update documents - returns an update operation builder
*/
update(query) {
return new UpdateOperationProxy_1.default(this.client, this.dbName, this.collectionName, query);
}
/**
* Delete documents - returns a delete operation builder
*/
delete(query) {
return new DeleteOperationProxy_1.default(this.client, this.dbName, this.collectionName, query);
}
/**
* Aggregate - returns an aggregation builder
*/
aggregate(pipeline) {
return new AggregationProxy_1.default(this.client, this.dbName, this.collectionName, pipeline);
}
/**
* Get total document count
*/
totalDocuments() {
return __awaiter(this, void 0, void 0, function* () {
return yield this.client.sendCommand(command_types_1.CommandType.TOTAL_DOCUMENTS, {
dbName: this.dbName,
collectionName: this.collectionName,
});
});
}
/**
* Create index on fields
*/
newIndex(...fieldNames) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.client.sendCommand(command_types_1.CommandType.CREATE_INDEX, {
dbName: this.dbName,
collectionName: this.collectionName,
fieldNames,
});
});
}
/**
* Drop an index
*/
dropIndex(indexName) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.client.sendCommand(command_types_1.CommandType.DROP_INDEX, {
dbName: this.dbName,
collectionName: this.collectionName,
indexName,
});
});
}
/**
* Get collection name
*/
get name() {
return this.collectionName;
}
}
exports.default = CollectionProxy;
//# sourceMappingURL=CollectionProxy.js.map