@hawiah/core
v1.0.2
Published
Core package for Hawiah - Schema-less database abstraction layer with relationships and DataLoader batching
Downloads
150,135
Readme
@hawiah/core 
Core package for Hawiah - Schema-less database abstraction layer with multiple driver support, relationships, and DataLoader batching.
Note: This is the core package. For the main package, install
hawiahinstead.
Installation
# Install core package only
npm install @hawiah/core
# Or install the main package
npm install hawiahFeatures
- 🚀 Lightweight and fast
- 🔌 Multiple database driver support
- 🔗 Built-in relationships with DataLoader batching
- 📦 Schema-less design
- 🎯 Simple and intuitive API
- 🔄 Automatic N+1 query optimization
- 💾 Memory driver included
Quick Start
import { Hawiah, MemoryDriver } from '@hawiah/core';
const db = new Hawiah({ driver: new MemoryDriver() });API Methods
Basic Operations
insert(data)- Insert a recordinsertMany(dataArray)- Insert multiple recordsget(query, limit?)- Get records matching querygetOne(query)- Get single recordgetAll()- Get all recordsupdate(query, data)- Update recordsremove(query)- Remove recordsclear()- Clear all records
Query Operations
getById(id)- Get record by IDgetBy(field, value)- Get records by field valuehas(query)- Check if records existcount(query)- Count matching recordssort(query, field, direction)- Sort resultsselect(query, fields)- Select specific fieldspaginate(query, page, pageSize)- Paginate results
Array Operations
push(query, field, value)- Add to arraypull(query, field, value)- Remove from arrayshift(query, field)- Remove first elementunshift(query, field, value)- Add to beginningpop(query, field)- Remove last element
Numeric Operations
increment(query, field, amount)- Increment fielddecrement(query, field, amount)- Decrement fieldsum(field, query)- Sum field values
Relationships
// Define relationships
const users = new Hawiah({ driver: new MemoryDriver() });
const posts = new Hawiah({ driver: new MemoryDriver() });
users.relation('posts', posts, '_id', 'userId', 'many');
posts.relation('author', users, 'userId', '_id', 'one');
// Query with relationships
const usersWithPosts = await users.getWith({}, 'posts');Custom Drivers
Implement the IDriver interface to create custom drivers:
import { IDriver, Query, Data } from '@hawiah/core';
class MyDriver implements IDriver {
async connect(): Promise<void> { /* ... */ }
async disconnect(): Promise<void> { /* ... */ }
async get(query: Query): Promise<Data[]> { /* ... */ }
async getOne(query: Query): Promise<Data | null> { /* ... */ }
async set(data: Data): Promise<Data> { /* ... */ }
async update(query: Query, data: Data): Promise<number> { /* ... */ }
async delete(query: Query): Promise<number> { /* ... */ }
async exists(query: Query): Promise<boolean> { /* ... */ }
async count(query: Query): Promise<number> { /* ... */ }
}License
MIT
