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

Updating TS target to 2022 to fix pg dependency bug #73

Merged
merged 7 commits into from
Nov 23, 2023

Conversation

sordina
Copy link
Contributor

@sordina sordina commented Nov 22, 2023

Bug reported against v0.14.1

Fixed by updating TS target and libraries to 2022.

New test: src/test/data/pg_dep.ts

Example Reproduction - index.ts:

import { Client } from "https://deno.land/x/[email protected]/mod.ts";

const dbConfig = {
  user: "asdfasdfasdfasdf",
  hostname: "asdfasdfasdfasdf.us-west-2.aws.neon.tech",
  port: 5432,
  password: "asdfasdfasdfasdf",
  database: "asdfasdfasdfasdf",
  ssl: true,
  sslmode: "require",
};

export async function insert_user(
  user_name: string,
): Promise<
  { id: string; name: string; created_at: string } | { message: string } | {
    error: string;
  } | {}
> {
  const client = new Client(dbConfig);

  try {
    await client.connect();

    const result = await client.queryObject({
      text: `INSERT INTO users(name) VALUES ('${user_name}') RETURNING *`,
    });

    if (result && result.rows.length > 0 && result.rows[0]) {
      return result.rows[0];
    } else {
      return { message: "Insert Failed" };
    }
  } catch (error) {
    console.error("Error:", error);
    return { error: "Error: " + error.message };
  } finally {
    await client.end();
  }
}

export async function insert_todos(
    user_id: string,
    todo: string
  ): Promise<
    { id: string; user_id: string; todo: string; created_at: string } | { message: string } | {
      error: string;
    } | {}
  > {
    const client = new Client(dbConfig);
  
    try {
      await client.connect();
      

      // Check if the user exists in the users table

      const userExistsQuery = await client.queryObject({
        text: `SELECT id FROM users where id =${user_id}`
      })

      if (userExistsQuery.rows.length === 0) {
        return { message: "User not found. Insert Failed" };
      }
      const result = await client.queryObject({
        text: `INSERT INTO todos(user_id,todo) VALUES ('${user_id}','${todo}') RETURNING *`,
      });
     
      if (result && result.rows.length > 0 && result.rows[0]) {
        return result.rows[0];
      } else {
        return { message: "Insert Failed" };
      }
    } catch (error) {
      console.error("Error:", error);
      return { error: "Error: " + error.message };
    } finally {
      await client.end();
    }
  }


  export async function delete_todos(
    todo_id: string
  ){
    const client = new Client(dbConfig);
    try{
      await  client.connect();

      const result = await client.queryObject({ text: `DELETE FROM todos WHERE id =${todo_id}`})
      if(result.rowCount===1){
        return `Deleted todo with id= ${todo_id} sucesssfully`
      }else{
        return "Deletion unsucessfull"
      }
    }catch(error){
        return "Error : "+ error.message
    }finally{
        client.end();
    }

  }

@sordina sordina self-assigned this Nov 22, 2023
@sordina sordina changed the title changing TS dependencies to fix bug reported by sooraj Updating TS target to 2022 to fix pg dependency bug Nov 23, 2023
CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Daniel Chambers <[email protected]>
@sordina sordina merged commit 34ea797 into main Nov 23, 2023
1 check passed
@daniel-chambers daniel-chambers deleted the lyndon/pg-bug-report-sooraj branch November 24, 2023 11:05
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 this pull request may close these issues.

2 participants