@better-auth/prisma-adapter 1.7.0-beta.5 → 1.7.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +51 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -299,7 +299,7 @@ const prismaAdapter = (prisma, config) => {
|
|
|
299
299
|
await db[model].delete({ where: whereClause });
|
|
300
300
|
} catch (e) {
|
|
301
301
|
if (isPrismaNotFoundError(e)) return;
|
|
302
|
-
|
|
302
|
+
throw e;
|
|
303
303
|
}
|
|
304
304
|
},
|
|
305
305
|
async deleteMany({ model, where }) {
|
|
@@ -353,6 +353,56 @@ const prismaAdapter = (prisma, config) => {
|
|
|
353
353
|
};
|
|
354
354
|
return inTransaction || typeof db.$transaction !== "function" ? claimFromTransaction(db) : db.$transaction(claimFromTransaction);
|
|
355
355
|
},
|
|
356
|
+
async incrementOne({ model, where, increment, set }) {
|
|
357
|
+
if (!db[model]) throw new BetterAuthError(`Model ${model} does not exist in the database. If you haven't generated the Prisma client, you need to run 'npx prisma generate'`);
|
|
358
|
+
const data = { ...set ?? {} };
|
|
359
|
+
for (const [field, delta] of Object.entries(increment)) data[field] = { increment: delta };
|
|
360
|
+
if (where?.some((w) => w.field === "id")) {
|
|
361
|
+
const whereClause = convertWhereClause({
|
|
362
|
+
model,
|
|
363
|
+
where,
|
|
364
|
+
action: "update"
|
|
365
|
+
});
|
|
366
|
+
try {
|
|
367
|
+
return await db[model].update({
|
|
368
|
+
where: whereClause,
|
|
369
|
+
data
|
|
370
|
+
}) ?? null;
|
|
371
|
+
} catch (e) {
|
|
372
|
+
if (isPrismaNotFoundError(e)) return null;
|
|
373
|
+
throw e;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const findWhere = convertWhereClause({
|
|
377
|
+
model,
|
|
378
|
+
where,
|
|
379
|
+
action: "findOne"
|
|
380
|
+
});
|
|
381
|
+
const mutateInTransaction = async (tx) => {
|
|
382
|
+
const target = await tx[model].findFirst({ where: findWhere });
|
|
383
|
+
if (!target) return null;
|
|
384
|
+
try {
|
|
385
|
+
return await tx[model].update({
|
|
386
|
+
where: convertWhereClause({
|
|
387
|
+
model,
|
|
388
|
+
where: [...where, {
|
|
389
|
+
field: "id",
|
|
390
|
+
value: target.id,
|
|
391
|
+
operator: "eq",
|
|
392
|
+
connector: "AND",
|
|
393
|
+
mode: "sensitive"
|
|
394
|
+
}],
|
|
395
|
+
action: "update"
|
|
396
|
+
}),
|
|
397
|
+
data
|
|
398
|
+
}) ?? null;
|
|
399
|
+
} catch (e) {
|
|
400
|
+
if (isPrismaNotFoundError(e)) return null;
|
|
401
|
+
throw e;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
return inTransaction || typeof db.$transaction !== "function" ? mutateInTransaction(db) : db.$transaction(mutateInTransaction);
|
|
405
|
+
},
|
|
356
406
|
options: config
|
|
357
407
|
};
|
|
358
408
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/prisma-adapter",
|
|
3
|
-
"version": "1.7.0-beta.
|
|
3
|
+
"version": "1.7.0-beta.6",
|
|
4
4
|
"description": "Prisma adapter for Better Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@better-auth/utils": "0.4.
|
|
38
|
+
"@better-auth/utils": "0.4.2",
|
|
39
39
|
"@prisma/client": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
40
40
|
"prisma": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
41
|
-
"@better-auth/core": "^1.7.0-beta.
|
|
41
|
+
"@better-auth/core": "^1.7.0-beta.6"
|
|
42
42
|
},
|
|
43
43
|
"peerDependenciesMeta": {
|
|
44
44
|
"@prisma/client": {
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@better-auth/utils": "0.4.
|
|
52
|
+
"@better-auth/utils": "0.4.2",
|
|
53
53
|
"tsdown": "0.21.1",
|
|
54
54
|
"typescript": "^5.9.3",
|
|
55
|
-
"@better-auth/core": "1.7.0-beta.
|
|
55
|
+
"@better-auth/core": "1.7.0-beta.6"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsdown",
|