@warlock.js/cascade
v4.1.15
Published
ORM for managing databases
Maintainers
Readme
cascade
A powerful, model-first TypeScript ORM for MongoDB and PostgreSQL on Node.js.
Features
Cascade is a unified ORM for MongoDB and PostgreSQL — one model-first API runs against both engines. Define a model once (its @warlock.js/seal schema doubles as the TypeScript type, the runtime validator, and the DB shape) and query straight off the class. It's fast, type-safe, and built for real-world apps.
Some but not all of the features:
- Easy to use:
Cascadeis very easy to use, it's just a wrapper around MongoDB driver. - Supports multiple connections: You can perform multiple connections to different MongoDB connections and use each one of them separately.
- Supports multiple databases:
Cascadesupports multiple databases, you can connect to multiple databases at the same time. - Powerful Aggregate framework:
Cascadehas a powerful aggregate framework that helps you to perform complex queries. - Basic CRUD operations:
Cascadesupports basic CRUD operations, you can perform create, read, update and delete operations. - Events Driven:
Cascadeis events driven, you can listen to events and perform actions, for example before creating, updating or deleting a document. - Powerful Models:
Cascadehas a powerful models system, a Model is a collection manager document based, it manages a collection's document easily with many utilities. - Learning curve:
Cascadehas a very small learning curve, you can learn it in few minutes. - Pagination support:
Cascadesupports pagination, you can paginate your results easily. - Output formatting:
Cascadesupports output formatting, you can format your output easily when model is sent as a response. - Auto incremented id:
Cascadesupports auto incremented id, you can use it as a primary key for your documents. - Random or sequential id:
Cascadesupports random or sequential id. - Recycle Bin: Reduce collection documents by removing the document entirely from the collection, but move it to a separate collection trash.
- Migration system:
Cascadehas a migration system, you can create migrations and run them easily. - Data casting: You can cast your data to a specific type or using custom casting.
- Embedded documents:
Cascadesupports single and multiple embedded documents, you can embed documents inside other documents. - Syncing Models: Auto update documents when model's data is updated or deleted.
Installation
npm i @warlock.js/cascadeUsing yarn:
yarn add @warlock.js/cascadeUsing pnpm:
pnpm add @warlock.js/cascadePeek inside cascade
Here is a simple example of defining a User model:
import { Model, RegisterModel } from "@warlock.js/cascade";
@RegisterModel()
export class User extends Model {
/**
* The table / collection name.
* Must be defined explicitly.
*/
public static table = "users";
}A quick example of creating a user:
import { User } from "src/models/user";
export async function createUser() {
const user = await User.create({
name: "Hasan Zohdy",
email: "[email protected]",
});
console.log(user.data);
}Outputs something similar to:
{
"id": 1231412,
"_id": "fagtrw43qwedasjoijwq",
"name": "Hasan Zohdy",
"email": "[email protected]",
"createdAt": "2023-06-01 00:00:00",
"updatedAt": "2023-06-01 00:00:00"
}Documentation
To see the full documentation, please visit Cascade Documentation
