Skip to content

Commit

Permalink
chore: update debug docs with example
Browse files Browse the repository at this point in the history
  • Loading branch information
bombillazo committed Feb 18, 2024
1 parent 87151ed commit d2858aa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1403,27 +1403,49 @@ enabled by using the `debug` option in the Client `controls` parameter. Pass
options:

- `queries` : Logs all SQL queries executed by the client
- `notices` : Logs database notices
- `notices` : Logs database messages (INFO, NOTICE, WARNING))
- `results` : Logs the result of the queries

### Example

```ts
{
const client = new Client({
...
controls: {
// enable all logs
debug: true,
},
});
import { Client } from "./mod.ts";

const client = new Client({
...
controls: {
// only enable logging of SQL query statements
debug: {
queries: true,
},
const client = new Client({
user: "postgres",
database: "postgres",
hostname: "localhost",
port: 5432,
password: "postgres",
controls: {
// the same as `debug: true`
debug: {
queries: true,
notices: true,
results: true,
},
});
}
},
});

await client.connect();

const result = await client.queryObject`SELECT public.get_some_user()`;

await client.end();
```

```sql
-- example database function that raises messages
CREATE OR REPLACE FUNCTION public.get_uuid()
RETURNS uuid LANGUAGE plpgsql
AS $function$
BEGIN
RAISE INFO 'This function generates a random UUID :)';
RAISE NOTICE 'A UUID takes up 128 bits in memory.';
RAISE WARNING 'UUIDs must follow a specific format and lenght in order to be valid!';
RETURN gen_random_uuid();
END;
$function$;;
```

![debug-output](debug-output.png)
Binary file added docs/debug-output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit d2858aa

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No typecheck tests failure

This error was most likely caused by incorrect type stripping from the SWC crate

Please report the following failure to https://github.com/denoland/deno with a reproduction of the current commit

Failure log

Please sign in to comment.