Unverified Commit 734d661b authored by Hong Minhee's avatar Hong Minhee
Browse files

Fix bug where some scalar values failed to store

parent 628be034
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -68,6 +68,9 @@ Changelog

To be released.

 -  Fixed a bug where some scalar values have failed to be stored in the
    database.

### Version 0.2.0

Released on November 3, 2024.
+10 −0
Original line number Diff line number Diff line
@@ -56,6 +56,16 @@ Deno.test("PostgresKvStore", async (t) => {
    assertEquals(result2[0].key, ["foo", "qux"]);
    assertEquals(result2[0].value, "qux");
    assertEquals(result2[0].ttl, "1 day");

    await store.set(["foo", "quux"], true);
    const result3 = await sql`
      SELECT * FROM ${sql(tableName)}
      WHERE key = ${["foo", "quux"]}
    `;
    assertEquals(result3.length, 1);
    assertEquals(result3[0].key, ["foo", "quux"]);
    assertEquals(result3[0].value, true);
    assertEquals(result3[0].ttl, null);
  });

  await t.step("delete()", async () => {
+5 −1
Original line number Diff line number Diff line
@@ -82,7 +82,11 @@ export class PostgresKvStore implements KvStore {
    const ttl = options?.ttl == null ? null : options.ttl.toString();
    await this.#sql`
      INSERT INTO ${this.#sql(this.#tableName)} (key, value, ttl)
      VALUES (${key}, ${value as string}, ${ttl})
      VALUES (
        ${key},
        (${{ value } as unknown as string}::jsonb) -> 'value',
        ${ttl}
      )
      ON CONFLICT (key)
        DO UPDATE SET value = EXCLUDED.value, ttl = EXCLUDED.ttl;
    `;
+4 −1
Original line number Diff line number Diff line
@@ -85,7 +85,10 @@ export class PostgresMessageQueue implements MessageQueue {
    const delay = options?.delay ?? Temporal.Duration.from({ seconds: 0 });
    await this.#sql`
      INSERT INTO ${this.#sql(this.#tableName)} (message, delay)
      VALUES (${message}, ${delay.toString()});
      VALUES (
        (${{ message } as unknown as string}::jsonb) -> 'message',
        ${delay.toString()}
      );
    `;
    await this.#sql.notify(this.#channelName, delay.toString());
  }