Skip to content

Commit a95c116

Browse files
Refactor: Use generated Prisma client and SQLite adapter
This commit updates the project to use a generated Prisma client and the better-sqlite3 adapter for improved performance and type safety. It also includes changes to the user search functionality and WebAuthn registration. Co-authored-by: me <[email protected]>
1 parent 962a480 commit a95c116

File tree

14 files changed

+416
-21
lines changed

14 files changed

+416
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ node_modules
2525

2626
# generated files
2727
/app/components/ui/icons
28+
/app/utils/prisma-generated.server
2829
.react-router/

app/routes/_auth+/webauthn+/registration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function action({ request }: Route.ActionArgs) {
110110
data: {
111111
id: credential.id,
112112
aaguid,
113-
publicKey: Buffer.from(credential.publicKey),
113+
publicKey: new Uint8Array(credential.publicKey),
114114
userId,
115115
webauthnUserId,
116116
counter: credential.counter,

app/routes/users+/index.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { searchUsers } from '@prisma/client/sql'
21
import { Img } from 'openimg/react'
32
import { redirect, Link } from 'react-router'
43
import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
@@ -14,8 +13,20 @@ export async function loader({ request }: Route.LoaderArgs) {
1413
return redirect('/users')
1514
}
1615

17-
const like = `%${searchTerm ?? ''}%`
18-
const users = await prisma.$queryRawTyped(searchUsers(like))
16+
const users = await prisma.user.findMany({
17+
where: {
18+
OR: [
19+
{ name: { contains: searchTerm ?? '' } },
20+
{ username: { contains: searchTerm ?? '' } },
21+
],
22+
},
23+
select: {
24+
id: true,
25+
name: true,
26+
username: true,
27+
image: { select: { objectKey: true } },
28+
},
29+
})
1930
return { status: 'idle', users } as const
2031
}
2132

@@ -49,7 +60,7 @@ export default function UsersRoute({ loaderData }: Route.ComponentProps) {
4960
>
5061
<Img
5162
alt={user.name ?? user.username}
52-
src={getUserImgSrc(user.imageObjectKey)}
63+
src={getUserImgSrc(user.image?.objectKey)}
5364
className="size-16 rounded-full"
5465
width={256}
5566
height={256}

app/utils/auth.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import crypto from 'node:crypto'
2-
import { type Connection, type Password, type User } from '@prisma/client'
2+
import { type Connection, type Password, type User } from '#app/utils/prisma-generated.server'
33
import bcrypt from 'bcryptjs'
44
import { redirect } from 'react-router'
55
import { Authenticator } from 'remix-auth'

app/utils/db.server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { styleText } from 'node:util'
22
import { remember } from '@epic-web/remember'
3-
// Changed import due to issue: https://github.com/remix-run/react-router/pull/12644
4-
import { PrismaClient } from '@prisma/client/index.js'
3+
import * as PrismaClientModule from '#app/utils/prisma-generated.server/index.js'
4+
const { PrismaClient } = PrismaClientModule
55

66
export const prisma = remember('prisma', () => {
77
// NOTE: if you change anything in this function you'll need to restart
@@ -14,6 +14,7 @@ export const prisma = remember('prisma', () => {
1414
log: [
1515
{ level: 'query', emit: 'event' },
1616
{ level: 'error', emit: 'stdout' },
17+
{ level: 'info', emit: 'stdout' },
1718
{ level: 'warn', emit: 'stdout' },
1819
],
1920
})

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export default [
99
rules: { 'react-hooks/rules-of-hooks': 'off' },
1010
},
1111
{
12-
ignores: ['.react-router/*'],
12+
ignores: ['.react-router/*', './app/utils/prisma-generated.server'],
1313
},
1414
]

0 commit comments

Comments
 (0)