diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..47eb6801 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,22 @@ +# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster +ARG VARIANT=16-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT} + +ENV DENO_INSTALL=/deno +RUN mkdir -p /deno \ + && curl -fsSL https://deno.land/x/install/install.sh | sh \ + && chown -R node /deno + +ENV PATH=${DENO_INSTALL}/bin:${PATH} \ + DENO_DIR=${DENO_INSTALL}/.cache/deno + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +# [Optional] Uncomment if you want to install more global node packages +# RUN su node -c "npm install -g " diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..c5466490 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,37 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/typescript-node +{ + "name": "Node.js & TypeScript", + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick a Node version: 18, 16, 14. + // Append -bullseye or -buster to pin to an OS version. + // Use -bullseye variants on local on arm64/Apple Silicon. + "args": { + "VARIANT": "18-bullseye" + } + }, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "dbaeumer.vscode-eslint" + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "npm install", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "node", + "features": { + "docker-from-docker": "latest" + } +} diff --git a/src/index.js b/src/index.js index 0573e2bc..4398b5f9 100644 --- a/src/index.js +++ b/src/index.js @@ -251,8 +251,7 @@ function Postgres(a, b) { const sql = Sql(handler) sql.savepoint = savepoint sql.prepare = x => prepare = x.replace(/[^a-z0-9$-_. ]/gi) - let uncaughtError - , result + let result name && await sql`savepoint ${ sql(name) }` try { @@ -260,15 +259,12 @@ function Postgres(a, b) { const x = fn(sql) Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(resolve, reject) }) - - if (uncaughtError) - throw uncaughtError } catch (e) { await (name ? sql`rollback to ${ sql(name) }` : sql`rollback` ) - throw e instanceof PostgresError && e.code === '25P02' && uncaughtError || e + throw e } if (!name) { @@ -288,7 +284,6 @@ function Postgres(a, b) { } function handler(q) { - q.catch(e => uncaughtError || (uncaughtError = e)) c.queue === full ? queries.push(q) : c.execute(q) || move(c, full)