edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Positional arguments in queries generator

Open MrFoxPro opened this issue 2 years ago • 0 comments

When creating query like this:

insert OtpPhoneRequest {
   phone := <str>$0,
   otp := <int32>$1,
   sentAt := <datetime>$2
};

Generated query will be:

export type InsertOtpRequestArgs = {
  "0": string;
  "1": number;  
  "2": Date;
};

export type InsertOtpRequestReturns = {
  "id": string;
};

export async function insertOtpRequest(client: Executor, args: InsertOtpRequestArgs): Promise<InsertOtpRequestReturns> {
  return client.queryRequiredSingle(`\
insert OtpPhoneRequest {
   phone := <str>$0,
   otp := <int32>$1,
   sentAt := <datetime>$2
};`, args);

But I execpect it should be like this:

export type InsertOtpRequestArgs = [string, number, Date]

export type InsertOtpRequestReturns = {
   id: string
}

export async function insertOtpRequest(
   client: Executor,
   ...args: InsertOtpRequestArgs
): Promise<InsertOtpRequestReturns> {
   return client.queryRequiredSingle(
      `\
insert OtpPhoneRequest {
   phone := <str>$0,
   otp := <int32>$1,
   sentAt := <datetime>$2
};`,
      ...args
   )
}

MrFoxPro avatar Oct 20 '23 07:10 MrFoxPro