Skip to content

Commit

Permalink
chore: Update for Deno 1.26.2 (#413)
Browse files Browse the repository at this point in the history
Co-authored-by: Arthur Petukhovsky <[email protected]>
  • Loading branch information
Soremwar and petuhovskiy committed Oct 19, 2022
1 parent 8a07131 commit 096d6cb
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 138 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: 1.17.3
deno-version: 1.26.2

- name: Format
run: deno fmt --check
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Report no typechecking tests status
id: no_typecheck_status
if: steps.no_typecheck.outcome == 'success'
run: echo "::set-output name=status::success"
run: echo "name=status::success" >> $GITHUB_OUTPUT
outputs:
no_typecheck: ${{ steps.no_typecheck.outputs.stdout }}
no_typecheck_status: ${{ steps.no_typecheck_status.outputs.status }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM denoland/deno:alpine-1.17.3
FROM denoland/deno:alpine-1.26.2
WORKDIR /app

# Install wait utility
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ await client.connect();
}

{
const result = await client.queryArray
`SELECT ID, NAME FROM PEOPLE WHERE ID = ${1}`;
const result = await client
.queryArray`SELECT ID, NAME FROM PEOPLE WHERE ID = ${1}`;
console.log(result.rows); // [[1, 'Carlos']]
}

Expand All @@ -43,8 +43,8 @@ await client.connect();
}

{
const result = await client.queryObject
`SELECT ID, NAME FROM PEOPLE WHERE ID = ${1}`;
const result = await client
.queryObject`SELECT ID, NAME FROM PEOPLE WHERE ID = ${1}`;
console.log(result.rows); // [{id: 1, name: 'Carlos'}]
}

Expand Down
2 changes: 1 addition & 1 deletion connection/connection_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export function createParams(
if (parsed_host.protocol === "file:") {
host = fromFileUrl(parsed_host);
} else {
throw new ConnectionParamsError(
throw new Error(
"The provided host is not a file path",
);
}
Expand Down
2 changes: 1 addition & 1 deletion connection/scram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function deriveKeySignatures(
salt,
},
pbkdf2_password,
{ name: "HMAC", hash: "SHA-256" },
{ name: "HMAC", hash: "SHA-256", length: 256 },
false,
["sign"],
);
Expand Down
18 changes: 9 additions & 9 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export * as base64 from "https://deno.land/std@0.141.0/encoding/base64.ts";
export * as hex from "https://deno.land/std@0.141.0/encoding/hex.ts";
export * as date from "https://deno.land/std@0.141.0/datetime/mod.ts";
export * as base64 from "https://deno.land/std@0.160.0/encoding/base64.ts";
export * as hex from "https://deno.land/std@0.160.0/encoding/hex.ts";
export * as date from "https://deno.land/std@0.160.0/datetime/mod.ts";
export {
BufReader,
BufWriter,
} from "https://deno.land/std@0.141.0/io/buffer.ts";
export { copy } from "https://deno.land/std@0.141.0/bytes/mod.ts";
export { crypto } from "https://deno.land/std@0.141.0/crypto/mod.ts";
} from "https://deno.land/std@0.160.0/io/buffer.ts";
export { copy } from "https://deno.land/std@0.160.0/bytes/mod.ts";
export { crypto } from "https://deno.land/std@0.160.0/crypto/mod.ts";
export {
type Deferred,
deferred,
delay,
} from "https://deno.land/std@0.141.0/async/mod.ts";
export { bold, yellow } from "https://deno.land/std@0.141.0/fmt/colors.ts";
} from "https://deno.land/std@0.160.0/async/mod.ts";
export { bold, yellow } from "https://deno.land/std@0.160.0/fmt/colors.ts";
export {
fromFileUrl,
isAbsolute,
join as joinPath,
} from "https://deno.land/std@0.141.0/path/mod.ts";
} from "https://deno.land/std@0.160.0/path/mod.ts";
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ services:
build: .
# Name the image to be reused in no_check_tests
image: postgres/tests
command: sh -c "/wait && deno test --unstable -A --jobs"
command: sh -c "/wait && deno test --unstable -A --parallel --check"
depends_on:
- postgres_clear
- postgres_md5
Expand All @@ -74,7 +74,7 @@ services:

no_check_tests:
image: postgres/tests
command: sh -c "/wait && deno test --unstable -A --jobs --no-check"
command: sh -c "/wait && deno test --unstable -A --parallel --no-check"
depends_on:
- tests
environment:
Expand Down
53 changes: 29 additions & 24 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -628,16 +628,16 @@ prepared statements with a nice and clear syntax for your queries

```ts
{
const result = await client.queryArray
`SELECT ID, NAME FROM PEOPLE WHERE AGE > ${10} AND AGE < ${20}`;
const result = await client
.queryArray`SELECT ID, NAME FROM PEOPLE WHERE AGE > ${10} AND AGE < ${20}`;
console.log(result.rows);
}

{
const min = 10;
const max = 20;
const result = await client.queryObject
`SELECT ID, NAME FROM PEOPLE WHERE AGE > ${min} AND AGE < ${max}`;
const result = await client
.queryObject`SELECT ID, NAME FROM PEOPLE WHERE AGE > ${min} AND AGE < ${max}`;
console.log(result.rows);
}
```
Expand Down Expand Up @@ -686,8 +686,8 @@ await client.queryArray`UPDATE TABLE X SET Y = 0 WHERE Z = ${my_id}`;
// Invalid attempt to replace an specifier
const my_table = "IMPORTANT_TABLE";
const my_other_id = 41;
await client.queryArray
`DELETE FROM ${my_table} WHERE MY_COLUMN = ${my_other_id};`;
await client
.queryArray`DELETE FROM ${my_table} WHERE MY_COLUMN = ${my_other_id};`;
```

### Specifying result type
Expand All @@ -706,8 +706,9 @@ intellisense
}

{
const array_result = await client.queryArray<[number, string]>
`SELECT ID, NAME FROM PEOPLE WHERE ID = ${17}`;
const array_result = await client.queryArray<
[number, string]
>`SELECT ID, NAME FROM PEOPLE WHERE ID = ${17}`;
// [number, string]
const person = array_result.rows[0];
}
Expand All @@ -721,8 +722,9 @@ intellisense
}

{
const object_result = await client.queryObject<{ id: number; name: string }>
`SELECT ID, NAME FROM PEOPLE WHERE ID = ${17}`;
const object_result = await client.queryObject<
{ id: number; name: string }
>`SELECT ID, NAME FROM PEOPLE WHERE ID = ${17}`;
// {id: number, name: string}
const person = object_result.rows[0];
}
Expand Down Expand Up @@ -1037,8 +1039,8 @@ const transaction = client_1.createTransaction("transaction_1");

await transaction.begin();

await transaction.queryArray
`CREATE TABLE TEST_RESULTS (USER_ID INTEGER, GRADE NUMERIC(10,2))`;
await transaction
.queryArray`CREATE TABLE TEST_RESULTS (USER_ID INTEGER, GRADE NUMERIC(10,2))`;
await transaction.queryArray`CREATE TABLE GRADUATED_STUDENTS (USER_ID INTEGER)`;

// This operation takes several minutes
Expand Down Expand Up @@ -1087,16 +1089,18 @@ following levels of transaction isolation:
await transaction.begin();
// This locks the current value of IMPORTANT_TABLE
// Up to this point, all other external changes will be included
const { rows: query_1 } = await transaction.queryObject<{ password: string }>
`SELECT PASSWORD FROM IMPORTANT_TABLE WHERE ID = ${my_id}`;
const { rows: query_1 } = await transaction.queryObject<
{ password: string }
>`SELECT PASSWORD FROM IMPORTANT_TABLE WHERE ID = ${my_id}`;
const password_1 = rows[0].password;

// Concurrent operation executed by a different user in a different part of the code
await client_2.queryArray
`UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id}`;
await client_2
.queryArray`UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id}`;

const { rows: query_2 } = await transaction.queryObject<{ password: string }>
`SELECT PASSWORD FROM IMPORTANT_TABLE WHERE ID = ${my_id}`;
const { rows: query_2 } = await transaction.queryObject<
{ password: string }
>`SELECT PASSWORD FROM IMPORTANT_TABLE WHERE ID = ${my_id}`;
const password_2 = rows[0].password;

// Database state is not updated while the transaction is ongoing
Expand Down Expand Up @@ -1124,18 +1128,19 @@ following levels of transaction isolation:
await transaction.begin();
// This locks the current value of IMPORTANT_TABLE
// Up to this point, all other external changes will be included
await transaction.queryObject<{ password: string }>
`SELECT PASSWORD FROM IMPORTANT_TABLE WHERE ID = ${my_id}`;
await transaction.queryObject<
{ password: string }
>`SELECT PASSWORD FROM IMPORTANT_TABLE WHERE ID = ${my_id}`;

// Concurrent operation executed by a different user in a different part of the code
await client_2.queryArray
`UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id}`;
await client_2
.queryArray`UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id}`;

// This statement will throw
// Target was modified outside of the transaction
// User may not be aware of the changes
await transaction.queryArray
`UPDATE IMPORTANT_TABLE SET PASSWORD = 'shiny_new_password' WHERE ID = ${the_same_id}`;
await transaction
.queryArray`UPDATE IMPORTANT_TABLE SET PASSWORD = 'shiny_new_password' WHERE ID = ${the_same_id}`;

// Transaction is aborted, no need to end it

Expand Down
5 changes: 2 additions & 3 deletions query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ export type QueryArguments = unknown[] | Record<string, unknown>;

const commandTagRegexp = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/;

type CommandType = (
type CommandType =
| "INSERT"
| "DELETE"
| "UPDATE"
| "SELECT"
| "MOVE"
| "FETCH"
| "COPY"
);
| "COPY";

export enum ResultType {
ARRAY,
Expand Down
5 changes: 3 additions & 2 deletions query/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ export class Transaction {
async getSnapshot(): Promise<string> {
this.#assertTransactionOpen();

const { rows } = await this.queryObject<{ snapshot: string }>
`SELECT PG_EXPORT_SNAPSHOT() AS SNAPSHOT;`;
const { rows } = await this.queryObject<
{ snapshot: string }
>`SELECT PG_EXPORT_SNAPSHOT() AS SNAPSHOT;`;
return rows[0].snapshot;
}

Expand Down
36 changes: 19 additions & 17 deletions tests/connection_params_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,31 +478,33 @@ Deno.test("Throws when TLS options and socket type are specified", () => {
});

Deno.test("Throws when host is a URL and host type is socket", () => {
assertThrows(
const error = assertThrows(
() =>
createParams({
database: "some_db",
hostname: "https://some_host.com",
host_type: "socket",
user: "some_user",
}),
(e: unknown) => {
if (!(e instanceof ConnectionParamsError)) {
throw new Error(`Unexpected error: ${e}`);
}

const expected_message = "The provided host is not a file path";

if (
typeof e?.cause?.message !== "string" ||
!e.cause.message.includes(expected_message)
) {
throw new Error(
`Expected error message to include "${expected_message}"`,
);
}
},
);

if (!(error instanceof ConnectionParamsError)) {
throw new Error(`Unexpected error: ${error}`);
}

if (!(error.cause instanceof Error)) {
throw new Error(`Expected cause for error`);
}

const expected_message = "The provided host is not a file path";
if (
typeof error.cause.message !== "string" ||
!error.cause.message.includes(expected_message)
) {
throw new Error(
`Expected error cause to include "${expected_message}"`,
);
}
});

Deno.test("Escapes spaces on option values", () => {
Expand Down
16 changes: 6 additions & 10 deletions tests/connection_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,6 @@ Deno.test("Closes connection on bad TLS availability verification", async functi
new URL("./workers/postgres_server.ts", import.meta.url).href,
{
type: "module",
deno: {
namespace: true,
},
},
);

Expand Down Expand Up @@ -437,9 +434,6 @@ async function mockReconnection(attempts: number) {
new URL("./workers/postgres_server.ts", import.meta.url).href,
{
type: "module",
deno: {
namespace: true,
},
},
);

Expand Down Expand Up @@ -668,8 +662,9 @@ Deno.test("Options are passed to the database on connection", async () => {
await client.connect();

try {
const { rows: result } = await client.queryObject<{ setting: string }>
`SELECT SETTING FROM PG_SETTINGS WHERE NAME = 'geqo'`;
const { rows: result } = await client.queryObject<
{ setting: string }
>`SELECT SETTING FROM PG_SETTINGS WHERE NAME = 'geqo'`;

assertEquals(result.length, 1);
assertEquals(result[0].setting, "off");
Expand All @@ -689,8 +684,9 @@ Deno.test("Options are passed to the database on connection", async () => {
await client.connect();

try {
const { rows: result } = await client.queryObject<{ setting: string }>
`SELECT SETTING FROM PG_SETTINGS WHERE NAME = 'geqo'`;
const { rows: result } = await client.queryObject<
{ setting: string }
>`SELECT SETTING FROM PG_SETTINGS WHERE NAME = 'geqo'`;

assertEquals(result.length, 1);
assertEquals(result[0].setting, "on");
Expand Down
4 changes: 2 additions & 2 deletions tests/data_types_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,8 @@ Deno.test(
Deno.test(
"json",
testClient(async (client) => {
const result = await client.queryArray
`SELECT JSON_BUILD_OBJECT( 'X', '1' )`;
const result = await client
.queryArray`SELECT JSON_BUILD_OBJECT( 'X', '1' )`;

assertEquals(result.rows[0], [{ X: "1" }]);
}),
Expand Down
Loading

0 comments on commit 096d6cb

Please sign in to comment.