Skip to content

Instantly share code, notes, and snippets.

@joras
Created June 16, 2020 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joras/8ac861709a8f1b879944cfa3575adc43 to your computer and use it in GitHub Desktop.
Save joras/8ac861709a8f1b879944cfa3575adc43 to your computer and use it in GitHub Desktop.
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