fix: support neq filters in local postgres client

This commit is contained in:
Jesse_Chen
2026-07-27 12:50:16 +08:00
parent dc1aa9e239
commit 80b25f8ec5
2 changed files with 14 additions and 1 deletions
@@ -12,6 +12,7 @@ type QueryResult = Readonly<{
type Filter =
| Readonly<{ kind: "eq"; column: string; value: unknown }>
| Readonly<{ kind: "neq"; column: string; value: unknown }>
| Readonly<{ kind: "in"; column: string; value: readonly unknown[] }>
| Readonly<{ kind: "is"; column: string; value: unknown }>
| Readonly<{ kind: "notContains"; column: string; value: unknown }>;
@@ -169,6 +170,12 @@ class LocalPostgresQueryBuilder implements PromiseLike<QueryResult> {
return this;
}
neq(column: string, value: unknown) {
identifier(column);
this.filters.push({ kind: "neq", column, value });
return this;
}
in(column: string, value: readonly unknown[]) {
identifier(column);
this.filters.push({ kind: "in", column, value });
@@ -250,7 +257,7 @@ class LocalPostgresQueryBuilder implements PromiseLike<QueryResult> {
return `not (${column} @> $${parameters.length})`;
}
parameters.push(databaseValue(types.get(filter.column), filter.value));
return `${column} = $${parameters.length}`;
return `${column} ${filter.kind === "neq" ? "<>" : "="} $${parameters.length}`;
});
return ` where ${parts.join(" and ")}`;
}
@@ -150,6 +150,12 @@ test("local PostgreSQL applies the reviewed business schema and serves authentic
email: "local-user@example.com",
credits: 0,
});
const nonAbandonedProfiles = await local.from("profiles")
.select("id")
.neq("email", "not-local-user@example.com")
.single();
assert.equal(nonAbandonedProfiles.error, null);
assert.deepEqual(nonAbandonedProfiles.data, { id: userId });
const admin = createLocalPostgresDataClient(
fixture.connectionUrl("admin_runtime", "admin-runtime-test-password"),
null,