Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing buffer values to sql produces invalid queries #86

Closed
vecerek opened this issue Sep 4, 2023 · 0 comments · Fixed by #87
Closed

Passing buffer values to sql produces invalid queries #86

vecerek opened this issue Sep 4, 2023 · 0 comments · Fixed by #87

Comments

@vecerek
Copy link
Contributor

vecerek commented Sep 4, 2023

Given:

const Args = Schema.struct({
  accountId: Schema.number,
  // ULIDFromBuffer: Schema.Schema<Buffer, ULID>
  ids: Schema.array(ULIDFromBuffer),
});

export type Args = Schema.To<typeof Args>;

export const query = (
  args: Args
) =>
  pipe(
    Sql.tag,
    Effect.bindTo("sql"),
    Effect.bind("input", () => Schema.encode(Args)(args)),
    Effect.map(
      ({ input, sql }) =>
        sql`SELECT * FROM my_events WHERE account_id = ${
          input.accountId
        } AND aggregate_id IN ${sql(input.ids)}`
    )
  );

I would expect the produced SQL query to be something of the following shape:

SELECT * FROM my_events WHERE account_id = ? AND aggregate_id IN (?)

However, in reality, we're getting:

SELECT * FROM my_events WHERE account_id = ? AND aggregate_id IN (`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`,`12`,`13`,`14`,`15`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)

A ulid, when encoded as a binary, is 16 bytes long (explains 0...15).

For more details, see Discord: https://discord.com/channels/795981131316985866/1148264145314127913

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant