Orb
Orb is a metering and pricing platform built to support usage-based billing models.
The Orb Wrapper is a WebAssembly(Wasm) foreign data wrapper which allows you to read data from Orb for use within your Postgres database.
Available Versions
Version | Wasm Package URL | Checksum |
---|---|---|
0.1.0 | https://github.com/supabase/wrappers/releases/download/wasm_orb_fdw_v0.1.0/orb_fdw.wasm |
89153a0a570257c231b78561cc909766731c828324585a5b6e2aa553902cb73a |
Preparation
Before you can query Orb, you need to enable the Wrappers extension and store your credentials in Postgres.
Enable Wrappers
Make sure the wrappers
extension is installed on your database:
1 |
|
Enable the Orb Wrapper
Enable the Wasm foreign data wrapper:
1 2 3 |
|
Store your credentials (optional)
By default, Postgres stores FDW credentials inside pg_catalog.pg_foreign_server
in plain text. Anyone with access to this table will be able to view these credentials. Wrappers is designed to work with Vault, which provides an additional level of security for storing credentials. We recommend using Vault to store your credentials.
1 2 3 4 5 6 7 |
|
Connecting to Orb
We need to provide Postgres with the credentials to access Orb and any additional options. We can do this using the create server
command:
1 2 3 4 5 6 7 8 9 10 |
|
1 2 3 4 5 6 7 8 9 10 |
|
Note the fdw_package_*
options are required, which specify the Wasm package metadata. You can get the available package version list from above.
Create a schema
We recommend creating a schema to hold all the foreign tables:
1 |
|
Options
The full list of foreign table options are below:
object
- Object name in Orb, required.
Supported objects are listed below:
Object name |
---|
alerts |
coupons |
credit_notes |
customers |
credits |
credits_ledger |
dimensional_price_groups |
events_backfills |
events_volume |
invoices |
items |
metrics |
plans |
prices |
subscriptions |
rowid_column
- Primary key column name, optional for data scan, required for data modify
Entities
Alert
This is a list of all alerts within Orb.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
alerts | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Notes
- The
attrs
column contains additional attributes in JSON format - The query must specify one of
customer_id
,external_customer_id
, orsubscription_id
Coupon
This is a list of all coupons for an account.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
coupons | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Credit Note
This is a list of all CreditNotes.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
credit_notes | ✅ | ✅ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Customer
This is a list of all customers for an account.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
customers | ✅ | ✅ | ✅ | ✅ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Credit
This is a list of unexpired, non-zero credit blocks for a customer.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
credits | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Notes
- The
attrs
column contains additional attributes in JSON format - The query must specify one of
customer_id
orexternal_customer_id
Credits ledger
This is a list of actions that have taken place to modify a customer’s credit balance.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
credits/ledger | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Notes
- The
attrs
column contains additional attributes in JSON format - The query must specify one of
customer_id
orexternal_customer_id
Dimensional Price Group
This is a list of dimensional price groups.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
dimensional_price_groups | ✅ | ✅ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Event Backfill
This is a list of all event backfills.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
events/backfills | ✅ | ✅ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Event Volume
This returns the event volume for an account.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
events/volume | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Invoice
This is a list of invoices for an account.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
invoices | ✅ | ✅ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Item
This is a list of all items.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
items | ✅ | ✅ | ✅ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Metric
This is a list of metric details.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
metrics | ✅ | ✅ | ✅ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Plan
This is a list of all plans for an account.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
plans | ✅ | ✅ | ✅ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Price
This is a list of all add-on prices.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
prices | ✅ | ✅ | ✅ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Subscription
This is a list of all subscriptions for an account.
Ref: Orb API docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
subscriptions | ✅ | ✅ | ✅ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Notes
- The
attrs
column contains additional attributes in JSON format
Query Pushdown Support
where
clause pushdown
This FDW supports where id = 'xxx'
clause pushdown for below objects:
- Coupon
- Credit Note
- Customer
- Dimensional Price Group
- Event Backfill
- Invoice
- Item
- Metric
- Plan
- Price
- Subscription
Some other supported where
clauses pushdown are listed below:
Alert
For example, where customer_id = 'WmUkxWmvLvvXHaNV'
.
- customer_id, (operations:
=
) - external_customer_id, (operations:
=
) - subscription_id, (operations:
=
)
Customer
For example, where created_at >= '2025-02-15T10:25:36'
.
- created_at, (operations:
<
,<=
,>
,>=
)
Event Volume
For example, where timeframe_start = '2025-02-15'
.
- timeframe_start, (operations:
=
)
Invoice
For example, where status = 'paid'
.
- customer_id, (operations:
=
) - external_customer_id, (operations:
=
) - subscription_id, (operations:
=
) - status, (operations:
=
) - due_date, (operations:
=
,<
,>
) - created_at, (operations:
<
,<=
,>
,>=
)
Subscription
For example, where status = 'active'
.
- customer_id, (operations:
=
) - external_customer_id, (operations:
=
) - status, (operations:
=
) - created_at, (operations:
<
,<=
,>
,>=
)
limit
clause pushdown
This FDW supports limit
clause pushdown for all the objects. For example,
1 |
|
Supported Data Types
Postgres Data Type | Orb Data Type |
---|---|
boolean | Boolean |
bigint | Number |
numeric | Number |
text | String |
timestamp | Time |
jsonb | Json |
The Orb API uses JSON formatted data, please refer to Orb API docs for more details.
Limitations
This section describes important limitations and considerations when using this FDW:
- Large result sets may experience slower performance due to full data transfer requirement
- Materialized views using these foreign tables may fail during logical backups
Examples
Below are some examples on how to use Orb foreign tables.
Basic example
This example will create a "foreign table" inside your Postgres database and query its data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
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.
Query JSON attributes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Data Modify Example
This example will modify data in a "foreign table" inside your Postgres database, note that rowid_column
foreign table option is mandatory for data modify. Data modify is done through the attrs
jsonb column, which will be posted as request body to Orb API endpoint. Please refer to Orb API reference docs for the JSON request details.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|