-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
194 additions
and
19 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
crates/cmds-std/node-definitions/postgrest/new_rpc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ | ||
"type": "native", | ||
"data": { | ||
"node_definition_version": "0.1", | ||
"unique_id": "", | ||
"node_id": "postgrest_new_rpc", | ||
"version": "0.1", | ||
"display_name": "New RPC", | ||
"description": "https://docs.rs/postgrest/latest/postgrest/struct.Postgrest.html#method.rpc", | ||
"tags": ["database", "postgrest", "supabase"], | ||
"related_to": [ | ||
{ | ||
"id": "", | ||
"type": "", | ||
"relationship": "" | ||
} | ||
], | ||
"resources": { | ||
"source_code_url": "", | ||
"documentation_url": "" | ||
}, | ||
"usage": { | ||
"license": "Apache-2.0", | ||
"license_url": "", | ||
"pricing": { | ||
"currency": "USDC", | ||
"purchase_price": 0, | ||
"price_per_run": 0, | ||
"custom": { | ||
"unit": "monthly", | ||
"value": "0" | ||
} | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Space Operator", | ||
"contact": "" | ||
} | ||
], | ||
"design": { | ||
"width": 0, | ||
"height": 0, | ||
"icon_url": "", | ||
"backgroundColorDark": "#000000", | ||
"backgroundColor": "#fff" | ||
}, | ||
"options": {} | ||
}, | ||
"targets": [ | ||
{ | ||
"name": "url", | ||
"type_bounds": ["string"], | ||
"required": false, | ||
"defaultValue": "https://base.spaceoperator.com/rest/v1/", | ||
"tooltip": "", | ||
"passthrough": false | ||
}, | ||
{ | ||
"name": "schema", | ||
"type_bounds": ["string"], | ||
"required": false, | ||
"defaultValue": "public", | ||
"tooltip": "", | ||
"passthrough": false | ||
}, | ||
{ | ||
"name": "function", | ||
"type_bounds": ["string"], | ||
"required": true, | ||
"defaultValue": null, | ||
"tooltip": "", | ||
"passthrough": false | ||
}, | ||
{ | ||
"name": "params", | ||
"type_bounds": ["free"], | ||
"required": true, | ||
"defaultValue": null, | ||
"tooltip": "", | ||
"passthrough": false | ||
} | ||
], | ||
"sources": [ | ||
{ | ||
"name": "quey", | ||
"type": "object", | ||
"defaultValue": "", | ||
"tooltip": "" | ||
} | ||
], | ||
"targets_form.json_schema": { | ||
"type": "object", | ||
"title": "New RPC", | ||
"properties": { | ||
"table": { | ||
"title": "table", | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"targets_form.ui_schema": { | ||
"ui:order": ["table"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ pub mod builder_select; | |
pub mod builder_update; | ||
pub mod execute_query; | ||
pub mod new_query; | ||
pub mod new_rpc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use flow_lib::command::prelude::*; | ||
|
||
const NAME: &str = "postgrest_new_rpc"; | ||
|
||
#[derive(Deserialize, Debug)] | ||
struct Input { | ||
url: Option<String>, | ||
schema: Option<String>, | ||
function: String, | ||
params: JsonValue, | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
struct Output { | ||
query: postgrest::Builder, | ||
} | ||
|
||
async fn run(ctx: Context, input: Input) -> Result<Output, CommandError> { | ||
let url = input | ||
.url | ||
.unwrap_or_else(|| format!("{}/rest/v1", ctx.endpoints.supabase)); | ||
let mut pg = postgrest::Postgrest::new(url); | ||
if let Some(schema) = input.schema { | ||
pg = pg.schema(schema); | ||
} | ||
let query = pg.rpc(input.function, serde_json::to_string(&input.params)?); | ||
Ok(Output { query }) | ||
} | ||
|
||
fn build() -> BuildResult { | ||
Ok( | ||
CmdBuilder::new(flow_lib::node_definition!("postgrest/new_rpc.json"))? | ||
.check_name(NAME)? | ||
.build(run), | ||
) | ||
} | ||
|
||
flow_lib::submit!(CommandDescription::new(NAME, |_| build())); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_build() { | ||
build().unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters