@@ -17,6 +17,7 @@ The Clerk Wrapper is a WebAssembly(Wasm) foreign data wrapper which allows you t
1717
1818| Version | Wasm Package URL | Checksum | Required Wrappers Version |
1919| ------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | ------------------------- |
20+ | 0.2.2 | ` https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.2.2/clerk_fdw.wasm ` | tbd | >=0.5.0 |
2021| 0.2.1 | ` https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.2.1/clerk_fdw.wasm ` | ` 100f3f105e7e6dab92c433b2da6bec98fafeccd0304e6efaf3780d0a8cae30ec ` | >=0.5.0 |
2122| 0.2.0 | ` https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.2.0/clerk_fdw.wasm ` | ` 89337bb11779d4d654cd3e54391aabd02509d213db6995f7dd58951774bf0e37 ` | >=0.5.0 |
2223| 0.1.0 | ` https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.1.0/clerk_fdw.wasm ` | ` 613be26b59fa4c074e0b93f0db617fcd7b468d4d02edece0b1f85fdb683ebdc4 ` | >=0.4.0 |
@@ -66,10 +67,10 @@ We need to provide Postgres with the credentials to access Clerk and any additio
6667 create server clerk_server
6768 foreign data wrapper wasm_wrapper
6869 options (
69- fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.2.1 /clerk_fdw.wasm',
70+ fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.2.2 /clerk_fdw.wasm',
7071 fdw_package_name 'supabase:clerk-fdw',
71- fdw_package_version '0.2.1 ',
72- fdw_package_checksum '100f3f105e7e6dab92c433b2da6bec98fafeccd0304e6efaf3780d0a8cae30ec ',
72+ fdw_package_version '0.2.2 ',
73+ fdw_package_checksum 'tbd ',
7374 api_url 'https://api.clerk.com/v1', -- optional
7475 api_key_id '<key_ID>' -- The Key ID from above.
7576 );
@@ -81,10 +82,10 @@ We need to provide Postgres with the credentials to access Clerk and any additio
8182 create server clerk_server
8283 foreign data wrapper wasm_wrapper
8384 options (
84- fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.2.1 /clerk_fdw.wasm',
85+ fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_clerk_fdw_v0.2.2 /clerk_fdw.wasm',
8586 fdw_package_name 'supabase:clerk-fdw',
86- fdw_package_version '0.2.1 ',
87- fdw_package_checksum '100f3f105e7e6dab92c433b2da6bec98fafeccd0304e6efaf3780d0a8cae30ec ',
87+ fdw_package_version '0.2.2 ',
88+ fdw_package_checksum 'tbd ',
8889 api_url 'https://api.clerk.com/v1', -- optional
8990 api_key 'sk_test_...' -- Clerk API key
9091 );
@@ -161,7 +162,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/Allow-lis
161162
162163| Object | Select | Insert | Update | Delete | Truncate |
163164| --------------------- | :----: | :----: | :----: | :----: | :------: |
164- | allowlist_identifiers | ✅ | ❌ | ❌ | ❌ | ❌ |
165+ | allowlist_identifiers | ✅ | ✅ | ❌ | ✅ | ❌ |
165166
166167#### Usage
167168
@@ -178,7 +179,8 @@ create foreign table clerk.allowlist_identifiers (
178179)
179180 server clerk_server
180181 options (
181- object ' allowlist_identifiers'
182+ object ' allowlist_identifiers' ,
183+ rowid_column ' id'
182184 );
183185```
184186
@@ -196,7 +198,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/Allow-lis
196198
197199| Object | Select | Insert | Update | Delete | Truncate |
198200| --------------------- | :----: | :----: | :----: | :----: | :------: |
199- | blocklist_identifiers | ✅ | ❌ | ❌ | ❌ | ❌ |
201+ | blocklist_identifiers | ✅ | ✅ | ❌ | ✅ | ❌ |
200202
201203#### Usage
202204
@@ -212,7 +214,8 @@ create foreign table clerk.blocklist_identifiers (
212214)
213215 server clerk_server
214216 options (
215- object ' blocklist_identifiers'
217+ object ' blocklist_identifiers' ,
218+ rowid_column ' id'
216219 );
217220```
218221
@@ -230,7 +233,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/Domains#o
230233
231234| Object | Select | Insert | Update | Delete | Truncate |
232235| ------- | :----: | :----: | :----: | :----: | :------: |
233- | domains | ✅ | ❌ | ❌ | ❌ | ❌ |
236+ | domains | ✅ | ❌ | ✅ | ✅ | ❌ |
234237
235238#### Usage
236239
@@ -245,7 +248,8 @@ create foreign table clerk.domains (
245248)
246249 server clerk_server
247250 options (
248- object ' domains'
251+ object ' domains' ,
252+ rowid_column ' id'
249253 );
250254```
251255
@@ -263,7 +267,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/Invitatio
263267
264268| Object | Select | Insert | Update | Delete | Truncate |
265269| ----------- | :----: | :----: | :----: | :----: | :------: |
266- | invitations | ✅ | ❌ | ❌ | ❌ | ❌ |
270+ | invitations | ✅ | ✅ | ❌ | ❌ | ❌ |
267271
268272#### Usage
269273
@@ -281,7 +285,8 @@ create foreign table clerk.invitations (
281285)
282286 server clerk_server
283287 options (
284- object ' invitations'
288+ object ' invitations' ,
289+ rowid_column ' id'
285290 );
286291```
287292
@@ -299,7 +304,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/JWT-Templ
299304
300305| Object | Select | Insert | Update | Delete | Truncate |
301306| ------------- | :----: | :----: | :----: | :----: | :------: |
302- | jwt_templates | ✅ | ❌ | ❌ | ❌ | ❌ |
307+ | jwt_templates | ✅ | ✅ | ✅ | ✅ | ❌ |
303308
304309#### Usage
305310
@@ -317,13 +322,15 @@ create foreign table clerk.jwt_templates (
317322)
318323 server clerk_server
319324 options (
320- object ' jwt_templates'
325+ object ' jwt_templates' ,
326+ rowid_column ' id'
321327 );
322328```
323329
324330#### Notes
325331
326332- The ` attrs ` column contains additional attributes in JSON format
333+ - Single-item retrieval is supported via ` WHERE id = 'xxx' ` clause, which fetches from ` GET /jwt_templates/{template_id} ` endpoint
327334
328335### OAuth Applications
329336
@@ -335,7 +342,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/OAuth-App
335342
336343| Object | Select | Insert | Update | Delete | Truncate |
337344| ------------------ | :----: | :----: | :----: | :----: | :------: |
338- | oauth_applications | ✅ | ❌ | ❌ | ❌ | ❌ |
345+ | oauth_applications | ✅ | ✅ | ✅ | ✅ | ❌ |
339346
340347#### Usage
341348
@@ -353,13 +360,15 @@ create foreign table clerk.oauth_applications (
353360)
354361 server clerk_server
355362 options (
356- object ' oauth_applications'
363+ object ' oauth_applications' ,
364+ rowid_column ' id'
357365 );
358366```
359367
360368#### Notes
361369
362370- The ` attrs ` column contains additional attributes in JSON format
371+ - Single-item retrieval is supported via ` WHERE id = 'xxx' ` clause, which fetches from ` GET /oauth_applications/{oauth_application_id} ` endpoint
363372
364373### Organizations
365374
@@ -371,7 +380,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/Organizat
371380
372381| Object | Select | Insert | Update | Delete | Truncate |
373382| ------------- | :----: | :----: | :----: | :----: | :------: |
374- | organizations | ✅ | ❌ | ❌ | ❌ | ❌ |
383+ | organizations | ✅ | ✅ | ✅ | ✅ | ❌ |
375384
376385#### Usage
377386
@@ -386,13 +395,15 @@ create foreign table clerk.organizations (
386395)
387396 server clerk_server
388397 options (
389- object ' organizations'
398+ object ' organizations' ,
399+ rowid_column ' id'
390400 );
391401```
392402
393403#### Notes
394404
395405- The ` attrs ` column contains additional attributes in JSON format
406+ - Single-item retrieval is supported via ` WHERE id = 'xxx' ` clause, which fetches from ` GET /organizations/{organization_id} ` endpoint
396407
397408### Organization Invitations
398409
@@ -462,6 +473,7 @@ create foreign table clerk.organization_memberships (
462473#### Notes
463474
464475- The ` attrs ` column contains additional attributes in JSON format
476+ - Single-item retrieval is supported via ` WHERE id = 'xxx' ` clause, which fetches from ` GET /oauth_applications/{oauth_application_id} ` endpoint
465477
466478### Redirect URLs
467479
@@ -473,7 +485,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/Redirect-
473485
474486| Object | Select | Insert | Update | Delete | Truncate |
475487| ------------- | :----: | :----: | :----: | :----: | :------: |
476- | redirect_urls | ✅ | ❌ | ❌ | ❌ | ❌ |
488+ | redirect_urls | ✅ | ✅ | ❌ | ✅ | ❌ |
477489
478490#### Usage
479491
@@ -487,13 +499,15 @@ create foreign table clerk.redirect_urls (
487499)
488500 server clerk_server
489501 options (
490- object ' redirect_urls'
502+ object ' redirect_urls' ,
503+ rowid_column ' id'
491504 );
492505```
493506
494507#### Notes
495508
496509- The ` attrs ` column contains additional attributes in JSON format
510+ - Single-item retrieval is supported via ` WHERE id = 'xxx' ` clause, which fetches from ` GET /redirect_urls/{id} ` endpoint
497511
498512### SAML Connections
499513
@@ -505,7 +519,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/SAML-Conn
505519
506520| Object | Select | Insert | Update | Delete | Truncate |
507521| ---------------- | :----: | :----: | :----: | :----: | :------: |
508- | saml_connections | ✅ | ❌ | ❌ | ❌ | ❌ |
522+ | saml_connections | ✅ | ✅ | ✅ | ✅ | ❌ |
509523
510524#### Usage
511525
@@ -523,13 +537,15 @@ create foreign table clerk.saml_connections (
523537)
524538 server clerk_server
525539 options (
526- object ' saml_connections'
540+ object ' saml_connections' ,
541+ rowid_column ' id'
527542 );
528543```
529544
530545#### Notes
531546
532547- The ` attrs ` column contains additional attributes in JSON format
548+ - Single-item retrieval is supported via ` WHERE id = 'xxx' ` clause, which fetches from ` GET /saml_connections/{saml_connection_id} ` endpoint
533549
534550### Users
535551
@@ -541,7 +557,7 @@ Ref: [Clerk API docs](https://clerk.com/docs/reference/backend-api/tag/Users#ope
541557
542558| Object | Select | Insert | Update | Delete | Truncate |
543559| ------ | :----: | :----: | :----: | :----: | :------: |
544- | users | ✅ | ❌ | ❌ | ❌ | ❌ |
560+ | users | ✅ | ✅ | ✅ | ✅ | ❌ |
545561
546562#### Usage
547563
@@ -558,13 +574,15 @@ create foreign table clerk.users (
558574)
559575 server clerk_server
560576 options (
561- object ' users'
577+ object ' users' ,
578+ rowid_column ' id'
562579 );
563580```
564581
565582#### Notes
566583
567584- The ` attrs ` column contains additional attributes in JSON format
585+ - Single-item retrieval is supported via ` WHERE id = 'xxx' ` clause, which fetches from ` GET /users/{user_id} ` endpoint
568586
569587### User Billing Subscriptions
570588
@@ -806,7 +824,41 @@ create foreign table clerk.billing_payment_attempts (
806824
807825## Query Pushdown Support
808826
809- This FDW doesn't support query pushdown.
827+ ### ` where ` clause pushdown
828+
829+ This FDW supports ` where id = 'xxx' ` clause pushdown for the following objects:
830+
831+ - users
832+ - organizations
833+ - jwt_templates
834+ - oauth_applications
835+ - saml_connections
836+ - redirect_urls
837+
838+ For example:
839+
840+ ``` sql
841+ -- Fetches from GET /users/user_xxx (single API call)
842+ select * from clerk .users where id = ' user_xxx' ;
843+ ```
844+
845+ ### Parameterized endpoints
846+
847+ Some endpoints require specific qualifiers in the WHERE clause:
848+
849+ | Object | Required qualifier |
850+ | --------| -------------------|
851+ | user_billing_subscriptions | ` user_id ` |
852+ | organization_billing_subscriptions | ` organization_id ` |
853+ | billing_statement | ` statement_id ` |
854+ | billing_payment_attempts | ` statement_id ` |
855+
856+ For example:
857+
858+ ``` sql
859+ -- Fetches from GET /users/{user_id}/billing/subscription
860+ select * from clerk .user_billing_subscriptions where user_id = ' user_xxx' ;
861+ ```
810862
811863## Supported Data Types
812864
@@ -826,7 +878,6 @@ The Clerk API uses JSON formatted data, please refer to [Clerk Backend API docs]
826878This section describes important limitations and considerations when using this FDW:
827879
828880- Large result sets may experience slower performance due to full data transfer requirement
829- - Query pushdown is not supported
830881- Materialized views using these foreign tables may fail during logical backups
831882
832883## Examples
@@ -850,11 +901,15 @@ create foreign table clerk.users (
850901)
851902 server clerk_server
852903 options (
853- object ' users'
904+ object ' users' ,
905+ rowid_column ' id'
854906 );
855907
856- -- query all users
908+ -- query all users (fetches from GET /users)
857909select * from clerk .users ;
910+
911+ -- retrieve a specific user by ID (fetches from GET /users/{user_id})
912+ select * from clerk .users where id = ' user_xxx' ;
858913```
859914
860915` attrs ` is a special column which stores all the object attributes in JSON format, you can extract any attributes needed from it. See more examples below.
@@ -870,6 +925,30 @@ from clerk.users u
870925 cross join json_array_elements((attrs- > ' email_addresses' )::json) e;
871926```
872927
928+ ### Data Modify Examples
929+
930+ Some tables support INSERT, UPDATE, and DELETE operations. Use the ` attrs ` JSONB column to provide the request body:
931+
932+ ``` sql
933+ -- Create a new user
934+ INSERT INTO clerk .
users (attrs)
VALUES (
' {"email_address": ["[email protected] "], "password": "secure123"}' );
935+
936+ -- Update a user (requires rowid_column 'id')
937+ UPDATE clerk .users SET attrs = ' {"first_name": "John", "last_name": "Doe"}' WHERE id = ' user_xxx' ;
938+
939+ -- Delete a user (requires rowid_column 'id')
940+ DELETE FROM clerk .users WHERE id = ' user_xxx' ;
941+
942+ -- Create a new organization
943+ INSERT INTO clerk .organizations (attrs) VALUES (' {"name": "My Organization", "slug": "my-org"}' );
944+
945+ -- Update an organization
946+ UPDATE clerk .organizations SET attrs = ' {"name": "Updated Name"}' WHERE id = ' org_xxx' ;
947+
948+ -- Delete an organization
949+ DELETE FROM clerk .organizations WHERE id = ' org_xxx' ;
950+ ```
951+
873952### Billing examples
874953
875954``` sql
@@ -893,4 +972,22 @@ SELECT * FROM clerk.user_billing_subscriptions WHERE user_id = 'user_xxx';
893972
894973-- Query subscription for a specific organization (requires WHERE clause)
895974SELECT * FROM clerk .organization_billing_subscriptions WHERE organization_id = ' org_xxx' ;
975+
976+ -- Retrieve a single user by ID (fetches from GET /users/{user_id})
977+ SELECT * FROM clerk .users WHERE id = ' user_xxx' ;
978+
979+ -- Retrieve a single organization by ID (fetches from GET /organizations/{organization_id})
980+ SELECT * FROM clerk .organizations WHERE id = ' org_xxx' ;
981+
982+ -- Retrieve a single JWT template by ID (fetches from GET /jwt_templates/{template_id})
983+ SELECT * FROM clerk .jwt_templates WHERE id = ' tmpl_xxx' ;
984+
985+ -- Retrieve a single OAuth application by ID (fetches from GET /oauth_applications/{oauth_application_id})
986+ SELECT * FROM clerk .oauth_applications WHERE id = ' oauth_xxx' ;
987+
988+ -- Retrieve a single SAML connection by ID (fetches from GET /saml_connections/{saml_connection_id})
989+ SELECT * FROM clerk .saml_connections WHERE id = ' samlconn_xxx' ;
990+
991+ -- Retrieve a single redirect URL by ID (fetches from GET /redirect_urls/{id})
992+ SELECT * FROM clerk .redirect_urls WHERE id = ' redir_xxx' ;
896993```
0 commit comments