npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prutotech-universal-db-layer

v1.0.1

Published

Cross-platform unified database layer with auto-environment detection and Prisma-like API

Downloads

7

Readme

Unified DB Layer

npm version License: MIT Build Status Coverage Status

A cross-platform unified database layer that automatically detects your runtime environment and uses the appropriate storage backend with a familiar Prisma-like API.

✨ Features

  • 🌍 Cross-platform: Works seamlessly in Browser, Node.js, Electron, and React Native
  • 🔍 Auto-detection: Automatically selects the best storage backend for your environment
  • 📊 Prisma-like API: Familiar and intuitive database operations with method chaining
  • 📴 Offline-first: No network dependencies, works entirely offline
  • Zero-config: Works out of the box with sensible defaults
  • 🎯 TypeScript: Full type support included
  • 🔒 Data validation: Built-in validation with custom rules
  • 🪝 Hooks system: Extensible middleware for custom logic
  • 📦 Lightweight: Minimal bundle size with tree-shaking support
  • 🔄 Import/Export: Easy data backup and migration

🚀 Quick Start

Installation

npm install universal-db-layer

For React Native projects, also install:

npm install @react-native-async-storage/async-storage

Basic Usage

import { UnifiedDB } from "universal-db-layer";

// Define your data models
const db = new UnifiedDB({
  models: {
    User: {
      fields: {
        id: { type: "string", primaryKey: true },
        name: { type: "string", required: true },
        email: { type: "string", required: true },
        age: { type: "number", default: 0 },
        createdAt: { type: "date", default: "now" },
      },
    },
    Post: {
      fields: {
        id: { type: "string", primaryKey: true },
        title: { type: "string", required: true },
        content: { type: "string", required: true },
        authorId: { type: "string", required: true },
        published: { type: "boolean", default: false },
      },
    },
  },
});

// Initialize the database
await db.init();

// Use the Prisma-like API
const user = await db.user.create({
  name: "John Doe",
  email: "[email protected]",
  age: 30,
});

const users = await db.user.findMany({
  where: { age: { gte: 18 } },
  orderBy: { name: "asc" },
  take: 10,
});

const post = await db.post.create({
  title: "Hello World",
  content: "This is my first post!",
  authorId: user.id,
  published: true,
});

🌐 Platform Support

| Platform | Storage Backend | Capacity | Persistence | | ---------------- | ----------------------- | ------------------ | ----------------- | | Browser | IndexedDB (preferred) | ~50MB+ | Until cleared | | Browser | localStorage (fallback) | ~5-10MB | Until cleared | | Node.js | File System | Disk space | Permanent | | Electron | File System | Disk space | Permanent | | React Native | AsyncStorage | Platform dependent | Until uninstalled |

The library automatically detects your environment and chooses the best available storage backend.

📚 Documentation

🎯 Use Cases

  • Offline-first applications - Work without internet connectivity
  • Cross-platform development - Same API across web, mobile, and desktop
  • Rapid prototyping - Quick setup without external database dependencies
  • Local data caching - Store API responses and user preferences
  • Development and testing - Mock databases for testing environments

🔧 Advanced Features

Query Builder

// Complex queries with method chaining
const results = await db.user
  .where("age", ">", 18)
  .where("email", "contains", "@company.com")
  .orderBy("createdAt", "desc")
  .limit(50)
  .findMany();

Hooks and Middleware

// Add custom logic to database operations
db.addHook("beforeCreate", (modelName, data) => {
  data.createdBy = getCurrentUserId();
  return data;
});

db.addHook("afterUpdate", (modelName, data) => {
  console.log(`Updated ${modelName}:`, data.id);
});

Data Import/Export

// Backup your data
const backup = await db.export();

// Restore from backup
await db.import(backup, { clearFirst: true });

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/yourusername/universal-db-layer.git
cd universal-db-layer

# Install dependencies
npm install

# Run tests
npm test

# Build the package
npm run build

# Run linting
npm run lint

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

📋 Requirements

  • Node.js: >= 14.0.0
  • Browsers: Modern browsers with ES2018+ support
  • React Native: >= 0.60.0 (with AsyncStorage)

🐛 Issues and Support

📈 Roadmap

  • [ ] Relationships: Support for model relationships and joins
  • [ ] Migrations: Automatic schema migrations
  • [ ] Encryption: Built-in data encryption support
  • [ ] Sync: Cloud synchronization capabilities
  • [ ] Plugins: Plugin system for custom storage backends
  • [ ] Performance: Query optimization and indexing

🏆 Acknowledgments

  • Inspired by Prisma for the API design
  • Built with Rollup for optimal bundling
  • Tested with Jest for reliability

📄 License

MIT © Your Name