bookshelf
Bookshelf is a JavaScript ORM for Node.js built on top of the Knex.js query builder, providing an Active Record-like interface for working with relational datab…
Installation
npm install bookshelf knex
yarn add bookshelf knex
pnpm add bookshelf knex
Import
import Bookshelf from 'bookshelf';
Quick Example
import Knex from 'knex';
import Bookshelf from 'bookshelf';
const knex = Knex({ client: 'pg', connection: process.env.DATABASE_URL });
const bookshelf = Bookshelf(knex);
const User = bookshelf.model('User', { tableName: 'users' });
const user = await User.forge({ name: 'Alice' }).save();About bookshelf
Bookshelf is a JavaScript ORM for Node.js built on top of the Knex.js query builder, providing an Active Record-like interface for working with relational databases. Bookshelf supports PostgreSQL, MySQL, MariaDB, and SQLite through Knex's multi-dialect support. The library provides model definitions with relations (hasOne, hasMany, belongsTo, belongsToMany through junction tables), eager loading to prevent N+1 query problems, virtual attributes for computed properties, and lifecycle events (creating, saving, updating, destroying) for model hooks. Bookshelf's API is inspired by Backbone.js models, providing fetch(), save(), destroy(), and forge() methods on model instances. The library supports pagination through the bookshelf-page plugin, soft deletes through bookshelf-paranoia, and case conversion through bookshelf-case-converter. While newer ORMs like Prisma and Drizzle offer better TypeScript support and developer experience, Bookshelf remains in use in existing codebases where its Knex foundation provides a familiar and well-understood query building layer. Bookshelf is particularly suitable for applications that need a simple Active Record pattern with the flexibility to drop down to Knex's query builder for complex queries.
Quick Facts
| Package | bookshelf |
| Category | Database |
| Weekly Downloads | 50K+ |
| License | MIT |
| Install | npm install bookshelf knex |
Related Packages
Knex.js is a batteries-included SQL query builder for Node.js that supports PostgreSQL, MySQL, Maria…
Objection.js is an SQL-friendly ORM for Node.js built on Knex.js that provides a powerful relation m…
Sequelize is a promise-based Node.js ORM that supports PostgreSQL, MySQL, MariaDB, SQLite, and Micro…
Prisma is a next-generation Node.js and TypeScript ORM that provides a declarative data modeling lan…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.