A lightweight, powerful in-memory database for JavaScript/TypeScript applications with support for multiple data structures, relationships, transactions, and schema validation. Perfect for both browser and Node.js environments.
- 🏃♂️ Lightweight and blazing fast in-memory operations
- 📊 Table-based data structure with relationships
- 🔒 Schema validation and type checking
- 🕒 Automatic timestamps
- 🗑️ Soft delete capability
- 📝 Transaction support with rollback
- 🔍 Advanced querying with multiple conditions
- 📈 Indexing for faster searches
- 🔄 Import/Export JSON functionality
- 📱 Browser and Node.js compatibility
- 🧮 Aggregation functions (count, avg, sum, min, max)
- 📄 Pagination support
- 🎯 Custom raw queries
npm install @salarizadi/vertex-db
yarn add @salarizadi/vertex-db
<script src="https://unpkg.com/@salarizadi/vertex-db"></script>
// Initialize VertexDB
const db = new VertexDB({
logging: true,
timestamps: true,
softDelete: true
});
// Create a table with schema
const userSchema = {
id: { type: 'number', required: true },
name: { type: 'string', required: true },
email: { type: 'string', required: true, pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/ },
age: { type: 'number', min: 18, max: 100 }
};
// Insert data
db.insert('users', {
id: VertexDB.AUTO_INCREMENT,
name: 'John Doe',
email: 'john@example.com',
age: 20
});
// Query data
const users = db.where('name', 'John Doe').get('users');
// Define relationships between tables
db.setRelation('posts', 'users', 'hasOne', 'user_id');
// Join tables
const postsWithUsers = db.join('posts', 'users', 'user_id', 'id');
db.transaction((tx) => {
tx.insert('users', { /* user data */ });
tx.insert('posts', { /* post data */ });
// Will rollback if any operation fails
});
const schema = {
title: { type: 'string', required: true },
views: { type: 'number', min: 0 },
status: { type: 'string', pattern: /^(draft|published)$/ }
};
db.createTable('posts', schema);
db.whereOperator('age', '>', 18)
.whereLike('name', '%John%')
.whereIn('status', ['active', 'pending'])
.orderBy('created_at', 'DESC')
.limit(10)
.get('users');
const result = db.paginate('users', 1, 10);
console.log(result.data); // Current page data
console.log(result.pagination); // Pagination info
createTable(tableName, schema?)
- Create a new tablesetTable(tableName, data, schema?)
- Set table data with optional schemainsert(tableName, data)
- Insert a single recordupdate(tableName, data)
- Update records matching conditionsdelete(tableName)
- Delete records matching conditionsget(tableName)
- Get all matching recordsgetOne(tableName)
- Get first matching record
where(field, value, operator)
- Add WHERE conditionwhereOperator(field, operator, value)
- Add WHERE condition with operatorwhereLike(field, pattern)
- Add LIKE conditionwhereIn(field, values)
- Add WHERE IN conditionorderBy(column, direction)
- Sort resultslimit(limit, offset)
- Limit resultspaginate(tableName, page, perPage)
- Get paginated results
backup()
- Create database backuprestore(backup)
- Restore from backuptoJSON(tableName)
- Export table to JSONfromJSON(tableName, jsonData)
- Import from JSONgetStats()
- Get database statisticstruncate(tableName)
- Clear table data
MIT © Salar Izadi
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
Give a ⭐️ if this project helped you!
Made with ❤️ by Salar Izadi