Skip to content

Commit 4785e26

Browse files
Refactor: Use Prisma's typedSql and LibSQL adapter
This commit updates the project to use Prisma's typedSql feature for more type-safe SQL queries. It also integrates the LibSQL adapter, enabling the use of LibSQL as the database. This includes changes to Prisma schema, route loaders, and dependency management. Co-authored-by: me <[email protected]>
1 parent a95c116 commit 4785e26

File tree

13 files changed

+338
-44
lines changed

13 files changed

+338
-44
lines changed

app/routes/users+/index.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
44
import { ErrorList } from '#app/components/forms.tsx'
55
import { SearchBar } from '#app/components/search-bar.tsx'
66
import { prisma } from '#app/utils/db.server.ts'
7+
import { searchUsers } from '#app/utils/prisma-generated.server/sql/searchUsers.ts'
78
import { cn, getUserImgSrc, useDelayedIsPending } from '#app/utils/misc.tsx'
89
import { type Route } from './+types/index.ts'
910

@@ -13,20 +14,7 @@ export async function loader({ request }: Route.LoaderArgs) {
1314
return redirect('/users')
1415
}
1516

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-
})
17+
const users = await prisma.$queryRawTyped(searchUsers(`%${searchTerm ?? ''}%`))
3018
return { status: 'idle', users } as const
3119
}
3220

@@ -60,7 +48,7 @@ export default function UsersRoute({ loaderData }: Route.ComponentProps) {
6048
>
6149
<Img
6250
alt={user.name ?? user.username}
63-
src={getUserImgSrc(user.image?.objectKey)}
51+
src={getUserImgSrc(user.imageObjectKey)}
6452
className="size-16 rounded-full"
6553
width={256}
6654
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 '#app/utils/prisma-generated.server'
2+
import { type Connection, type Password, type User } from '#app/utils/prisma-generated.server/client.ts'
33
import bcrypt from 'bcryptjs'
44
import { redirect } from 'react-router'
55
import { Authenticator } from 'remix-auth'

app/utils/db.server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { styleText } from 'node:util'
22
import { remember } from '@epic-web/remember'
3-
import * as PrismaClientModule from '#app/utils/prisma-generated.server/index.js'
4-
const { PrismaClient } = PrismaClientModule
3+
import { PrismaClient } from '#app/utils/prisma-generated.server/client.ts'
54

65
export const prisma = remember('prisma', () => {
76
// NOTE: if you change anything in this function you'll need to restart

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/*', './app/utils/prisma-generated.server'],
12+
ignores: ['.react-router/*', './app/utils/prisma-generated.server/**'],
1313
},
1414
]

0 commit comments

Comments
 (0)