Top Related Projects
ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, MS SQL Server, PostgreSQL and SQLite/libSQL databases.
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js
Quick Overview
nestjsx/crud is a powerful CRUD (Create, Read, Update, Delete) module for NestJS, a progressive Node.js framework. It provides a set of tools and decorators to quickly generate RESTful APIs with minimal boilerplate code, supporting various database types and offering advanced querying capabilities.
Pros
- Rapid API development with minimal code
- Highly customizable and extensible
- Supports multiple databases (TypeORM, Mongoose, Sequelize)
- Advanced querying features (filtering, sorting, pagination)
Cons
- Learning curve for developers new to NestJS
- May introduce unnecessary complexity for simple projects
- Limited flexibility in some edge cases
- Potential performance overhead for large-scale applications
Code Examples
- Basic CRUD controller:
@Crud({
model: {
type: User,
},
})
@Controller('users')
export class UsersController {
constructor(public service: UsersService) {}
}
This code creates a full CRUD controller for the User entity with minimal code.
- Custom endpoints with @Override decorator:
@Override('getOneBase')
getOne(@ParsedRequest() req: CrudRequest) {
return this.base.getOneBase(req);
}
This example shows how to override a base CRUD method to add custom logic.
- Advanced query parameters:
GET /users?filter=firstName||$cont||john&sort=lastName,ASC&page=1&limit=10
This URL demonstrates the advanced querying capabilities, including filtering, sorting, and pagination.
Getting Started
- Install the required packages:
npm i @nestjsx/crud @nestjsx/crud-typeorm @nestjs/typeorm typeorm class-transformer class-validator
- Create an entity:
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
}
- Create a service:
@Injectable()
export class UsersService extends TypeOrmCrudService<User> {
constructor(@InjectRepository(User) repo) {
super(repo);
}
}
- Create a controller:
@Crud({
model: {
type: User,
},
})
@Controller('users')
export class UsersController {
constructor(public service: UsersService) {}
}
- Add the controller and service to your module:
@Module({
imports: [TypeOrmModule.forFeature([User])],
controllers: [UsersController],
providers: [UsersService],
})
export class UsersModule {}
Competitor Comparisons
ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Pros of TypeORM
- More comprehensive ORM solution with support for multiple databases
- Offers advanced features like migrations, relations, and caching
- Larger community and ecosystem with extensive documentation
Cons of TypeORM
- Steeper learning curve due to its extensive feature set
- Can be overkill for simple CRUD operations
- May require more setup and configuration
Code Comparison
TypeORM:
@Entity()
class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
}
CRUD:
@Crud({
model: {
type: User
}
})
@Controller('users')
export class UsersController {
constructor(public service: UsersService) {}
}
TypeORM focuses on defining entities and their relationships, while CRUD simplifies controller creation for basic CRUD operations. TypeORM provides more flexibility and control over database interactions, whereas CRUD offers a higher-level abstraction for rapid API development.
TypeORM is better suited for complex database operations and projects requiring fine-grained control over data models. CRUD excels in quickly setting up RESTful APIs with minimal boilerplate code, making it ideal for simpler applications or prototypes.
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
Pros of Prisma
- More powerful and flexible ORM with advanced features like migrations and type-safe database access
- Better performance and scalability for large-scale applications
- Supports multiple databases (PostgreSQL, MySQL, SQLite, and more)
Cons of Prisma
- Steeper learning curve, especially for developers new to ORMs
- Requires more setup and configuration compared to CRUD's simpler approach
- Less seamless integration with NestJS out of the box
Code Comparison
Prisma:
const user = await prisma.user.create({
data: {
name: 'Alice',
email: 'alice@example.com',
},
})
CRUD:
@Crud({
model: {
type: User,
},
})
@Controller('users')
export class UsersController {
constructor(public service: UsersService) {}
}
Prisma offers a more programmatic approach to database operations, while CRUD provides a declarative way to generate CRUD endpoints in NestJS. Prisma's code is more flexible and allows for complex queries, whereas CRUD simplifies the process of creating basic CRUD operations with minimal code.
Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.
Pros of Sequelize
- More mature and widely adopted ORM with extensive documentation
- Supports multiple databases (MySQL, PostgreSQL, SQLite, etc.)
- Offers advanced features like migrations, associations, and transactions
Cons of Sequelize
- Steeper learning curve due to its comprehensive feature set
- Can be overkill for simple CRUD operations
- Performance overhead for complex queries and large datasets
Code Comparison
Sequelize:
const User = sequelize.define('User', {
name: DataTypes.STRING,
email: DataTypes.STRING
});
const users = await User.findAll();
CRUD:
@Crud({
model: { type: UserEntity }
})
@Controller('users')
export class UsersController {
constructor(public service: UsersService) {}
}
Key Differences
- Sequelize is a full-featured ORM, while CRUD is focused on generating RESTful APIs
- CRUD is specifically designed for NestJS, whereas Sequelize can be used with various frameworks
- Sequelize requires more manual setup for models and queries, while CRUD automates CRUD operations
Use Cases
- Choose Sequelize for complex database operations and when working with multiple database types
- Opt for CRUD when building NestJS applications with simple data models and standard CRUD endpoints
Community and Ecosystem
- Sequelize has a larger community and more third-party integrations
- CRUD is tailored for the NestJS ecosystem and benefits from its growing popularity
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, MS SQL Server, PostgreSQL and SQLite/libSQL databases.
Pros of mikro-orm
- More comprehensive ORM solution with advanced features like identity map, unit of work, and lazy loading
- Better TypeScript support with decorators and type inference
- Supports multiple database engines (SQL and NoSQL)
Cons of mikro-orm
- Steeper learning curve due to more complex API and concepts
- May be overkill for simple CRUD operations
- Requires more setup and configuration compared to simpler solutions
Code Comparison
mikro-orm:
@Entity()
class Book {
@PrimaryKey()
id!: number;
@Property()
title!: string;
}
const book = orm.em.create(Book, { title: 'My Book' });
await orm.em.persistAndFlush(book);
crud:
@Crud({
model: {
type: Book,
},
})
@Controller('books')
export class BooksController {
constructor(public service: BooksService) {}
}
While mikro-orm provides a full-featured ORM with advanced capabilities, crud focuses on simplifying CRUD operations in NestJS applications. mikro-orm offers more control over database interactions and supports complex data models, but crud excels in quickly setting up basic CRUD endpoints with minimal configuration. The choice between the two depends on the project's complexity and specific requirements.
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
Pros of Knex
- More flexible and database-agnostic, supporting multiple SQL databases
- Provides a powerful query builder for complex SQL operations
- Mature and widely adopted in the Node.js ecosystem
Cons of Knex
- Requires more manual setup and configuration for CRUD operations
- Less opinionated, which may lead to inconsistent code patterns across projects
- Lacks built-in TypeScript support (though types are available)
Code Comparison
Knex query example:
knex('users')
.where('id', 1)
.update({ name: 'John Doe' })
CRUD query example:
@Injectable()
export class UsersService extends TypeOrmCrudService<User> {
constructor(@InjectRepository(User) repo) {
super(repo);
}
}
Summary
Knex is a flexible SQL query builder that supports multiple databases, offering more control over database operations. It's well-suited for projects requiring complex queries and database-agnostic code.
CRUD, on the other hand, provides a higher-level abstraction for CRUD operations in NestJS applications, offering a more opinionated and streamlined approach. It's ideal for rapid development of RESTful APIs with TypeScript support out of the box.
Choose Knex for greater flexibility and control over database operations, or CRUD for faster development of standardized CRUD endpoints in NestJS applications.
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js
Pros of Bookshelf
- More mature and established ORM with a larger community and ecosystem
- Supports multiple database systems, including PostgreSQL, MySQL, and SQLite
- Provides a flexible and powerful query builder for complex database operations
Cons of Bookshelf
- Less integrated with modern TypeScript-based frameworks like NestJS
- Requires more manual setup and configuration compared to CRUD's automatic CRUD operations
- May have a steeper learning curve for developers new to ORMs
Code Comparison
Bookshelf:
const User = bookshelf.Model.extend({
tableName: 'users',
posts() {
return this.hasMany(Post);
}
});
CRUD:
@Crud({
model: { type: UserEntity },
query: { join: { posts: {} } }
})
@Controller('users')
export class UsersController {
constructor(public service: UsersService) {}
}
The Bookshelf example shows a model definition with a relationship, while the CRUD example demonstrates how to create a full CRUD controller with minimal code. CRUD's approach is more declarative and requires less boilerplate, especially when working within the NestJS ecosystem.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
:point_right:You can help NestJs CRUD
CRUD
We believe that everyone who's working with NestJs and building some RESTful services and especially some CRUD functionality will find @nestjsx/crud
microframework very useful.
Features
-
:electric_plug: Super easy to install and start using the full-featured controllers and services :point_right:
-
:octopus: DB and service agnostic extendable CRUD controllers
-
:mag_right: Reach query parsing with filtering, pagination, sorting, relations, nested relations, cache, etc.
-
:telescope: Framework agnostic package with query builder for a frontend usage
-
:space_invader: Query, path params and DTOs validation included
-
:clapper: Overriding controller methods with ease
-
:wrench: Tiny config (including globally)
-
:gift: Additional helper decorators
-
:pencil2: Swagger documentation
Packages
- @nestjsx/crud - core package which provides
@Crud()
decorator for endpoints generation, global configuration, validation, helper decorators (docs) - @nestjsx/crud-request - request builder/parser package which provides
RequestQueryBuilder
class for a frontend usage andRequestQueryParser
that is being used internally for handling and validating query/path params on a backend side (docs) - @nestjsx/crud-typeorm - TypeORM package which provides base
TypeOrmCrudService
with methods for CRUD database operations (docs)
Documentation
- :dart: General Information
- :video_game: CRUD Controllers
- :horse_racing: CRUD ORM Services
- :trumpet: Handling Requests
Support
Any support is welcome. At least you can give us a star :star:
Contributors
Code Contributors
This project exists thanks to all the people who contribute. [Contribute].
Financial Contributors
Become a financial contributor and help us sustain our community. [Contribute]
Individuals
Organizations
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
License
Top Related Projects
ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, MS SQL Server, PostgreSQL and SQLite/libSQL databases.
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot