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
{{ message }}
This repository was archived by the owner on Mar 25, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: content/docs/0300_ingesting-data/0300_foreign-data-wrappers/0500_load-mount-handlers.mdx
+5-66Lines changed: 5 additions & 66 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,76 +6,15 @@ export const meta = {
6
6
To mount a custom database into your Splitgraph engine, you have to do three things:
7
7
8
8
- Install the foreign data wrapper into the engine (either using PGXN or compiling the wrapper by yourself)
9
-
- Write a Python function that, when invoked, will create the required mountpoint on the engine and initialize
10
-
the remote foreign data wrapper. For an example, see `mount_postgres` in `splitgraph.hooks.mount_handlers`.
9
+
- Write a Python class deriving from `ForeignDataWrapperDataSource` that defines the FDW's class
10
+
and how command line options map to the FDW's own options. For an example, see `PostgreSQLDataSource` in `splitgraph.hooks.data_source`.
11
11
- Register the handler in your `.sgconfig` file:
12
12
13
13
```ini
14
14
[mount_handlers]
15
-
handler_name=your.handler.module.handler_function
15
+
handler_name=your.handler.module.HandlerClass
16
16
```
17
17
18
-
Registering the handler in such a way will also parse its function signature and docstring, adding the handler automatically to the `sgr` client as a subcommand, as well as making it available to be used in Splitfiles.
18
+
Registering the handler in such a way will also use make it available in the `sgr` client as an `sgr mount`subcommand, as well as make it available to be used in Splitfiles.
gets made available in the `sgr` client with this help message:
59
-
60
-
```bash
61
-
$ sgr mount postgres_fdw --help
62
-
Usage: sgr mount postgres_fdw [OPTIONS] SCHEMA
63
-
64
-
Mount a Postgres database.
65
-
66
-
Mounts a schema on a remote Postgres database as a set of foreign
67
-
tables locally.
68
-
69
-
Options:
70
-
-c, --connection TEXT Connection string in the form
71
-
username:password@server:port
72
-
-o, --handler-options TEXT JSON-encoded dictionary of handler options:
73
-
dbname: Remote database name.
74
-
remote_schema:
75
-
Remote schema name.
76
-
tables: Tables to mount
77
-
(default all).
78
-
--help Show this message and exit.
79
-
```
80
-
81
-
The connection string gets parsed and passed to the mount handler as `server`, `port`, `username` and `password` parameters. The remaining options are converted from a JSON dictionary and passed to the handler as extra kwargs.
20
+
For an end-to-end example of a custom mount handler querying the Firebase Hacker News API, see [Splitgraph's GitHub repository](https://github.com/splitgraph/splitgraph/tree/master/examples/custom_fdw).
0 commit comments