Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template(db): Update api/src/lib/db template #11379

Merged
merged 4 commits into from
Aug 28, 2024
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
29 changes: 29 additions & 0 deletions .changesets/11379.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- template(db): Update `api/src/lib/db` template (#11379) by @dac09

Updates the template in `api/src/lib/db.{js,ts}` to export `db` differently.

In your existing projects, you can make the following changes:

```diff

import { PrismaClient } from '@prisma/client'

import { emitLogLevels, handlePrismaLogging } from '@redwoodjs/api/logger'

import { logger } from './logger'
import { prismaExtension } from './uploads'

- export const db = new PrismaClient({
+ const prismaClient = new PrismaClient({
log: emitLogLevels(['info', 'warn', 'error']),
})

handlePrismaLogging({
- db
+ db: prismaClient,
logger,
logLevels: ['info', 'warn', 'error'],
})

+ export const db = prismaClient
```
15 changes: 10 additions & 5 deletions __fixtures__/test-project/api/src/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import { emitLogLevels, handlePrismaLogging } from '@redwoodjs/api/logger'

import { logger } from './logger'

/*
* Instance of the Prisma Client
*/
export const db = new PrismaClient({
const prismaClient = new PrismaClient({
log: emitLogLevels(['info', 'warn', 'error']),
})

handlePrismaLogging({
db,
db: prismaClient,
logger,
logLevels: ['info', 'warn', 'error'],
})

/**
* Global Prisma client extensions should be added here, as $extend
* returns a new instance.
* export const db = prismaClient.$extend(...)
* Add any .$on hooks before using $extend
*/
export const db = prismaClient
15 changes: 10 additions & 5 deletions packages/create-redwood-app/templates/js/api/src/lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import { emitLogLevels, handlePrismaLogging } from '@redwoodjs/api/logger'

import { logger } from './logger'

/*
* Instance of the Prisma Client
*/
export const db = new PrismaClient({
const prismaClient = new PrismaClient({
log: emitLogLevels(['info', 'warn', 'error']),
})

handlePrismaLogging({
db,
db: prismaClient,
logger,
logLevels: ['info', 'warn', 'error'],
})

/**
* Global Prisma client extensions should be added here, as $extend
* returns a new instance.
* export const db = prismaClient.$extend(...)
* Add any .$on hooks before using $extend
*/
export const db = prismaClient
15 changes: 10 additions & 5 deletions packages/create-redwood-app/templates/ts/api/src/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import { emitLogLevels, handlePrismaLogging } from '@redwoodjs/api/logger'

import { logger } from './logger'

/*
* Instance of the Prisma Client
*/
export const db = new PrismaClient({
const prismaClient = new PrismaClient({
log: emitLogLevels(['info', 'warn', 'error']),
})

handlePrismaLogging({
db,
db: prismaClient,
logger,
logLevels: ['info', 'warn', 'error'],
})

/**
* Global Prisma client extensions should be added here, as $extend
* returns a new instance.
* export const db = prismaClient.$extend(...)
* Add any .$on hooks before using $extend
*/
export const db = prismaClient
Loading