Skip to content

hawiahjs/hawiah

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


hawiah
NPM Downloads npm Version License


Modular database abstraction with virtual relationships. Support for 7 drivers, 50+ methods, and DataLoader batching. One API to rule them all.

✨ Features

  • Universal API - Same code works with any database
  • Multiple Drivers - JSON, YAML, SQLite, MongoDB, Firebase, PostgreSQL, MySQL
  • Runtime Agnostic - Works with Node.js, Bun, and Deno
  • Virtual Relationships - Define relations between any collections, even across different databases!
  • Hybrid Schema - Blends SQL tables with NoSQL flexibility (Real columns + JSON)
  • DataLoader Optimization - Automatic query batching and caching eliminates N+1 problems
  • Extensible - Create custom drivers for any data source
  • Schema-less / Schema-full - You choose: Strict validation or total freedom
  • TypeScript Ready - Full type definitions included

πŸ“¦ Installation

# Core package (required)
npm install hawiah
# or
bun add hawiah
# or
deno install npm:hawiah

# Choose one or more drivers
npm install @hawiah/local      # JSON & YAML
npm install @hawiah/sqlite     # SQLite
npm install @hawiah/mongo      # MongoDB
npm install @hawiah/firebase   # Firebase Firestore
npm install @hawiah/postgres   # PostgreSQL
npm install @hawiah/mysql      # MySQL

Works with:

  • βœ… Node.js
  • βœ… Bun
  • βœ… Deno

πŸš€ Quick Start

import { Hawiah } from 'hawiah';
import { MongoDriver } from '@hawiah/mongo';

const db = new Hawiah({
  driver: new MongoDriver({
    uri: 'mongodb://localhost:27017',
    databaseName: 'myapp',
    collectionName: 'users'
  })
});

await db.connect();
await db.insert({ id: 1, name: 'John', age: 25 });
const users = await db.get({});
await db.disconnect();

Switch to SQLite or Firebase? Just change the driver. Your code stays the same.

🧬 The Hybrid Schema System

Hawiah v1.1 introduces a game-changing Hybrid Schema capabilities.

Virtual vs. Real Schemas

How Hawiah handles your schema depends on the driver:

Feature SQL Drivers (Postgres, SQLite, MySQL) NoSQL Drivers (Mongo, Firebase, Local)
Logic Real Schema (Physical columns) Virtual Schema (Validator)
Storage Columns for defined fields + JSON for extras. Full JSON Document.
Benefit Native SQL performance & indexing. Maximum flexibility & speed.

Schema Definition

import { Schema, DataTypes } from '@hawiah/core';

const userSchema = new Schema({
  // Basic Types
  username: { type: DataTypes.STRING, required: true },
  age:      { type: DataTypes.INTEGER, min: 18 },
  
  // Advanced Types
  email:    { type: DataTypes.EMAIL, unique: true },
  tags:     { type: DataTypes.ARRAY },
  
  // Default Values
  isActive: { type: DataTypes.BOOLEAN, default: true },
  created:  { type: DataTypes.DATE, default: () => new Date() }
});

πŸ”— Virtual Relationships - The Game Changer

Define relationships between collections without foreign keys or schema changes. Works across different databases!

import { Hawiah } from 'hawiah';
import { MongoDriver } from '@hawiah/mongo';
import { SQLiteDriver } from '@hawiah/sqlite';

// Users in MongoDB
const users = new Hawiah({
  driver: new MongoDriver({
    uri: 'mongodb://localhost:27017',
    databaseName: 'myapp',
    collectionName: 'users'
  })
});

// Posts in SQLite
const posts = new Hawiah({
  driver: new SQLiteDriver('./blog.db', 'posts')
});

// Define virtual relationship - MongoDB ↔ SQLite!
users.relation('posts', posts, '_id', 'userId', 'many');
posts.relation('author', users, 'userId', '_id', 'one');

await users.connect();
await posts.connect();

// Query with relationships - automatically optimized!
const usersWithPosts = await users.getWith({}, 'posts');
// Each user includes their posts from SQLite - no N+1 queries!

const postsWithAuthors = await posts.getWith({}, 'author');
// Each post includes author from MongoDB - fully batched!

Why Virtual Relationships are Powerful:

✨ Cross-Database Relations - Connect MongoDB users with SQLite posts, or any combination
⚑ Zero N+1 Problems - DataLoader automatically batches and caches all queries
πŸš€ No Schema Changes - No foreign keys, no migrations, just pure flexibility
🎯 Type-Safe - Full TypeScript support with proper typing
πŸ”„ Nested Relations - Load relations of relations infinitely
πŸ’ͺ Production Ready - Battle-tested optimization used by GraphQL servers worldwide

πŸ—„οΈ Available Drivers

Driver Package Use Case
JSON @hawiah/local Development, Testing
YAML @hawiah/local Configuration
SQLite @hawiah/sqlite Desktop/Mobile Apps
MongoDB @hawiah/mongo Web/Cloud Apps
Firebase @hawiah/firebase Real-time Apps
PostgreSQL @hawiah/postgres Enterprise Apps
MySQL @hawiah/mysql Web Apps
Custom - Any Data Source

πŸ“š API Overview

Basic Operations: insert, insertMany, get, getOne, getById, update, updateById, remove, removeById, clear

Virtual Relationships:

  • relation(name, targetCollection, localKey, foreignKey, type) - Define virtual relation
  • getWith(query, relations) - Load data with relations (auto-optimized with DataLoader)

Advanced: sort, paginate, select, count, sum, group, unique

Arrays: push, pull, shift, unshift, pop

Fields: increment, decrement, unset, rename

πŸ“– Documentation

For detailed documentation, driver examples, relationships guide, and custom driver tutorials:

πŸ“š Full Documentation

πŸ”— Links

πŸ“¦ GitHub Repositories

Core & Documentation

Database Drivers

πŸ“„ License

MIT Β© Shuruhatik

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors