In dart, I turn my `DataModel` into a json documen...
# help
m
In dart, I turn my
DataModel
into a json document using a
toMap()
method defined by me. I pass that document to the insert statement like this:
Copy code
dart
addTransaction(DataModel data) {
    var response = _databaseService
        .insert(
          data.toMap(),
        )
        .execute();
    return response;
  }
I want to do the same thing but in a
Stored Procedure
like this:
Copy code
dart
addTransaction(DataModel data) {
    var response = _databaseService
        .rpc(
          data.toMap(),
        )
        .execute();
    return response;
  }
What would be the name of the object type while defining this function? I cannot find json in the intellisense. The reason I want to do this is to be able to add some data from the json document in one table and the rest of the data in another table in one go.
n
Hello @Muezz! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
v
which exact function do you mean? In
dart
or in
postgres
?
n
wubba_lubba_whatever (2022-04-16)
m
I mean the
Stored Procedure
that can be executed directly from dart using the
rpc
command i.e. the one written in
plpgsql
you have to define the
type
of the argument.
v
jsonb
m
lemme see
v
Doesn't need your dart code the name of the function? You only pass the arguments.
m
yes. But when I am defining the function within Supabase, I have to explicitly tell the type of the argument it will be getting.
v
I know, but
jsonb
is listed there, isn't it?
m
currently I am trying to test the function directly in the SQL Editor and the intellisense doesnt show
jsonb
v
try nevertheless. It will throw a type on function creation, if it doesn't exist
m
I am trying to check. gimme a couple mins
@Vinzent In normal
plpgsql
INSERT
calls, you have to define the values you will be inserting as well as the names of the columns that will be getting those values. How do I make the
INSERT
call figure out on its own that it is getting a json doc where the keys are the column names and the values are the values that need to be inserted?
This is what a normal
INSERT
call looks like
v
Are you interpreting the error message that way?
m
What do you mean?
v
the error comes from line 10 ( I guess, because you cannot return a table that way)
m
I think the error comes from line 8 because sql thinks that it is a variable that should have been declared earlier and it is not. It does not know that it is a table because I did not insert using the conventional method.
v
I think that's the answer https://stackoverflow.com/a/26742370
m
This did not work too
But this defeats the purpose as I am gonna end up 10 or more column names and values anyway