Skip to content

Commit 4c2001a

Browse files
authored
Merge pull request #300 from supabase/bo/docs/stripe-insert
docs(stripe): add example for data insertion
2 parents bef35e8 + 8372a9e commit 4c2001a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/stripe.md

+27
Original file line numberDiff line numberDiff line change
@@ -845,3 +845,30 @@ update stripe.customers set description='hello fdw' where id ='cus_xxx';
845845
update stripe.customers set attrs='{"metadata[foo]": "bar"}' where id ='cus_xxx';
846846
delete from stripe.customers where id ='cus_xxx';
847847
```
848+
849+
To insert into an object with sub-fields, we need to create the foreign table with column name exactly same as the API required. For example, to insert a `subscription` object we can define the foreign table following [the Stripe API docs](https://docs.stripe.com/api/subscriptions/create):
850+
851+
```sql
852+
-- create the subscription table for data insertion, the 'customer'
853+
-- and 'items[0][price]' fields are required.
854+
create foreign table stripe.subscriptions (
855+
id text,
856+
customer text,
857+
"items[0][price]" text -- column name will be used in API Post request
858+
)
859+
server stripe_server
860+
options (
861+
object 'subscriptions',
862+
rowid_column 'id'
863+
);
864+
```
865+
866+
And then we can insert a subscription like below:
867+
868+
```sql
869+
insert into stripe.subscriptions (customer, "items[0][price]")
870+
values ('cus_Na6dX7aXxi11N4', 'price_1MowQULkdIwHu7ixraBm864M');
871+
```
872+
873+
Note this foreign table is only for data insertion, it cannot be used in `select` statement.
874+

0 commit comments

Comments
 (0)