Skip to content

fix(database) :: test the connection pool hooks and the retry backoff - #1437

Open
81reap wants to merge 1 commit into
sqlpage:mainfrom
81reap:mutation/12-2-connection-pool-hooks
Open

fix(database) :: test the connection pool hooks and the retry backoff#1437
81reap wants to merge 1 commit into
sqlpage:mainfrom
81reap:mutation/12-2-connection-pool-hooks

Conversation

@81reap

@81reap 81reap commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

on_connect.sql and on_reset.sql are documented in configuration.md but are not covered by any tests.

The retry test runs on a paused clock, so it asserts that each retry waits five seconds and that the loop then gives up.

discovered by #1396

SQLPage/configuration.md

Lines 239 to 280 in 6d32b40

### Connection initialization scripts
SQLPage allows you to run a SQL script when a new database connection is opened,
by simply creating a `sqlpage/on_connect.sql` file.
This can be useful to set up the database connection for your application.
For instance, on postgres, you can use this to [set the `search path` and various other connection options](https://www.postgresql.org/docs/current/sql-set.html).
```sql
SET TIME ZONE 'UTC';
SET search_path = my_schema;
```
On SQLite, you can use this to [`ATTACH`](https://www.sqlite.org/lang_attach.html) additional databases.
```sql
ATTACH DATABASE '/path/to/my_other_database.db' AS my_other_database;
```
(and then, you can use `my_other_database.my_table` in your queries)
You can also use this to create *temporary tables* to store intermediate results that are useful in your SQLPage application, but that you don't want to store permanently in the database.
```sql
CREATE TEMPORARY TABLE my_temporary_table(
my_temp_column TEXT
);
```
### Connection cleanup scripts: `on_reset.sql`
SQLPage allows you to run a SQL script after a request has been processed,
by simply creating a `sqlpage/on_reset.sql` file.
This can be useful to clean up temporary tables,
rollback transactions that were left open,
or other resources that were created during the request.
You can also use this script to close database connections that are
in an undesirable state, such as being in a transaction that was left open.
To close a connection, write a select statement that returns a single row
with a single boolean column named `is_healthy`, and set it to false.

`on_connect.sql` and `on_reset.sql` are documented in `configuration.md` but are covered by any tests.

The retry test runs on a paused clock, so it asserts that each retry waits five seconds and that the loop then gives up.
@81reap
81reap force-pushed the mutation/12-2-connection-pool-hooks branch from 88b3e56 to be99484 Compare September 7, 2026 05:23
@81reap
81reap marked this pull request as ready for review September 7, 2026 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant