Copying data from one table to another table in supabase.

Database & APIs

Please can someone explain how data can be copied from one table to another table in supabase + FF. I have two tables CART and ORDERS, on the checkout page i'd like to move the products on the CART table to a specific list column on the ORDER table with the name Cart_details. Please can someone help, i have been trying to achieve this for weeks now.

What have you tried so far?

I tried creating an action but its still not working

// Import the required library

import 'package:supabase/supabase.dart';

// Define the custom action function

Future<void> copyTableDataToList(SupabaseClient supabase, String sourceTable, String destinationTable, String destinationListField, String destinationRowId) async {

// Reference the source table

final sourceTableRef = supabase.from(sourceTable);

// Get all documents from the source table

final sourceData = await sourceTableRef.select('*').execute();

// Check if any documents were found

if (sourceData.error != null || sourceData.data.isEmpty) {

return; // Nothing to copy

}

// List to store copied data

final copiedDataList = sourceData.data as List;

// Reference the destination table document

final destinationTableRef = supabase.from(destinationTable).eq('id', destinationRowId);

// Update the destination document with the copied data list

await destinationTableRef.update({

destinationListField: copiedDataList,

});

}

Did you check FlutterFlow's Documentation for this topic?
No
1
1 reply