postgres connection pooling
This commit is contained in:
parent
0e9a2c8e9b
commit
2761eaed2d
|
@ -8,7 +8,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<p
|
<p
|
||||||
style="{textAlign ? `text-align:${textAlign}` : ``}"
|
style={textAlign ? `text-align:${textAlign}` : ``}
|
||||||
class:noPadding
|
class:noPadding
|
||||||
class="spectrum-Body spectrum-Body--size{size}"
|
class="spectrum-Body spectrum-Body--size{size}"
|
||||||
class:spectrum-Body--serif={serif}
|
class:spectrum-Body--serif={serif}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1
|
<h1
|
||||||
style="{textAlign ? `text-align:${textAlign}` : ``}"
|
style={textAlign ? `text-align:${textAlign}` : ``}
|
||||||
class:noPadding
|
class:noPadding
|
||||||
class="spectrum-Heading spectrum-Heading--size{size}"
|
class="spectrum-Heading spectrum-Heading--size{size}"
|
||||||
>
|
>
|
||||||
|
|
|
@ -30,12 +30,14 @@
|
||||||
<Layout gap="XS" noPadding>
|
<Layout gap="XS" noPadding>
|
||||||
<Heading textAlign="center">Forgotten your password?</Heading>
|
<Heading textAlign="center">Forgotten your password?</Heading>
|
||||||
<Body size="S" textAlign="center">
|
<Body size="S" textAlign="center">
|
||||||
No problem! Just enter your account's email address and we'll send
|
No problem! Just enter your account's email address and we'll send you
|
||||||
you a link to reset it.
|
a link to reset it.
|
||||||
</Body>
|
</Body>
|
||||||
<Input label="Email" bind:value={email} />
|
<Input label="Email" bind:value={email} />
|
||||||
</Layout>
|
</Layout>
|
||||||
<Button cta on:click={forgot} disabled={!email}>Reset your password</Button>
|
<Button cta on:click={forgot} disabled={!email}
|
||||||
|
>Reset your password</Button
|
||||||
|
>
|
||||||
</Layout>
|
</Layout>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
notifications.error("Unable to reset password")
|
notifications.error("Unable to reset password")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -33,7 +32,9 @@
|
||||||
</Body>
|
</Body>
|
||||||
<PasswordRepeatInput bind:password bind:error />
|
<PasswordRepeatInput bind:password bind:error />
|
||||||
</Layout>
|
</Layout>
|
||||||
<Button cta on:click={reset} disabled={error || !resetCode}>Reset your password</Button>
|
<Button cta on:click={reset} disabled={error || !resetCode}
|
||||||
|
>Reset your password</Button
|
||||||
|
>
|
||||||
</Layout>
|
</Layout>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
const { Client } = require("pg")
|
const { Pool } = require("pg")
|
||||||
|
|
||||||
|
let pool
|
||||||
|
|
||||||
const SCHEMA = {
|
const SCHEMA = {
|
||||||
docs: "https://node-postgres.com",
|
docs: "https://node-postgres.com",
|
||||||
|
@ -51,31 +53,39 @@ const SCHEMA = {
|
||||||
class PostgresIntegration {
|
class PostgresIntegration {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.config = config
|
this.config = config
|
||||||
this.client = new Client(config)
|
if (!pool) {
|
||||||
this.connect()
|
pool = new Pool(this.config)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
async query(sql) {
|
||||||
return this.client.connect()
|
try {
|
||||||
|
this.client = await pool.connect()
|
||||||
|
return await this.client.query(sql)
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(err)
|
||||||
|
} finally {
|
||||||
|
this.client.release()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async create({ sql }) {
|
async create({ sql }) {
|
||||||
const response = await this.client.query(sql)
|
const response = await this.query(sql)
|
||||||
return response.rows.length ? response.rows : [{ created: true }]
|
return response.rows.length ? response.rows : [{ created: true }]
|
||||||
}
|
}
|
||||||
|
|
||||||
async read({ sql }) {
|
async read({ sql }) {
|
||||||
const response = await this.client.query(sql)
|
const response = await this.query(sql)
|
||||||
return response.rows
|
return response.rows
|
||||||
}
|
}
|
||||||
|
|
||||||
async update({ sql }) {
|
async update({ sql }) {
|
||||||
const response = await this.client.query(sql)
|
const response = await this.query(sql)
|
||||||
return response.rows.length ? response.rows : [{ updated: true }]
|
return response.rows.length ? response.rows : [{ updated: true }]
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete({ sql }) {
|
async delete({ sql }) {
|
||||||
const response = await this.client.query(sql)
|
const response = await this.query(sql)
|
||||||
return response.rows.length ? response.rows : [{ deleted: true }]
|
return response.rows.length ? response.rows : [{ deleted: true }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue