Registry / database / eden-db

eden-db

JSON →
library0.0.2jsnpmunverified

Eden DB is a Firebase-style PostgreSQL wrapper for Node.js and TypeScript that provides zero-config collections with auto-migration, transactions, and type-safe queries. Current version is 0.0.2, released as an early alpha. It differentiates from traditional ORMs like Sequelize or TypeORM by offering a simpler, document-like interface similar to Firestore, while using PostgreSQL as the backend. The library automatically creates tables on first use, supports raw SQL queries, and includes migration support. Note: version 0.0.2 is pre-stable and may have breaking changes.

npm install eden-db
INSTALL
IMPORT
SIG · EDEN-DB
E
eden-db
databasejavascriptv0.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

db
✓ import { db } from 'eden-db'
✗ const eden = require('eden-db')
The package uses named exports; default import is not available. Also, using require() with destructuring may cause issues in ESM contexts.
runMigrations
✓ import { runMigrations } from 'eden-db'
✗ import runMigrations from 'eden-db'
runMigrations is a named export, not default. Also ensure you have a valid pool instance passed as first argument.
QueryOptions
✓ import type { QueryOptions } from 'eden-db'
✗ import { QueryOptions } from 'eden-db'
QueryOptions is a type (interface), so use 'import type' in TypeScript to avoid runtime errors. The package ships TypeScript types.

Demonstrates basic CRUD operations: connect, insert, find, findById, query with filters, count, update, and delete.

import { db } from 'eden-db'; import 'dotenv/config'; async function main() { // Connect (auto-creates tables on first use) await db.connect({ url: process.env.DATABASE_URL ?? '' }); // Insert a user const user = await db.collection('users').insert({ name: 'Alice', email: 'alice@example.com', role: 'admin', }); console.log('Inserted:', user); // Find all users const users = await db.collection('users').find(); console.log('All users:', users); // Find user by ID const found = await db.collection('users').findById(user.id); console.log('Found:', found); // Query with filters const admins = await db.collection('users').find({ where: { role: 'admin' }, orderBy: { field: 'createdAt', direction: 'desc' }, limit: 10, }); console.log('Admins:', admins); // Count const count = await db.collection('users').count({ role: 'admin' }); console.log('Count:', count); // Update await db.collection('users').update(user.id, { name: 'Alice Smith' }); // Delete await db.collection('users').delete(user.id); } main().catch(console.error);
Debug
Known issues
breakingAuto-migration creates tables on insert without schema validation, which may cause unexpected column types or conflicts with existing tables.
fix
Review the generated schema in your database after first insert and consider using explicit migrations via runMigrations().
affects: >=0.0.1
breakingThe .collection() method returns a collection object that uses a table name inferred from the collection name (e.g., 'users' maps to 'users' table). If the table already exists with a different schema, insert may fail.
fix
Ensure table names match your schema or use raw SQL for custom tables.
affects: >=0.0.1
gotchaTransactions require passing a client object explicitly to each collection method inside the transaction callback; forgetting leads to operations running outside the transaction.
fix
Always pass the client parameter to collection methods inside transactions: db.collection('users').insert(data, client)
affects: >=0.0.1
deprecatedNo deprecated APIs known as version 0.0.2 is early stage.
fix
None.
affects: <0.0.1
gotchaThe .count() method accepts a where object but does not support advanced operators like $gt or $in; only exact equality.
fix
For complex counts, use raw SQL via db.query().
affects: >=0.0.1
breakingThe package uses ESM modules. Using require() in CommonJS projects will fail unless using dynamic import().
fix
Use ES module syntax or set "type": "module" in package.json.
affects: >=0.0.1
gotchaAuto-migration runs on every insert, which may cause performance issues on high-traffic inserts.
fix
Pre-create tables via SQL or use runMigrations() once during startup to avoid repeated schema checks.
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module 'eden-db' or its corresponding type declarations.
Module not installed or TypeScript can't find types.
fix
Run 'npm install eden-db pg' and ensure 'node_modules' is present. For TypeScript, ensure 'skipLibCheck' is false or add 'eden-db' to 'types' in tsconfig.json.
Property 'connect' does not exist on type 'typeof import("eden-db")'.
Using default import instead of named import.
fix
Use named import: import { db } from 'eden-db'
error: relation "users" does not exist
Auto-migration didn't run because insert was called before connect or table was not created.
fix
Ensure 'await db.connect()' is called before any collection operations. The table is created on first insert; if you need pre-creation, run a manual migration.
client is not defined
Using transactional method without passing client parameter.
fix
Inside db.transaction callback, use db.collection('users').insert(data, client) where client is the argument of the callback.
Cannot use import statement outside a module
Package uses ESM, but project is CommonJS.
fix
Set "type": "module" in package.json or use dynamic import: const { db } = await import('eden-db');
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
pgrequiredpg is a peer dependency used for PostgreSQL connection and query execution.
Agent activity
8 hits · last 30 days
node
8
Resources
eden-db — npm install eden-db · libregistry