Created
June 16, 2020 09:54
-
-
Save joras/8ac861709a8f1b879944cfa3575adc43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createConnection, Connection, PrimaryColumn } from "typeorm"; | |
import { Entity, Column } from "typeorm"; | |
@Entity() | |
export class Test { | |
@PrimaryColumn("integer") | |
id!: string; | |
} | |
function sleep(ms: number) { | |
return new Promise((resolve) => { | |
setTimeout(resolve, ms); | |
}); | |
} | |
async function longQuery(connection: Connection) { | |
try { | |
console.log(await connection.query("SELECT pg_sleep(5)")); | |
} catch (e) { | |
console.error("caught ", e); | |
} | |
} | |
async function borkedQuery(connection: Connection) { | |
try { | |
console.log(await connection.query("SELECT asdf;")); | |
} catch (e) { | |
console.error("borked caught ", e); | |
} | |
} | |
async function main() { | |
const connection = await createConnection({ | |
type: "postgres", | |
host: "localhost", | |
port: 5432, | |
username: "postgres", | |
password: "postgres", | |
database: "test", | |
entities: [Test], | |
synchronize: true, | |
poolErrorHandler: (err) => console.error("pool error: ", err), | |
logging: true, | |
extra: { | |
min: 2, | |
max: 2, | |
}, | |
}); | |
while (true) { | |
await longQuery(connection); | |
await borkedQuery(connection); | |
await sleep(1000); | |
} | |
} | |
main().catch((err) => { | |
console.error("main error", err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment