fix: support neq filters in local postgres client
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user