AxarDB Documentation
High-performance NoSQL database server powered by a JavaScript-based query language
AxarDB is a NoSQL database server that works with JavaScript-based queries using the Jint JavaScript engine. It runs on ASP.NET Core 8.0.
Core Features
📦 Collection Based
MongoDB-like structure. Automatic creation.
🔍 JavaScript Query
Data processing with native JS syntax.
⚡ High Performance
Lazy evaluation via PLINQ and strictly capped 40% RAM cache usage.
📄 CSV Engine
Convert lists of objects to CSV, or parse raw CSV strings instantly.
📊 Index Support
Performance with ASC/DESC sorting.
🔗 Join Operations
Joining multiple collections.
👁️ Views
Server-side stored queries.
⚡ Triggers
Automated scripts that respond automatically.
Data Reading
The db object is the entry point for all database operations.
// Find a single record (returns the first match)
var user = db.users.find(u => u.age > 18);
// List all matches (convert to array with toList())
var admins = db.users.findall(u => u.role == 'admin').toList();
// Get the entire collection
var allUsers = db.users.findall().toList();
// Get the first record
var first = db.users.findall().first();
// Record count
var count = db.users.findall().count();
var adults = db.users.findall().count(u => u.age > 18);
// Distinct unique values
var roles = db.users.findall().distinct(u => u.role).toList();
// Case-insensitive search
var devs = db.users.contains(x => x.title == "developer");
findall() returns a ResultSet. To use it as an array,
.toList() must be called.
Data Writing
insert
db.users.insert({
name: "Ahmet",
age: 25,
role: "developer"
});
update
// Update records that match the condition
db.users.update(u => u.name == "Ahmet", { age: 26 });
// Update via ResultSet
db.users.findall(u => u.inactive).update({ status: "archived" });
delete
// Delete Documents (Filtered)
db.users.findall(u => u.inactive == true).delete();
// Delete Entire Collection (RAM + Disk)
db.users.delete();
db.deleteCollection("users");
foreach
db.users.findall().foreach(user => {
console.log(user.name);
});
Join Operations
// Recommended: Join with Aliases
var result = db.join(
alias(db.users, "u"),
alias(db.orders, "o")
)
.where(x => x.u._id == x.o.userId).toList();
// Default: Join with indexed properties (j1, j2...)
var data = db.join(db.products, db.categories).select(x => ({
name: x.j1.productName,
category: x.j2.categoryName
}));
Creating Index
// ASC (default)
db.users.index(x => x.email);
// DESC sorting
db.users.index(x => x.createdAt, "DESC");
// Chaining
db.users.insert({...}).index(x => x.name);
Views
Views are reusable queries stored on the server side in the Views/ folder.
Public View (Accessible to Everyone)
// Accessible via HTTP GET /views/activeUsers (No Auth required)
db.saveView("activeUsers", `
// @access public
return db.users.findall(u => u.active == true).toList();
`);
Private View (Internal Use Only)
// Can only be called with db.view(), not accessible from HTTP
db.saveView("internalReport", `
// @access private
return db.orders.findall(o => o.status == "pending").toList();
`);
View Usage
// Call internally
var result = db.view("activeUsers");
// Get view code
var code = db.getView("activeUsers");
// Access via HTTP (only public views)
// GET /views/activeUsers
•
// @access public → Accessible from outside via HTTP GET•
// @access private → Can only be used internally via db.view()
Triggers
Triggers are asynchronous scripts that run automatically by monitoring file changes in the
Data/ folder. They are stored in the Triggers/ folder.
Creating a Trigger
// saveTrigger(triggerName, targetCollection, scriptCode)
db.saveTrigger("userNotifier", "users", `
// @target users
console.log("User changed: " + event.documentId);
webhook("https://api.example.com/notify",
{ id: event.documentId, type: event.type },
{ "Authorization": "Bearer " + $API_TOKEN }
);
`);
@target Metadata
Determines which collection the trigger will react to changes in:
// Monitor changes only in the "orders" collection
// @target orders
// Monitor multiple collections
// @target users,orders,products
Event Object
event.type // "changed" | "created" | "deleted"
event.collection // Name of the changed collection
event.documentId // _id value of the changed document
event.timestamp // Server time (ISO format)
Event Types
- created - When a new document is added
- changed - When an existing document is updated
- deleted - When a document is deleted
trigger_logs/
folder.
Vaults (Secure Storage)
Secure key-value store in the sysvaults collection for API keys and constants.
// Add value to Vault
addVault("API_KEY", "sk-xxxx...");
addVault("SLACK_WEBHOOK", "https://hooks.slack.com/...");
// Use as $Key in queries
webhook($SLACK_WEBHOOK, { text: "Notification!" }, {});
Webhooks
The webhook(url, data, headers) function is used to send HTTP POST requests to external
services.
Basic Usage
// Simple webhook (without headers)
webhook("https://api.example.com/notify", {
message: "New record added",
timestamp: new Date().toISOString()
}, {});
Usage with Headers
// With Bearer Token
webhook("https://api.example.com/data",
{ userId: 123, action: "update" },
{
"Authorization": "Bearer " + $API_TOKEN,
"Content-Type": "application/json"
}
);
// With API Key
webhook("https://api.stripe.com/v1/charges",
{ amount: 1000, currency: "usd" },
{ "X-API-Key": $STRIPE_KEY }
);
// Slack Webhook
webhook($SLACK_WEBHOOK,
{ text: "New order received!" },
{ "Content-Type": "application/json" }
);
External Databases
AxarDB can execute queries on external MySQL/MariaDB and PostgreSQL databases.
MySQL / MariaDB
var conn = "Server=localhost;Database=test;Uid=root;Pwd=pass;";
// Read data
var users = mysqlRead(conn, "SELECT * FROM users WHERE age > @age", { age: 18 });
// Execute command
var count = mysqlExec(conn, "UPDATE users SET active = 1 WHERE id = @id", { id: 5 });
PostgreSQL
var conn = "Host=localhost;Database=db;Username=pg;Password=pass";
// Read data
var data = pgsqlRead(conn, "SELECT * FROM public.logs WHERE type = @t", { t: 'error' });
// Execute command
var affected = pgsqlExec(conn, "DELETE FROM public.logs WHERE id = @id", { id: 10 });
Queue Operations
Schedule long-running tasks for background execution using queue().
// Simple background job
var jobId = queue("db.logs.insert({msg: 'Background task', time: guid()})");
// Job with parameters and priority
var highPriJob = queue(
"db.users.update(u => u.id == @id, { active: true })",
{ id: 123 },
{ priority: 1 }
);
HTTP API
| Endpoint | Method | Description | Auth |
|---|---|---|---|
/query |
POST | Execute JavaScript query | ✓ |
/collections |
GET | List collections | ✓ |
/collections/{name} |
DELETE | Delete collection (RAM + Disk) | ✓ |
/views/{name} |
GET | Run public view | @access |
/views/{name} |
DELETE | Delete view | ✓ |
/triggers/{name} |
DELETE | Delete trigger | ✓ |
Query Parameters
// POST /query?userName=John&userAge=30
db.users.insert({
name: @userName,
age: parseInt(@userAge)
});
Security
- Basic Authentication: Required for /query and /collections
- Default User:
unlocker / unlocker - Password Hashing: Supports both plain text and SHA256 hashed passwords in the
sysuserscollection. - Injection Protection: @param placeholders are securely bound
- Malicious Code Check: eval, Function are blocked
eval(, Function(,
script in parameters are rejected.
Utility Functions
// Create unique ID (UUID)
var id = guid();
// Write log to console (server console and logs/)
console.log("Message");
// Send webhook (url, data, headers)
webhook("https://api.example.com/hook",
{ data: "value" },
{ "Authorization": "Bearer token" }
);
// Add value to Vault
addVault("KEY_NAME", "value");
// List existing collections
var cols = showCollections();
// Create SHA256 hash
var hash = sha256("password");
// Create random string
var token = randomString(32);
// Parse CSV or Generate CSV
var parsed = csv("id,name\n1,john");
var strOut = csv([{id: 1, name: "john"}]);
// Deep copy object
var copy = deepcopy(original);
// HTTP GET request
var res = httpGet("https://api.example.com", { "Auth": "..." });
// OpenAI compatible LLM Client
var ai = openai(url, token);
// AES Encryption / Decryption
var secret = encrypt("hello", "salt");
var plain = decrypt(secret, "salt");
// Hash functions (MD5)
var m = md5("test");
// Date manipulation
var nextWeek = addDays(new Date(), 7);
var later = addMinutes(new Date(), 15);
var hourLater = addHours(new Date(), 1);
// Converters
var b64 = toBase64("text");
var txt = fromBase64(b64);
var num = toDecimal("10.5");
var json = toJson({a: 1});
// Randoms
var n = randomNumber(1, 100);
var d = randomDecimal(0, 1);