_4kb
_4kb
XXata
Created by _4kb on 10/9/2024 in #help
Unable to get query using dynamic table
I want to retrieve data with the filter userId is this.userId. but when I do it with dynamic table name I get an error:
This expression is not callable.
Each member of the union type '{ <F extends FilterColumns<AgentRecord> | JSONFilterColumns<AgentRecord>>(column: F, value: FilterValueAtColumn<AgentRecord, F>): Query<...>; (filter?: BaseApiFilter<...> | ... 1 more ... | undefined): Query<...>; } | { ...; } | { ...; } | { ...; }' has signatures, but none of those signatures are compatible with each other.ts(2349)
This expression is not callable.
Each member of the union type '{ <F extends FilterColumns<AgentRecord> | JSONFilterColumns<AgentRecord>>(column: F, value: FilterValueAtColumn<AgentRecord, F>): Query<...>; (filter?: BaseApiFilter<...> | ... 1 more ... | undefined): Query<...>; } | { ...; } | { ...; } | { ...; }' has signatures, but none of those signatures are compatible with each other.ts(2349)
this is the example code in my case:
import { DatabaseSchema, getXataClient, XataClient } from "../../xata";

class AiDB {
private xata: XataClient;
private userId: string;
private agentName: string;
private table: keyof DatabaseSchema;

constructor(userId: string, agentName: string) {
this.xata = getXataClient();
this.userId = userId;
this.agentName = agentName;
this.table = `${agentName}_AIDB` as keyof DatabaseSchema;
}

public async get() {
return await this.xata.db[this.table].filter({ userId: { $is: this.userId } }).getFirst();
}
}
import { DatabaseSchema, getXataClient, XataClient } from "../../xata";

class AiDB {
private xata: XataClient;
private userId: string;
private agentName: string;
private table: keyof DatabaseSchema;

constructor(userId: string, agentName: string) {
this.xata = getXataClient();
this.userId = userId;
this.agentName = agentName;
this.table = `${agentName}_AIDB` as keyof DatabaseSchema;
}

public async get() {
return await this.xata.db[this.table].filter({ userId: { $is: this.userId } }).getFirst();
}
}
10 replies