You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add the ability to create a `sqlpage/on_connect.sql` file that will be run every time a new database connection is opened.
This has many interesting applications, see configuration.md
See #48
SQLPage allows you to create custom components in addition to or instead of the default ones.
41
+
To create a custom component, create a [`.handlebars`](https://handlebarsjs.com/guide/expressions.html)
42
+
file in the `sqlpage/templates` directory of your SQLPage installation.
43
+
44
+
For instance, if you want to create a custom `my_component` component, that displays the value of the `my_column` column, create a `sqlpage/templates/my_component.handlebars` file with the following content:
45
+
46
+
```handlebars
47
+
<ul>
48
+
{{#each_row}}
49
+
<li>Value of my column: {{my_column}}</li>
50
+
{{/each_row}}
51
+
</ul>
52
+
```
53
+
54
+
## Connection initialization scripts
55
+
56
+
SQLPage allows you to run a SQL script when a new database connection is opened,
57
+
by simply creating a `sqlpage/on_connect.sql` file.
58
+
59
+
This can be useful to set up the database connection for your application.
60
+
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).
61
+
62
+
```sql
63
+
SETTIME ZONE 'UTC';
64
+
SET search_path = my_schema;
65
+
```
66
+
67
+
On SQLite, you can use this to [`ATTACH`](https://www.sqlite.org/lang_attach.html) additional databases.
(and then, you can use `my_other_database.my_table` in your queries)
74
+
75
+
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.
0 commit comments