Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/components/Navigation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const currentPageMatch = currentPage.endsWith('/')
<li>
<a
href={link.link}
class={`flex gap-1 border-l pl-3 ${
class={`flex gap-2 items-start border-l pl-3 ${
currentPageMatch === link.link
? 'border-current text-violet-500 dark:text-violet-400'
: 'border-transparent text-gray-700 hover:border-current hover:border-gray-500 dark:text-gray-300 dark:hover:border-gray-400'
Expand Down
10 changes: 10 additions & 0 deletions docs/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export const navigation: Navigation[] = [
title: 'Prisma Client Extensions',
link: '/docs/prisma-client-extensions',
},
{
title: 'Rust-free and Driver Adapters',
link: '/docs/rust-free-and-driver-adapter',
badge: 'New',
},
{
title: 'Query Logging Extension',
link: '/docs/query-logging-extension',
Expand Down Expand Up @@ -100,6 +105,11 @@ export const examples: Example[] = [
description: 'NestJS app with Express, Prisma and nestjs-prisma.',
link: 'https://github.com/notiz-dev/nestjs-prisma/tree/main/examples/basics',
},
{
name: 'Rust-free and driver adapter',
description: 'NestJS app with prisma-client (Rust-free), driver adapter and nestjs-prisma.',
link: 'https://github.com/notiz-dev/nestjs-prisma/tree/main/examples/driver',
},
{
name: 'Fastify',
description: 'NestJS app with Fastify, Prisma and nestjs-prisma.',
Expand Down
150 changes: 150 additions & 0 deletions docs/src/content/docs/rust-free-and-driver-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
title: Rust-free and driver adapter
---

> Rust-free Prisma Client is Generally Available with [v6.16.0](https://github.com/prisma/prisma/releases/tag/6.16.0).

Learn how to use the new `prisma-client` provider with a custom output path and adapter driver. For more information see the [No Rust engine](https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/no-rust-engine) guide on Prisma docs.

Make sure you have `prisma` and `@prisma/client` v6.16.0 or later installed.

## Configure Rust-free Prisma Client

Configure your Prisma schema to use the new `prisma-client` provider and set a output directory. You can include the output directory in git, because it doesn't contain the rust query engine binary.

```prisma
// prisma/schema.prisma
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
engineType = "client"
runtime = "nodejs"
moduleFormat = "cjs"
}

datasource db {
provider = "sqlite"
url = "file:dev.db"
}
```

Read more about additional [fields](https://www.prisma.io/docs/orm/reference/prisma-schema-reference#fields-for-prisma-client-provider) for the `prisma-client` provider.

Add your models to the `schema.prisma`, run `npx prisma generate` and run the prisma migration `npx prisma migrate dev`.

### Prisma config (optional)

Add at the root level the `prisma.config.ts` to [configure](https://www.prisma.io/docs/orm/reference/prisma-config-reference) the Prisma CLI for commands like `migrate`, `seed`.

```ts
// prisma.config.ts
import path from 'node:path';
import { defineConfig } from 'prisma/config';

export default defineConfig({
schema: path.join('prisma', 'schema.prisma'),
migrations: {
path: './prisma/migrations',
seed: 'tsx ./prisma/seed.ts',
},
});
```

### Install driver adapter

You need to [install a driver adapter](https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/no-rust-engine#3-install-the-driver-adapter) depending on your database.

For the example, use install the driver adatper for SQLite.

```bash
npm install @prisma/adapter-better-sqlite3
```

### Prisma Client instance

Now create a `PrismaClient` instance from your custom output and configure the driver adapter.

```ts
// src/prisma.extension.ts
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3';
import { PrismaClient } from './generated/prisma/client';

const adapter = new PrismaBetterSQLite3({ url: 'file:./prisma/dev.db' });
export const prisma = new PrismaClient({ adapter });

export type PrismaClientType = typeof prisma;
```

You can also use `process.env.DATABASE_URL` for setting the url in the adapter.

### Seed database

Add `seed.ts` in your prisma directory and reuse the prisma client instance for seeding your development environment.

```ts
// prisma/seed.ts
// reuse the prisma client instance
import { prisma } from '../src/prisma.extension';

async function main() {
console.log('Seeding database...');
console.time('Seeding complete 🌱');

// TODO seed development data

console.timeEnd('Seeding complete 🌱');
}

main().catch((e) => console.log(e));
```

## Use Rust-free Prisma Client

Register your `prisma` instance with the `CustomPrismaModule`.

```ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CustomPrismaModule } from 'nestjs-prisma/dist/custom';
import { prisma } from './prisma.extension';

@Module({
imports: [
CustomPrismaModule.forRootAsync({
name: 'PrismaService',
useFactory: () => {
return prisma;
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
```

Query your database by injecting `CustomPrismaService` with your `PrismaClientType`. You have full access to the Prisma Client with `this.prismaService.client`.

```ts
import { Inject, Injectable } from '@nestjs/common';
import { CustomPrismaService } from 'nestjs-prisma/dist/custom';
import { PrismaClientType } from './prisma.extension';

@Injectable()
export class AppService {
constructor(
// ✅ use `ExtendedPrismaClient` from extension for correct type-safety
@Inject('PrismaService')
private prismaService: CustomPrismaService<PrismaClientType>,
) {}

users() {
return this.prismaService.client.user.findMany();
}
}
```

## Example

Checkout the [Rust-free and driver adapter](https://github.com/notiz-dev/nestjs-prisma/blob/main/examples/extensions/src/query-logging.extension.ts) example on GitHub.
59 changes: 59 additions & 0 deletions examples/driver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# prisma
prisma/dev.db*
4 changes: 4 additions & 0 deletions examples/driver/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
98 changes: 98 additions & 0 deletions examples/driver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Project setup

```bash
$ npm install
```

## Compile and run the project

```bash
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod
```

## Run tests

```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```

## Deployment

When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.

If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:

```bash
$ npm install -g @nestjs/mau
$ mau deploy
```

With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.

## Resources

Check out a few resources that may come in handy when working with NestJS:

- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
34 changes: 34 additions & 0 deletions examples/driver/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: ['eslint.config.mjs'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
sourceType: 'commonjs',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn'
},
},
);
8 changes: 8 additions & 0 deletions examples/driver/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
Loading