Skip to content

salarizadi/vertex-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

VertexDB ๐Ÿ’พ

License Version Downloads

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.

Features โœจ

  • ๐Ÿƒโ€โ™‚๏ธ 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

Installation ๐Ÿ“ฆ

NPM

npm install @salarizadi/vertex-db

Yarn

yarn add @salarizadi/vertex-db

Browser

<script src="https://unpkg.com/@salarizadi/vertex-db"></script>

Quick Start ๐Ÿš€

// 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');

Advanced Usage ๐Ÿ”ฅ

Relationships

// Define relationships between tables
db.setRelation('posts', 'users', 'hasOne', 'user_id');

// Join tables
const postsWithUsers = db.join('posts', 'users', 'user_id', 'id');

Transactions

db.transaction((tx) => {
    tx.insert('users', { /* user data */ });
    tx.insert('posts', { /* post data */ });
    // Will rollback if any operation fails
});

Schema Validation

const schema = {
    title: { type: 'string', required: true },
    views: { type: 'number', min: 0 },
    status: { type: 'string', pattern: /^(draft|published)$/ }
};

db.createTable('posts', schema);

Advanced Queries

db.whereOperator('age', '>', 18)
  .whereLike('name', '%John%')
  .whereIn('status', ['active', 'pending'])
  .orderBy('created_at', 'DESC')
  .limit(10)
  .get('users');

Pagination

const result = db.paginate('users', 1, 10);
console.log(result.data); // Current page data
console.log(result.pagination); // Pagination info

API Reference ๐Ÿ“š

Core Methods

  • createTable(tableName, schema?) - Create a new table
  • setTable(tableName, data, schema?) - Set table data with optional schema
  • insert(tableName, data) - Insert a single record
  • update(tableName, data) - Update records matching conditions
  • delete(tableName) - Delete records matching conditions
  • get(tableName) - Get all matching records
  • getOne(tableName) - Get first matching record

Query Methods

  • where(field, value, operator) - Add WHERE condition
  • whereOperator(field, operator, value) - Add WHERE condition with operator
  • whereLike(field, pattern) - Add LIKE condition
  • whereIn(field, values) - Add WHERE IN condition
  • orderBy(column, direction) - Sort results
  • limit(limit, offset) - Limit results
  • paginate(tableName, page, perPage) - Get paginated results

Utilities

  • backup() - Create database backup
  • restore(backup) - Restore from backup
  • toJSON(tableName) - Export table to JSON
  • fromJSON(tableName, jsonData) - Import from JSON
  • getStats() - Get database statistics
  • truncate(tableName) - Clear table data

License ๐Ÿ“„

MIT ยฉ Salar Izadi

Contributing ๐Ÿค

Contributions, issues, and feature requests are welcome! Feel free to check issues page.

Support ๐ŸŒŸ

Give a โญ๏ธ if this project helped you!


Made with โค๏ธ by Salar Izadi

About

A lightweight, high-performance JavaScript/TypeScript database library for modern web applications. Supports in-memory data storage, persistent storage, and real-time data synchronization with flexible query capabilities.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors