Skip to content

Commit

Permalink
fixed so ui shows correct package name and other stuff + small bug
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikSorum committed Feb 18, 2025
1 parent d32a509 commit 2e37d08
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 59 deletions.
101 changes: 50 additions & 51 deletions api/src/db.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
// import dotenv from 'dotenv'
import pg from 'pg'
const { Pool } = pg

// dotenv.config({ path: '../../.env' })

// const { DB_PASSWORD } = process.env
// if (!DB_PASSWORD) {
// throw new Error("Missing DB_PASSWORD env variable.")
// }

const pool = new Pool({
user: "osvuser",
host: "lsm_database",
database: "osvdb",
password: 'osvpassword',
// password: DB_PASSWORD,
port: 5432,
max: 20,
idleTimeoutMillis: 5000,
connectionTimeoutMillis: 3000
})

export default async function run(query: string, params: string[]) {
const client = await pool.connect()
try {
return await client.query(query, params)
} catch (error) {
client.release()
throw error
} finally {
client.release()
}
}

export async function runInTransaction<T>(
callback: (client: pg.PoolClient) => Promise<T>
): Promise<T> {
const client = await pool.connect()
try {
await client.query("BEGIN")
const result = await callback(client)
await client.query("COMMIT")
return result
} catch (error) {
await client.query("ROLLBACK")
throw error
} finally {
client.release()
}
}
// import dotenv from 'dotenv'
import pg from 'pg'
const { Pool } = pg

// dotenv.config({ path: '../../.env' })

// const { DB_PASSWORD } = process.env
// if (!DB_PASSWORD) {
// throw new Error("Missing DB_PASSWORD env variable.")
// }

const pool = new Pool({
user: "osvuser",
host: "lsm_database",
database: "osvdb",
password: 'osvpassword',
// password: DB_PASSWORD,
port: 5432,
max: 20,
idleTimeoutMillis: 5000,
connectionTimeoutMillis: 3000
})

export default async function run(query: string, params: string[]) {
const client = await pool.connect()
try {
return await client.query(query, params)
} catch (error) {
throw error
} finally {
client.release()
}
}

export async function runInTransaction<T>(
callback: (client: pg.PoolClient) => Promise<T>
): Promise<T> {
const client = await pool.connect()
try {
await client.query("BEGIN")
const result = await callback(client)
await client.query("COMMIT")
return result
} catch (error) {
await client.query("ROLLBACK")
throw error
} finally {
client.release()
}
}
9 changes: 1 addition & 8 deletions ui/src/utils/filtering/editPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,5 @@ export default async function editPackage({pkg, setPackages, packages, list}: Re
return
}

setPackages(packages.filter((p) => p.name !== pkg.name))
// setPackages([...packages, {
// name: pkg.name,
// ecosystems: pkg.ecosystems,
// versions: pkg.versions,
// comments: pkg.comments,
// repositories: pkg.repositories
// }])
setPackages(packages.map((p) =>p.name === pkg.name ? pkg : p));
}

0 comments on commit 2e37d08

Please sign in to comment.