Muhammad-Magdi / pgmq-js

Postgres Message Queue (PGMQ) JavaScript Client Library
Apache License 2.0
60 stars 2 forks source link

Deno version and Bug with parseDbQueue #5

Closed tmountain closed 1 month ago

tmountain commented 1 month ago

Hi Muhammad, I just wanted to give you a heads up that I created a derivative library using pgmq-js as the foundation. The library is custom tailored for Deno.

https://github.com/tmountain/deno-pgmq

While I was porting the code, I found a bug in your parseDbQueue function. It was not reporting the is_unlogged flag properly. This is the implementation that I landed on:

export const parseDbQueue = (q: string): Queue => {
  const parts = q.substring(1, q.length - 1).split(",");
  return {
    name: parts[0],
    createdAt: new Date(parts[3]),
    isPartitioned: parts[1] === "t",
    isUnlogged: parts[2] === "t",
  };
};

I updated my project's license to provide the proper attribution. Thank you for your work on this. It has been very helpful.

tmountain commented 1 month ago

Just illustrate the previous bug:

> const q = '(test2,f,t,"2024-09-18 08:48:41.85001+00")'
undefined
> const parts = q.substring(1, q.length - 1).split(",");
undefined
> parts
[ "test2", "f", "t", '"2024-09-18 08:48:41.85001+00"' ]
> {
        name: parts[0],
        createdAt: new Date(parts[1]),
        isPartitioned: parts[2] === "t",
        isUnlogged: parts[3] === "t",
    }
{
  name: "test2",
  createdAt: Invalid Date,
  isPartitioned: true,
  isUnlogged: false
}
Muhammad-Magdi commented 1 month ago

Thanks @tmountain. This is fixed by #6.