Skip to content

Commit 5b23fba

Browse files
committed
fix(set): fix "Cannot target a non-object." error
1 parent 97e2a08 commit 5b23fba

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/methods/set.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export default async (db: Client, params: Params, options: Options) => {
2727
if (typeof fetched === "object" && params.ops.target) {
2828
params.data = JSON.parse(params.data);
2929
params.data = set(fetched, params.ops.target, params.data);
30-
} else throw new TypeError("Cannot target a non-object.");
30+
} else if (params.ops.target)
31+
throw new TypeError("Cannot target a non-object.");
3132

3233
// Stringify data
3334
if (typeof params.data != "string") params.data = JSON.stringify(params.data);

tests/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ db.on("end", () => console.log("ℹ️ Database connection ended"));
3838

3939
console.time("Time to test (excludes connection & end)");
4040

41+
await db.set("userInfo", { difficulty: "Easy" });
42+
4143
await db.set("users.0", {
4244
username: "Zero",
4345
email: "zero@quickpostgres.com",

0 commit comments

Comments
 (0)