axiodb 2.31.104 → 3.31.105
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -476
- package/lib/Services/Indexation.operation.d.ts +2 -1
- package/lib/Services/Indexation.operation.js +7 -2
- package/lib/Services/Indexation.operation.js.map +1 -1
- package/lib/config/Keys/Keys.d.ts +5 -4
- package/lib/config/Keys/Keys.js +5 -5
- package/lib/config/Keys/Keys.js.map +1 -1
- package/lib/engine/node/WorkerForDataLoad.engine.js +40 -45
- package/lib/engine/node/WorkerForDataLoad.engine.js.map +1 -1
- package/lib/engine/node/WorkerForSearch.engine.js +12 -18
- package/lib/engine/node/WorkerForSearch.engine.js.map +1 -1
- package/lib/server/public/AxioControl/.vite/manifest.json +2 -2
- package/lib/server/public/AxioControl/assets/index-C8TNGVxT.css +1 -0
- package/lib/server/public/AxioControl/index.html +2 -2
- package/lib/server/public/AxioControl/sw.js +1 -1
- package/lib/utility/BufferLoaderWithWorker.utils.js +2 -1
- package/lib/utility/BufferLoaderWithWorker.utils.js.map +1 -1
- package/lib/utility/Searcher.utils.d.ts +4 -2
- package/lib/utility/Searcher.utils.js +24 -4
- package/lib/utility/Searcher.utils.js.map +1 -1
- package/lib/utility/SortData.utils.d.ts +1 -0
- package/lib/utility/SortData.utils.js +33 -8
- package/lib/utility/SortData.utils.js.map +1 -1
- package/package.json +1 -1
- package/lib/server/public/AxioControl/assets/index-BfyBz2WH.css +0 -1
- /package/lib/server/public/AxioControl/assets/{index-TLwj6wdu.js → index-BRkVgnlw.js} +0 -0
package/README.md
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
|
-
# AxioDB: The
|
|
1
|
+
# AxioDB: The Pure JavaScript Alternative to SQLite
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/axiodb)
|
|
4
4
|
[](https://github.com/nexoral/AxioDB/actions/workflows/github-code-scanning/codeql)
|
|
5
5
|
[](https://socket.dev/npm/package/axiodb)
|
|
6
6
|
[](https://github.com/nexoral/AxioDB/actions/workflows/Push.yml)
|
|
7
7
|
|
|
8
|
-
> **AxioDB** is
|
|
8
|
+
> **AxioDB** is an embedded NoSQL database for Node.js with MongoDB-style queries. Zero native dependencies, no compilation, no platform issues. Pure JavaScript from npm install to production. Think SQLite, but NoSQL with JavaScript queries—perfect for desktop apps, CLI tools, and embedded systems.
|
|
9
9
|
|
|
10
10
|
👉 **[Official Documentation](https://axiodb.site/)**: Access full guides, examples, and API references.
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## 🎯 Why AxioDB?
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
**SQLite requires native C bindings that cause deployment headaches. JSON files have no querying or caching. MongoDB needs a separate server. AxioDB combines the best of all: embedded like SQLite, NoSQL queries like MongoDB, intelligent caching built-in.**
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
### The Problem with SQLite
|
|
19
|
+
|
|
20
|
+
SQLite is great, but it requires native bindings that break in Electron and cross-platform deployments:
|
|
21
|
+
|
|
22
|
+
- ❌ `electron-rebuild` on every Electron update
|
|
23
|
+
- ❌ Platform-specific builds (Windows .node files ≠ Mac .node files)
|
|
24
|
+
- ❌ SQL strings instead of JavaScript objects
|
|
25
|
+
- ❌ Schema migrations when your data model changes
|
|
26
|
+
- ❌ `node-gyp` compilation headaches
|
|
27
|
+
|
|
28
|
+
### AxioDB Solution
|
|
29
|
+
|
|
30
|
+
- ✅ Works everywhere Node.js runs—no rebuild, no native dependencies
|
|
31
|
+
- ✅ MongoDB-style queries: `{age: {$gt: 25}}`
|
|
32
|
+
- ✅ Schema-less JSON documents—no migrations
|
|
33
|
+
- ✅ Built-in InMemoryCache with automatic invalidation
|
|
34
|
+
- ✅ Multi-core parallelism with Worker Threads
|
|
35
|
+
- ✅ Built-in web GUI at `localhost:27018`
|
|
22
36
|
|
|
23
37
|
---
|
|
24
38
|
|
|
@@ -41,15 +55,30 @@ As a Node.js backend engineer, setting up Redis for small prototypes, struggling
|
|
|
41
55
|
|
|
42
56
|
## 🏆 Performance Comparison
|
|
43
57
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
| Query
|
|
50
|
-
|
|
|
58
|
+
### AxioDB vs SQLite
|
|
59
|
+
|
|
60
|
+
| Feature | SQLite | AxioDB |
|
|
61
|
+
| ------- | ------ | ------ |
|
|
62
|
+
| **Native Dependencies** | ❌ Yes (C bindings) | ✅ Pure JavaScript |
|
|
63
|
+
| **Query Language** | SQL Strings | JavaScript Objects |
|
|
64
|
+
| **Schema Migrations** | ❌ Required (ALTER TABLE) | ✅ Schema-less (optional) |
|
|
65
|
+
| **Built-in Caching** | ⚠️ Manual | ✅ InMemoryCache |
|
|
66
|
+
| **Multi-core Processing** | ❌ Single-threaded | ✅ Worker Threads |
|
|
67
|
+
| **Built-in GUI** | ❌ External tools only | ✅ Web interface included |
|
|
68
|
+
| **Best For** | 10M+ records, relational data | 10K-500K documents, embedded apps |
|
|
69
|
+
|
|
70
|
+
### AxioDB vs Traditional JSON Files
|
|
51
71
|
|
|
52
|
-
|
|
72
|
+
| Feature | Traditional JSON Files | AxioDB |
|
|
73
|
+
| ------- | --------------------- | ------ |
|
|
74
|
+
| **Storage** | Single JSON file | File-per-document |
|
|
75
|
+
| **Caching** | None | InMemoryCache |
|
|
76
|
+
| **Indexing** | None | Auto documentId |
|
|
77
|
+
| **Query Speed** | Linear O(n) | Sub-millisecond O(1) |
|
|
78
|
+
| **Scalability** | Poor | Excellent |
|
|
79
|
+
| **Built-in Query Operators** | None | $gt, $lt, $regex, $in |
|
|
80
|
+
|
|
81
|
+
**Benchmark:** AxioDB's documentId search with InMemoryCache provides **instant retrieval** compared to traditional JSON files that require full-file parsing (tested with 1M+ documents).
|
|
53
82
|
|
|
54
83
|
---
|
|
55
84
|
|
|
@@ -71,6 +100,32 @@ For vulnerabilities, see [SECURITY.md](SECURITY.md).
|
|
|
71
100
|
|
|
72
101
|
---
|
|
73
102
|
|
|
103
|
+
## 🎨 Built-in Web GUI
|
|
104
|
+
|
|
105
|
+
AxioDB includes a built-in web-based GUI for database visualization and management—perfect for Electron apps and development environments.
|
|
106
|
+
|
|
107
|
+
### Enabling the GUI
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
// Enable GUI when creating AxioDB instance
|
|
111
|
+
const db = new AxioDB(true); // GUI available at localhost:27018
|
|
112
|
+
|
|
113
|
+
// With custom database path
|
|
114
|
+
const db = new AxioDB(true, "MyDB", "./custom/path");
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### GUI Features
|
|
118
|
+
|
|
119
|
+
- 📊 Visual database and collection browser
|
|
120
|
+
- 🔍 Real-time data inspection
|
|
121
|
+
- 📝 Query execution interface
|
|
122
|
+
- 📈 Performance monitoring
|
|
123
|
+
- 🎯 No external dependencies required
|
|
124
|
+
|
|
125
|
+
Access the GUI at `http://localhost:27018` when enabled.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
74
129
|
## ⚙️ Architecture & Internal Mechanisms
|
|
75
130
|
|
|
76
131
|
### Tree Structure for Fast Data Retrieval
|
|
@@ -85,6 +140,10 @@ Leverages Node.js Worker Threads for non-blocking I/O, multi-core utilization, a
|
|
|
85
140
|
|
|
86
141
|
Optimized for range queries and filtered searches, minimizing memory usage and computational overhead.
|
|
87
142
|
|
|
143
|
+
### InMemoryCache System
|
|
144
|
+
|
|
145
|
+
Built-in intelligent caching with automatic eviction policies, TTL support, and memory optimization. Delivers sub-millisecond response times for frequently accessed data.
|
|
146
|
+
|
|
88
147
|
### Query Processing Pipeline
|
|
89
148
|
|
|
90
149
|
Intelligent caching, parallelized processing, lazy evaluation, and just-in-time query optimization for maximum throughput.
|
|
@@ -107,9 +166,34 @@ npm install axiodb@latest --save
|
|
|
107
166
|
|
|
108
167
|
---
|
|
109
168
|
|
|
110
|
-
## 🛠️
|
|
169
|
+
## 🛠️ Quick Start
|
|
111
170
|
|
|
112
|
-
|
|
171
|
+
### Hello World in 30 Seconds
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
// npm install axiodb
|
|
175
|
+
const { AxioDB } = require('axiodb');
|
|
176
|
+
|
|
177
|
+
// Create AxioDB instance with built-in GUI
|
|
178
|
+
const db = new AxioDB(true); // Enable GUI at localhost:27018
|
|
179
|
+
|
|
180
|
+
// Create database and collection
|
|
181
|
+
const myDB = await db.createDB('HelloWorldDB');
|
|
182
|
+
const collection = await myDB.createCollection('greetings', false);
|
|
183
|
+
|
|
184
|
+
// Insert and retrieve data - Hello World! 👋
|
|
185
|
+
await collection.insert({ message: 'Hello, Developer! 👋' });
|
|
186
|
+
const result = await collection.findAll();
|
|
187
|
+
console.log(result[0].message); // Hello, Developer! 👋
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Node.js Required:** AxioDB runs on Node.js servers (v20.0.0+), not in browsers.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 🛠️ Detailed Usage
|
|
195
|
+
|
|
196
|
+
> **Important:** Only one AxioDB instance should be initialized per application for consistency and security.
|
|
113
197
|
|
|
114
198
|
### Collection Creation Options
|
|
115
199
|
|
|
@@ -202,516 +286,113 @@ console.log(results);
|
|
|
202
286
|
|
|
203
287
|
---
|
|
204
288
|
|
|
205
|
-
##
|
|
289
|
+
## 🎯 When to Use AxioDB
|
|
206
290
|
|
|
207
|
-
|
|
208
|
-
-
|
|
209
|
-
-
|
|
210
|
-
-
|
|
211
|
-
-
|
|
291
|
+
**Perfect For:**
|
|
292
|
+
- 🖥️ Desktop apps (Electron, Tauri)
|
|
293
|
+
- 🛠️ CLI tools
|
|
294
|
+
- 📦 Embedded systems
|
|
295
|
+
- 🚀 Rapid prototyping
|
|
296
|
+
- 🏠 Local-first applications
|
|
297
|
+
- 💻 Node.js apps requiring local storage
|
|
212
298
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
## 🔮 Future Roadmap
|
|
216
|
-
|
|
217
|
-
- **Data Export & Import:** JSON, CSV, and native formats
|
|
218
|
-
- **Enhanced Web GUI:** Real-time analytics, visual query builder, performance monitoring
|
|
219
|
-
- **Comprehensive Documentation:** Tutorials, interactive examples, and API references
|
|
299
|
+
**Sweet Spot:** 10K-500K documents with intelligent caching
|
|
220
300
|
|
|
221
301
|
---
|
|
222
302
|
|
|
223
|
-
##
|
|
224
|
-
|
|
225
|
-
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
303
|
+
## 💭 Honest Positioning
|
|
226
304
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
## 📜 License
|
|
305
|
+
**AxioDB is not competing with PostgreSQL or MongoDB.** It's for when you need a database embedded in your app—no server setup, no native dependencies. Think SQLite-scale with MongoDB-style queries and built-in caching.
|
|
230
306
|
|
|
231
|
-
|
|
307
|
+
When you outgrow AxioDB (1M+ documents, distributed systems), migrate to PostgreSQL or MongoDB. That's the right choice, and we support it.
|
|
232
308
|
|
|
233
309
|
---
|
|
234
310
|
|
|
235
|
-
##
|
|
236
|
-
|
|
237
|
-
Special thanks to all contributors and supporters of AxioDB. Your feedback and contributions make this project better!
|
|
238
|
-
|
|
239
|
-
## ⚠️ Current Limitations
|
|
240
|
-
|
|
241
|
-
While AxioDB offers many powerful features, there are some limitations to consider:
|
|
311
|
+
## ⚠️ Limitations & Scale Considerations
|
|
242
312
|
|
|
243
|
-
|
|
313
|
+
### Scale & Performance Boundaries
|
|
244
314
|
|
|
245
|
-
- **
|
|
315
|
+
- **Dataset Size:** Optimized for 10K-500K documents. For 10M+ documents, use PostgreSQL, MongoDB, or SQLite which are designed for massive scale.
|
|
246
316
|
|
|
247
|
-
- **Single-
|
|
248
|
-
|
|
249
|
-
- **Limited Query Complexity:** Some advanced query patterns found in mature databases are not yet implemented.
|
|
250
|
-
|
|
251
|
-
- **No Built-in Replication:** Currently lacks distributed data replication capabilities for high availability setups.
|
|
252
|
-
|
|
253
|
-
We're actively working to address these limitations in future releases.
|
|
254
|
-
|
|
255
|
-
---
|
|
317
|
+
- **Concurrency:** Single-instance architecture. For multi-user web applications with hundreds of concurrent connections, use traditional client-server databases.
|
|
256
318
|
|
|
257
|
-
|
|
319
|
+
- **Relational Data:** Document-based NoSQL architecture. No JOIN operations. For complex relational data with foreign keys and constraints, use SQL databases.
|
|
258
320
|
|
|
259
|
-
|
|
321
|
+
- **Distributed Systems:** Single-node only. No replication, no sharding, no clustering. For distributed systems, use MongoDB or CouchDB.
|
|
260
322
|
|
|
261
|
-
- **
|
|
262
|
-
- **Data Export and Import Mechanisms:** Enable seamless export and import of data in various formats like JSON, CSV, and more.
|
|
263
|
-
- **Improved Query Optimization:** Enhance query performance with advanced optimization techniques.
|
|
264
|
-
- **Data Backup and Restore:** Implement robust backup and restore mechanisms for data safety.
|
|
265
|
-
- **Comprehensive Documentation:** Expand tutorials, examples, and API references for developers.
|
|
323
|
+
- **Transactions:** No ACID transactions across multiple collections. For transaction requirements, use PostgreSQL or MongoDB with transactions enabled.
|
|
266
324
|
|
|
267
325
|
---
|
|
268
326
|
|
|
269
|
-
##
|
|
270
|
-
|
|
271
|
-
Install AxioDB via npm:
|
|
327
|
+
## 🔮 Future Roadmap
|
|
272
328
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
329
|
+
- **Data Export & Import:** Seamless data migration with support for JSON, CSV, and native AxioDB formats
|
|
330
|
+
- **Enhanced Web GUI:** Advanced web interface with real-time analytics, visual query builder, and performance monitoring
|
|
331
|
+
- **Comprehensive Documentation:** Extensive tutorials, interactive examples, and complete API references for all skill levels
|
|
332
|
+
- **Performance Optimizations:** Continued improvements to query performance and caching strategies
|
|
276
333
|
|
|
277
334
|
---
|
|
278
335
|
|
|
279
|
-
##
|
|
280
|
-
|
|
281
|
-
> **Important Note:** AxioDB uses a single instance architecture. You should initialize only one AxioDB instance with the `new` keyword, under which you can create unlimited databases, collections, and documents. This design ensures data consistency and security across your application.
|
|
282
|
-
|
|
283
|
-
### Collection Creation Options
|
|
284
|
-
|
|
285
|
-
When creating collections, you need to specify these parameters in the `createCollection` method:
|
|
286
|
-
|
|
287
|
-
```javascript
|
|
288
|
-
// Signature of createCollection method:
|
|
289
|
-
createCollection(
|
|
290
|
-
name: string, // Name of the collection (required)
|
|
291
|
-
isSchemaNeeded: boolean, // Whether schema validation is needed (required)
|
|
292
|
-
schema?: object | any, // Schema definition (required if isSchemaNeeded is true, empty {} if false)
|
|
293
|
-
isEncrypted?: boolean, // Whether to encrypt the collection (default: false)
|
|
294
|
-
encryptionKey?: string // Custom encryption key (optional, system generates one if not provided)
|
|
295
|
-
)
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
Examples:
|
|
299
|
-
|
|
300
|
-
```javascript
|
|
301
|
-
// Create collection with schema validation
|
|
302
|
-
const collection1 = await db1.createCollection("testCollection", true, schema);
|
|
303
|
-
|
|
304
|
-
// Create collection without schema validation
|
|
305
|
-
const collection2 = await db1.createCollection("testCollection2", false);
|
|
306
|
-
|
|
307
|
-
// Create an encrypted collection with schema validation and default encryption key
|
|
308
|
-
const collection3 = await db1.createCollection(
|
|
309
|
-
"testCollection3",
|
|
310
|
-
true,
|
|
311
|
-
schema,
|
|
312
|
-
true,
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
// Create an encrypted collection with schema validation and custom encryption key
|
|
316
|
-
const collection4 = await db1.createCollection(
|
|
317
|
-
"testCollection4",
|
|
318
|
-
true,
|
|
319
|
-
schema,
|
|
320
|
-
true,
|
|
321
|
-
"myCustomKey",
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
// Create an encrypted collection without schema validation (using empty object for schema)
|
|
325
|
-
const collection5 = await db1.createCollection(
|
|
326
|
-
"testCollection5",
|
|
327
|
-
false,
|
|
328
|
-
{},
|
|
329
|
-
true,
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
// Create an encrypted collection without schema and with custom key
|
|
333
|
-
const collection6 = await db1.createCollection(
|
|
334
|
-
"testCollection6",
|
|
335
|
-
false,
|
|
336
|
-
{},
|
|
337
|
-
true,
|
|
338
|
-
"myCustomKey",
|
|
339
|
-
);
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
### CommonJS Example
|
|
343
|
-
|
|
344
|
-
```javascript
|
|
345
|
-
const { AxioDB, SchemaTypes } = require("axiodb");
|
|
346
|
-
|
|
347
|
-
// Create a single AxioDB instance for your entire application
|
|
348
|
-
// This will also start the Web GUI on localhost:27018 (currently under development)
|
|
349
|
-
const db = new AxioDB();
|
|
350
|
-
|
|
351
|
-
const main = async () => {
|
|
352
|
-
// Create multiple databases under the single instance
|
|
353
|
-
const db1 = await db.createDB("testDB");
|
|
354
|
-
const db2 = await db.createDB("testDB2", false);
|
|
355
|
-
|
|
356
|
-
// Define a schema
|
|
357
|
-
const schema = {
|
|
358
|
-
name: SchemaTypes.string().required(),
|
|
359
|
-
age: SchemaTypes.number().required().min(1).max(100),
|
|
360
|
-
email: SchemaTypes.string().required().email(),
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
// Create collections with and without schema validation
|
|
364
|
-
const collectionNoSchema = await db1.createCollection(
|
|
365
|
-
"testCollection2",
|
|
366
|
-
false,
|
|
367
|
-
);
|
|
368
|
-
const collectionExplicitSchema = await db1.createCollection(
|
|
369
|
-
"testCollection3",
|
|
370
|
-
true,
|
|
371
|
-
schema,
|
|
372
|
-
);
|
|
373
|
-
const collectionWithEncryption = await db1.createCollection(
|
|
374
|
-
"testCollection4",
|
|
375
|
-
schema,
|
|
376
|
-
true,
|
|
377
|
-
"myKey",
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
// Insert data
|
|
381
|
-
const saveStatus = await collection.insert({
|
|
382
|
-
name: "Ankan",
|
|
383
|
-
age: 21,
|
|
384
|
-
email: "ankan@example.com",
|
|
385
|
-
});
|
|
386
|
-
console.log(saveStatus);
|
|
387
|
-
|
|
388
|
-
// Query data
|
|
389
|
-
const totalDocuments = await collection
|
|
390
|
-
.query({})
|
|
391
|
-
.Limit(1)
|
|
392
|
-
.Skip(0)
|
|
393
|
-
.Sort({ name: 1 })
|
|
394
|
-
.setCount(true)
|
|
395
|
-
.setProject({ name: 1, age: 1 })
|
|
396
|
-
.exec();
|
|
397
|
-
console.log(totalDocuments);
|
|
398
|
-
|
|
399
|
-
const FastDocument = await collection
|
|
400
|
-
.query({ documentId: "S4ACDVS6SZ4S6VS" })
|
|
401
|
-
.exec(); // By using documentId you can get the document in Lightning Fast Speed, no matter how many documents are in the collection (Tested with 1000000+ documents)
|
|
402
|
-
console.log(FastDocument);
|
|
403
|
-
|
|
404
|
-
const ArrayFirstDocument = await collection
|
|
405
|
-
.query({ documentId: ["S4ACDVS6SZ4S6VS", "VESV61Z6VS16VSE6V1S"] })
|
|
406
|
-
.exec(); // query using an array of documentId to get multiple documents in lightning fast speed, no matter how many documents are in the collection (Tested with 1000000+ documents)
|
|
407
|
-
console.log(ArrayFirstDocument);
|
|
408
|
-
|
|
409
|
-
// Update data
|
|
410
|
-
const updatedDocuments = await collection
|
|
411
|
-
.update({ name: { $regex: "Ankan" } })
|
|
412
|
-
.UpdateOne({ name: "Ankan Saha", age: 22 });
|
|
413
|
-
console.log(updatedDocuments);
|
|
414
|
-
|
|
415
|
-
// Delete data
|
|
416
|
-
const deletedDocuments = await collection
|
|
417
|
-
.delete({ name: { $regex: "Ankan" } })
|
|
418
|
-
.deleteOne();
|
|
419
|
-
console.log(deletedDocuments);
|
|
420
|
-
|
|
421
|
-
// Aggregation
|
|
422
|
-
const response = await collection
|
|
423
|
-
.aggregate([
|
|
424
|
-
{ $match: { age: { $gt: 20 }, name: { $regex: "Ankan" } } },
|
|
425
|
-
{ $group: { _id: "$age", count: { $sum: 1 } } },
|
|
426
|
-
{ $sort: { count: -1 } },
|
|
427
|
-
{ $project: { _id: 0, age: "$_id", count: 1 } },
|
|
428
|
-
{ $limit: 10 },
|
|
429
|
-
{ $skip: 0 },
|
|
430
|
-
])
|
|
431
|
-
.exec();
|
|
432
|
-
console.log(response);
|
|
433
|
-
};
|
|
336
|
+
## 🤝 Contributing
|
|
434
337
|
|
|
435
|
-
|
|
436
|
-
```
|
|
338
|
+
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
437
339
|
|
|
438
340
|
---
|
|
439
341
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
```javascript
|
|
443
|
-
import { AxioDB, SchemaTypes } from "axiodb";
|
|
444
|
-
|
|
445
|
-
const main = async () => {
|
|
446
|
-
const db = new AxioDB();
|
|
447
|
-
|
|
448
|
-
// Create a database with schema validation (default)
|
|
449
|
-
const db1 = await db.createDB("testDB");
|
|
450
|
-
|
|
451
|
-
// Create a database without schema validation
|
|
452
|
-
const db2 = await db.createDB("testDB2", false);
|
|
453
|
-
|
|
454
|
-
// Define a schema
|
|
455
|
-
const schema = {
|
|
456
|
-
name: SchemaTypes.string().required(),
|
|
457
|
-
age: SchemaTypes.number().required().min(1).max(100),
|
|
458
|
-
email: SchemaTypes.string().required().email(),
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
// Create collections with and without schema validation
|
|
462
|
-
const collectionNoSchema = await db1.createCollection(
|
|
463
|
-
"testCollection2",
|
|
464
|
-
false,
|
|
465
|
-
);
|
|
466
|
-
const collectionExplicitSchema = await db1.createCollection(
|
|
467
|
-
"testCollection3",
|
|
468
|
-
true,
|
|
469
|
-
schema,
|
|
470
|
-
);
|
|
471
|
-
const collectionWithEncryption = await db1.createCollection(
|
|
472
|
-
"testCollection4",
|
|
473
|
-
schema,
|
|
474
|
-
true,
|
|
475
|
-
"myKey",
|
|
476
|
-
);
|
|
477
|
-
|
|
478
|
-
// Insert data
|
|
479
|
-
const saveStatus = await collection.insert({
|
|
480
|
-
name: "Ankan",
|
|
481
|
-
age: 21,
|
|
482
|
-
email: "ankan@example.com",
|
|
483
|
-
});
|
|
484
|
-
console.log(saveStatus);
|
|
485
|
-
|
|
486
|
-
// Query data
|
|
487
|
-
const totalDocuments = await collection
|
|
488
|
-
.query({})
|
|
489
|
-
.Limit(1)
|
|
490
|
-
.Skip(0)
|
|
491
|
-
.Sort({ name: 1 })
|
|
492
|
-
.setCount(true)
|
|
493
|
-
.setProject({ name: 1, age: 1 })
|
|
494
|
-
.exec();
|
|
495
|
-
console.log(totalDocuments);
|
|
496
|
-
|
|
497
|
-
const FastDocument = await collection
|
|
498
|
-
.query({ documentId: "S4ACDVS6SZ4S6VS" })
|
|
499
|
-
.exec(); // By using documentId you can get the document in Lightning Fast Speed, no matter how many documents are in the collection (Tested with 1000000+ documents)
|
|
500
|
-
console.log(FastDocument);
|
|
501
|
-
|
|
502
|
-
const ArrayFirstDocument = await collection
|
|
503
|
-
.query({ documentId: ["S4ACDVS6SZ4S6VS", "VESV61Z6VS16VSE6V1S"] })
|
|
504
|
-
.exec(); // query using an array of documentId to get multiple documents in lightning fast speed, no matter how many documents are in the collection (Tested with 1000000+ documents)
|
|
505
|
-
console.log(ArrayFirstDocument);
|
|
506
|
-
|
|
507
|
-
// Update data
|
|
508
|
-
const updatedDocuments = await collection
|
|
509
|
-
.update({ name: { $regex: "Ankan" } })
|
|
510
|
-
.UpdateOne({ name: "Ankan Saha", age: 22 });
|
|
511
|
-
console.log(updatedDocuments);
|
|
512
|
-
|
|
513
|
-
// Delete data
|
|
514
|
-
const deletedDocuments = await collection
|
|
515
|
-
.delete({ name: { $regex: "Ankan" } })
|
|
516
|
-
.deleteOne();
|
|
517
|
-
console.log(deletedDocuments);
|
|
518
|
-
|
|
519
|
-
// Aggregation
|
|
520
|
-
const response = await collection
|
|
521
|
-
.aggregate([
|
|
522
|
-
{ $match: { age: { $gt: 20 }, name: { $regex: "Ankan" } } },
|
|
523
|
-
{ $group: { _id: "$age", count: { $sum: 1 } } },
|
|
524
|
-
{ $sort: { count: -1 } },
|
|
525
|
-
{ $project: { _id: 0, age: "$_id", count: 1 } },
|
|
526
|
-
{ $limit: 10 },
|
|
527
|
-
{ $skip: 0 },
|
|
528
|
-
])
|
|
529
|
-
.exec();
|
|
530
|
-
console.log(response);
|
|
531
|
-
};
|
|
342
|
+
## 📜 License
|
|
532
343
|
|
|
533
|
-
|
|
534
|
-
```
|
|
344
|
+
MIT License. See [LICENSE](LICENSE).
|
|
535
345
|
|
|
536
346
|
---
|
|
537
347
|
|
|
538
|
-
##
|
|
539
|
-
|
|
540
|
-
### 1. **Creating Multiple Databases and Collections**
|
|
541
|
-
|
|
542
|
-
```javascript
|
|
543
|
-
const { AxioDB, SchemaTypes } = require("axiodb");
|
|
544
|
-
|
|
545
|
-
const db = new AxioDB();
|
|
546
|
-
|
|
547
|
-
const setup = async () => {
|
|
548
|
-
const schema = {
|
|
549
|
-
name: SchemaTypes.string().required().max(15),
|
|
550
|
-
age: SchemaTypes.number().required().min(18),
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
const DB1 = await db.createDB("DB1");
|
|
554
|
-
const collection1 = await DB1.createCollection(
|
|
555
|
-
"collection1",
|
|
556
|
-
schema,
|
|
557
|
-
true,
|
|
558
|
-
"secretKey",
|
|
559
|
-
);
|
|
560
|
-
|
|
561
|
-
// Insert data
|
|
562
|
-
for (let i = 0; i < 300; i++) {
|
|
563
|
-
await collection1.insert({ name: `User${i}`, age: i + 18 });
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
// Query data
|
|
567
|
-
const results = await collection1
|
|
568
|
-
.query({})
|
|
569
|
-
.Sort({ age: -1 })
|
|
570
|
-
.Limit(10)
|
|
571
|
-
.exec();
|
|
572
|
-
console.log("Query Results:", results);
|
|
573
|
-
|
|
574
|
-
// Delete collection
|
|
575
|
-
await DB1.deleteCollection("collection1");
|
|
576
|
-
};
|
|
348
|
+
## 🙌 Acknowledgments
|
|
577
349
|
|
|
578
|
-
|
|
579
|
-
```
|
|
350
|
+
Special thanks to all contributors and supporters of AxioDB. Your feedback and contributions make this project better!
|
|
580
351
|
|
|
581
352
|
---
|
|
582
353
|
|
|
583
|
-
|
|
354
|
+
## 📋 Requirements
|
|
584
355
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
const aggregationResult = await collection1
|
|
589
|
-
.aggregate([
|
|
590
|
-
{ $match: { name: { $regex: "User" } } },
|
|
591
|
-
{ $project: { name: 1, age: 1 } },
|
|
592
|
-
{ $sort: { age: -1 } },
|
|
593
|
-
{ $limit: 10 },
|
|
594
|
-
])
|
|
595
|
-
.exec();
|
|
596
|
-
|
|
597
|
-
console.log("Aggregation Result:", aggregationResult);
|
|
598
|
-
```
|
|
356
|
+
- **Node.js:** >=20.0.0
|
|
357
|
+
- **npm:** >=6.0.0
|
|
358
|
+
- **yarn:** >=1.0.0 (optional)
|
|
599
359
|
|
|
600
360
|
---
|
|
601
361
|
|
|
602
|
-
|
|
362
|
+
## 🌐 Documentation Website
|
|
603
363
|
|
|
604
|
-
|
|
364
|
+
The AxioDB documentation is built with:
|
|
365
|
+
- **React 18** with TypeScript
|
|
366
|
+
- **Vite** for fast development and building
|
|
367
|
+
- **TailwindCSS** for styling
|
|
368
|
+
- **Lucide React** for icons
|
|
605
369
|
|
|
606
|
-
|
|
607
|
-
const encryptedCollection = await DB1.createCollection(
|
|
608
|
-
"secureCollection",
|
|
609
|
-
schema,
|
|
610
|
-
true,
|
|
611
|
-
"mySecretKey",
|
|
612
|
-
);
|
|
613
|
-
|
|
614
|
-
// Insert encrypted data
|
|
615
|
-
await encryptedCollection.insert({ name: "Encrypted User", age: 25 });
|
|
616
|
-
|
|
617
|
-
// Query encrypted data
|
|
618
|
-
const encryptedResult = await encryptedCollection.query({ age: 25 }).exec();
|
|
619
|
-
console.log("Encrypted Query Result:", encryptedResult);
|
|
620
|
-
```
|
|
621
|
-
|
|
622
|
-
---
|
|
370
|
+
To run the documentation locally:
|
|
623
371
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
```javascript
|
|
629
|
-
// Update a single document
|
|
630
|
-
await collection1
|
|
631
|
-
.update({ age: 20 })
|
|
632
|
-
.UpdateOne({ name: "Updated User", gender: "Male" });
|
|
633
|
-
|
|
634
|
-
// Update multiple documents
|
|
635
|
-
await collection1
|
|
636
|
-
.update({ name: { $regex: "User" } })
|
|
637
|
-
.UpdateMany({ isActive: true });
|
|
372
|
+
```bash
|
|
373
|
+
cd Document
|
|
374
|
+
npm install
|
|
375
|
+
npm run dev
|
|
638
376
|
```
|
|
639
377
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
```javascript
|
|
643
|
-
// Delete a single document
|
|
644
|
-
await collection1.delete({ name: "User1" }).deleteOne();
|
|
645
|
-
|
|
646
|
-
// Delete multiple documents
|
|
647
|
-
await collection1.delete({ age: { $lt: 25 } }).deleteMany();
|
|
648
|
-
```
|
|
378
|
+
The documentation site will be available at `http://localhost:5173`
|
|
649
379
|
|
|
650
380
|
---
|
|
651
381
|
|
|
652
|
-
##
|
|
382
|
+
## 📝 Author
|
|
653
383
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
- **`createDB(dbName: string, schemaValidation: boolean = true): Promise<Database>`**
|
|
657
|
-
Creates a new database. The optional `schemaValidation` parameter (default: true) determines whether schema validation will be enforced for collections in this database.
|
|
658
|
-
|
|
659
|
-
- **`deleteDatabase(dbName: string): Promise<SuccessInterface | ErrorInterface>`**
|
|
660
|
-
Deletes a database.
|
|
661
|
-
|
|
662
|
-
### Database
|
|
663
|
-
|
|
664
|
-
- **`createCollection(name: string, schema: object, crypto?: boolean, key?: string): Promise<Collection>`**
|
|
665
|
-
Creates a collection with an optional schema and encryption.
|
|
666
|
-
|
|
667
|
-
- **`deleteCollection(name: string): Promise<SuccessInterface | ErrorInterface>`**
|
|
668
|
-
Deletes a collection.
|
|
669
|
-
|
|
670
|
-
- **`getCollectionInfo(): Promise<SuccessInterface>`**
|
|
671
|
-
Retrieves information about all collections.
|
|
672
|
-
|
|
673
|
-
### Collection
|
|
674
|
-
|
|
675
|
-
- **`createCollection(name: string, schemaOrBoolean: object | boolean, schemaOrEmpty?: object, crypto?: boolean, key?: string): Promise<Collection>`**
|
|
676
|
-
Creates a collection with optional schema validation and encryption. The parameters are flexible:
|
|
677
|
-
- If the second parameter is a schema object, schema validation is enabled
|
|
678
|
-
- If the second parameter is a boolean, it determines whether schema validation is enabled
|
|
679
|
-
- For collections without schema but with encryption, pass `false, {}, true` as parameters
|
|
680
|
-
- The encryption key parameter is optional - if not provided, a default key will be generated
|
|
681
|
-
|
|
682
|
-
- **`insert(data: object): Promise<SuccessInterface | ErrorInterface>`**
|
|
683
|
-
Inserts a document into the collection.
|
|
684
|
-
|
|
685
|
-
- **`query(query: object): Reader`**
|
|
686
|
-
Queries documents in the collection.
|
|
687
|
-
|
|
688
|
-
- **`aggregate(pipeline: object[]): Aggregation`**
|
|
689
|
-
Performs aggregation operations.
|
|
690
|
-
|
|
691
|
-
### Reader
|
|
692
|
-
|
|
693
|
-
- **`Limit(limit: number): Reader`**
|
|
694
|
-
Sets a limit on the number of documents.
|
|
695
|
-
|
|
696
|
-
- **`Skip(skip: number): Reader`**
|
|
697
|
-
Skips a number of documents.
|
|
698
|
-
|
|
699
|
-
- **`Sort(sort: object): Reader`**
|
|
700
|
-
Sorts the query results.
|
|
701
|
-
|
|
702
|
-
- **`exec(): Promise<SuccessInterface | ErrorInterface>`**
|
|
703
|
-
Executes the query.
|
|
384
|
+
**Ankan Saha**
|
|
704
385
|
|
|
705
386
|
---
|
|
706
387
|
|
|
707
|
-
##
|
|
708
|
-
|
|
709
|
-
AxioDB prioritizes data security with features like:
|
|
388
|
+
## 💖 Support
|
|
710
389
|
|
|
711
|
-
|
|
712
|
-
-
|
|
713
|
-
-
|
|
714
|
-
|
|
390
|
+
If you find AxioDB helpful, consider:
|
|
391
|
+
- ⭐ Starring the repository
|
|
392
|
+
- 🐛 Reporting issues
|
|
393
|
+
- 💡 Suggesting features
|
|
394
|
+
- 🤝 Contributing code
|
|
395
|
+
- 💰 [Sponsoring the project](https://github.com/sponsors/AnkanSaha)
|
|
715
396
|
|
|
716
397
|
---
|
|
717
398
|
|