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