{"id":19435405,"url":"https://github.com/nestjsplus/massive","last_synced_at":"2025-04-24T21:30:30.664Z","repository":{"id":35099406,"uuid":"206669870","full_name":"nestjsplus/massive","owner":"nestjsplus","description":"A Module for Utilizing MassiveJS with NestJS","archived":false,"fork":false,"pushed_at":"2023-01-24T00:39:14.000Z","size":565,"stargazers_count":65,"open_issues_count":16,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-11T00:39:11.254Z","etag":null,"topics":["javascript","massive","nestjs","postgresql","sql","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nestjsplus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-05T22:49:13.000Z","updated_at":"2024-02-22T17:51:16.000Z","dependencies_parsed_at":"2023-02-13T05:30:54.381Z","dependency_job_id":null,"html_url":"https://github.com/nestjsplus/massive","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsplus%2Fmassive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsplus%2Fmassive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsplus%2Fmassive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsplus%2Fmassive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nestjsplus","download_url":"https://codeload.github.com/nestjsplus/massive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223965805,"owners_count":17233077,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","massive","nestjs","postgresql","sql","typescript"],"created_at":"2024-11-10T15:06:11.807Z","updated_at":"2024-11-10T15:06:12.517Z","avatar_url":"https://github.com/nestjsplus.png","language":"TypeScript","readme":"\u003ch1 align=\"center\"\u003e\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://nestjs.com/img/logo_text.svg\" width=\"150\" alt=\"Nest Logo\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003ch3 align=\"center\"\u003eA Module for Utilizing MassiveJS with NestJS\u003c/h3\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://nestjs.com\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg\" alt=\"License\" /\u003e\n    \u003cimg src=\"https://badge.fury.io/js/%40nestjsplus%2Fmassive.svg\" alt=\"npm version\" height=\"18\"\u003e    \u003cimg src=\"https://img.shields.io/badge/built%20with-NestJs-red.svg\" alt=\"Built with NestJS\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n### Installation\n\n\u003e npm install @nestjsplus/massive\n\n(or yarn equivalent)\n\n### About Massive and PostgreSQL\n\nThis module is a thin layer on top of the [MassiveJS library](https://massivejs.org/).\n\nAs an [old database guy](#ingres), I sometimes feel like the **OR/M** days passed me by :smiley:\n\nIn truth, I find the OR/M model and the _pure SQl_ model to just define opposite ends of a spectrum, and I'm happy to live somewhere in the middle. _Massive_ provides a very happy middle ground. Looked at one way, it introspects your database and provides an automatic API to it in a way that seems similar to a MongoDB type API. You can get quite far with `save()`, `find()`, etc. methods that are similar to MongoDB in many ways, but **do not require a model**. As Dian Fay, author of Massive says, _\"Massive analyzes and builds an API for the data model expressed in your database's tables, views, and functions\"_.\n\nMassive is also **PostgreSQL only**. If you don't care about database portability (I'm firmly attached to PostgreSQL, and would have to change a lot more than a DB API library to move), this is a big boon. Because it doesn't sacrifice at the alter of \"portability\", Massive takes significant advantage of native PostgreSQL functionality.\n\nIt has a nice query builder, but doesn't obscure SQL, and let's you get right down to the metal easily.\n\nIt fully supports database functions. It even lets you write parameterized SQL files on the file system and call them just like procedures (one of my favorite features, and an underrated one at that, as it gets SQL out of your TypeScript, lets you manage the SQL script files nicely in your git repo just like the rest of your app, and it makes it dead easy to avoid SQL injection).\n\nOn top of all that, it has full `JSONB` support, meaning you get to treat your PostgreSQL database like a full-fledged NoSQL database, storing JSON objects natively. You can store them alongside your relational data, query them with API calls or native SQL (with JSONB support), or mix-and-match.\n\n### Quick Start\n\nTo configure your DB connection, import the `Massive` module using the familiar `register()` / `registerAsync()` pattern. See the [example repo](https://github.com/nestjsplus/massive-cats) for an example. Basically, you configure the module with at least a `connectionOptions` object, and optionally a `configurationOptions` object and `driverOptions` object. These options objects map directly to the connection, configuration, and driver options [in the Massive docs](https://massivejs.org/docs/connecting).\n\nOnce configured, inject the `SINGLETON` connection object into any service using the `MASSIVE_CONNECTION` injection token.\n\nFor example, your `AppModule` might look like this (full example in the [sample repo](https://github.com/nestjsplus/massive-cats)):\n\n```typescript\n// src/app.module.ts\nimport { Module } from '@nestjs/common';\nimport { AppController } from './app.controller';\nimport { AppService } from './app.service';\nimport { ConfigModule } from './config/config.module';\nimport { ConfigService } from './config/config.service';\nimport { MassiveModule } from '@nestjsplus/massive';\n\n@Module({\n  imports: [\n    MassiveModule.registerAsync({\n      useClass: ConfigService,\n    }),\n    ConfigModule,\n  ],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule {}\n```\n\nNow you have access to a `MASSIVE_CONNECTION` token that is associated with the PostgreSQL connection pool, which you can inject into any provider, and use directly. For example, you might do this:\n\n```typescript\n// src/app.service.ts\nimport { Inject, Injectable } from '@nestjs/common';\nimport { MASSIVE_CONNECTION } from '@nestjsplus/massive';\n\n@Injectable()\nexport class AppService {\n  constructor(@Inject(MASSIVE_CONNECTION) private readonly db) {}\n\n  async find(age) {\n    const criteria = age ? { 'age \u003e=': age } : {};\n    return await this.db.cats.find(criteria);\n  }\n  ...\n```\n\nHere, you've injected the connection as a local property of the service class, and can access any of the MassiveJS API through that property (e.g., `return await this.db.cats.find(criteria)`, where `db` represents your MassiveJS connection object).\n\n### Configuring `connectionOptions`\n\nI'm not showing the `ConfigService` in the `AppModule` above, but it's just an _injectable_ that implements the `MassiveOptionsFactory` interface, meaning it has methods to return a `connectionOptions` object (and optionally, `configurationOptions` and `driverOptions` objects). A `connectionOptions` object looks like:\n\n```json\n{\n  \"host\": \"localhost\",\n  \"port\": 5432,\n  \"database\": \"nest\",\n  \"user\": \"john\",\n  \"password\": \"password\"\n}\n```\n\nYou can use any of the following methods to provide the `connectionOptions` (and optionally `configurationOptions` and `driverOptions`) to the module. These follow the [usual patterns for custom providers](https://docs.nestjs.com/fundamentals/custom-providers):\n\n- `register()`: pass a plain JavaScript object\n- `registerAsync()`: pass a dynamic object via:\n  - `useFactory`: supply a factory function to return the object; the factory should implement the [MassiveOptionsFactory](https://github.com/nestjsplus/massive/blob/master/src/interfaces/massive-options-factory.interface.ts) interface\n  - `useClass`: bind to a provider/service that supplies the object; that service should implement the [MassiveOptionsFactory](https://github.com/nestjsplus/massive/blob/master/src/interfaces/massive-options-factory.interface.ts) interface\n  - `useExisting`: bind to an existing (provided elsewhere) provider/service to supply the object; that service should implement the [MassiveOptionsFactory](https://github.com/nestjsplus/massive/blob/master/src/interfaces/massive-options-factory.interface.ts) interface\n\n### Connection availability on application startup\n\nThe `MASSIVE_CONNECTION` is an [asynchronous provider](https://docs.nestjs.com/fundamentals/async-providers). This means that the Nest application bootstrap process (specifically, the Dependency Injection phase) won't complete until the DB connection is made. So your app, once it bootstraps, is guaranteed to have a DB connection (pool) via the `MASSIVE_CONNECTION` injection token. Note that asynchronous providers must be injected with the `@Inject()` decorator instead of normal constructor injection (again, see the [example](https://github.com/nestjsplus/massive-cat)).\n\n### Working Example\n\nSee [massive-cats](https://github.com/nestjsplus/massive-cats) for a full example. It shows an example of using the `MASSIVE_CONNECTION`, a service that uses it to access a PostgreSQL database, and includes a few of the nifty Massive features described above.\n\n### Ingres\n\nBoring end-notes here! My long love affair with SQL databases began when I started working for Ingres Corp., provider of the [Ingres](\u003chttps://en.wikipedia.org/wiki/Ingres_(database)\u003e) database commercial product. It had a long prior history as a university research project. Amazingly, while it had a relatively short-lived commercial life-span (solid ass-kicking by Oracle, which (to this day, I maintain) had inferior technology but superior sales and marketing), it was reborn again as an open source project - (**Post** In**gres**) - [PostgreSQL](https://www.postgresql.org/). From what I can gather, PostgreSQL is widely regarded as the leading open source RDBMS, and by my accounts, for good reason. Among its many virtues:\n\n- It's free! :smiley:\n- It's fast and scalable\n- It's supported on Amazon RDS\n- It's got every modern SQL feature, and many, many more (check out [Postgis](https://postgis.net/) if you are into mapping/GIS, for example)\n- It supports JSONB and is a very good NoSQL database\n- It has a super passionate community, and support on StackOverflow is superb\n- I could go on, but I won't :smile:\n\n### To Do\n\n- [ ] Tests\n- [x] Implement the [driver configuration](https://massivejs.org/docs/connecting#driver-configuration) option\n\n### Change Log\n\nSee [Changelog](CHANGELOG.md) for more information.\n\n### Contributing\n\nContributions welcome! See [Contributing](CONTRIBUTING.md).\n\n### Author\n\n**John Biundo (Y Prospect on [Discord](https://discord.gg/G7Qnnhy))**\n\n### License\n\nLicensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestjsplus%2Fmassive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnestjsplus%2Fmassive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestjsplus%2Fmassive/lists"}