mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-05 00:03:08 +00:00
900a8d675e
* feat: init database triggers * feat: ✨ wip: database_triggers * feat: ✨ add database triggers front view * feat: 🚧 database_triggers * feat: 🚧 add definition in yaml, updated backend code and added migration * feat: 🚧 updated migration file, update openapi.yml, updated database_triggers page and backend function * fix: struct rust * feat: 🚧 update migrate, database trigger backend function fixed * feat: 🚧 add resource picker front, update backend function * feat: 🚧 edit inner database inner, update triggers * feat: 🚧 database_triggers * feat: 🚧 update openapi yaml, prettied websocker trigger * feat: 🚧 database_triggers * feat: 🚧 add resource module, update variable file, working on main loop for database_trigger * feat: 🐛 working sqlx query * feat: 🚧 fix query with sqlx, added main loop * feat: 🚧 add new column database_trigg * feat: 🛂 run jobs works * feat: 🚧 handling slot name and replication * feat: restructring triggers, decoding trigger message on work * feat: 🚧 database_trigger * feat: 🚧 * feat: 🚧 converter done, work on custom script * feat: 🚧 multiple trigger * feat: 🚧 adding new argument function * feat: 🚧 database_trigger * feat: 🚧 add generate template for front, update script picker * feat: 🚧 template script fix bug, work on restructing backend logic * feat: 🚧 update autogenerated script, add persistence state for template script * feat: 🚧 update structure client * feat: 🚧 rewrited crud function * feat: 🚧 added publication handler * feat: 🚧 new ui finished * feat: 🚧 added slot function hanlder finish front ux * feat: ✨ ux improvement done, backend logic done * feat: 🐛 fix where clause * feat: * feat: * chore: update .sqlx and remove empty package * fix: update publication and remove unneccessary print * feat: finish converter to json, remove save button, remove unused crate * feat: update migration for database trigger, fixed query, fixed frontend error with missing feature on back * chore: update .sqlx * chore: update sqlx * chore: .sqlx * chore: add unused * fix: use right database resource in back and front * fix build * refactor: * fix sqlx * nits: retrieve all script from database trigger editor * fix: template script object, fix route name * merge main * feat: rework ux * feat/finish ux and update backend logic * feat: database_trigger * feat: database_trigger * chore: update sqlx * chore: fix ci * nits: fix worker.rs * feat: database_trigger * Update frontend/src/lib/components/triggers/database/DatabaseTriggersPanel.svelte Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * feat: * fix ci * nits: database to postgres * nits: fix .sqlx * feat: add link to original code and open tab functionallity * nits: update .sqlx * nits: fix request type and yaml file * nits: add abel suggestion * fix: update .sqlx * fix: update .sqlx * nits: add comment to hex.rs * nits: remove features, rename database to postgres name * nits: replace database name by postgres * nits: database name to postgres * nits: update .sqlx * nits: update .sqlx * nit * nit * nits * nit * nits * nits * nits * nits * fix sqlx * nits: update .vscode --------- Co-authored-by: HugoCasa <hugo@casademont.ch> Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
135 lines
4.2 KiB
Rust
135 lines
4.2 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use rust_postgres::types::Type;
|
|
|
|
use super::handler::Language;
|
|
|
|
fn postgres_to_typescript_type(postgres_type: Option<Type>) -> String {
|
|
let data_type = match postgres_type {
|
|
Some(postgres_type) => match postgres_type {
|
|
Type::BOOL => "boolean",
|
|
Type::BOOL_ARRAY => "Array<boolean>",
|
|
Type::CHAR | Type::BPCHAR | Type::VARCHAR | Type::NAME | Type::TEXT => "string",
|
|
Type::CHAR_ARRAY
|
|
| Type::BPCHAR_ARRAY
|
|
| Type::VARCHAR_ARRAY
|
|
| Type::NAME_ARRAY
|
|
| Type::TEXT_ARRAY => "Array<string>",
|
|
Type::INT2 | Type::INT4 | Type::INT8 | Type::NUMERIC => "number",
|
|
Type::INT2_ARRAY | Type::INT4_ARRAY | Type::INT8_ARRAY => "Array<number>",
|
|
Type::FLOAT4 | Type::FLOAT8 => "number",
|
|
Type::FLOAT8_ARRAY | Type::FLOAT4_ARRAY => "Array<number>",
|
|
Type::NUMERIC_ARRAY => "Array<number>",
|
|
Type::BYTEA => "Array<number>",
|
|
Type::BYTEA_ARRAY => "Array<Array<number>>",
|
|
Type::DATE => "string",
|
|
Type::DATE_ARRAY => "Array<string>",
|
|
Type::TIME => "string",
|
|
Type::TIME_ARRAY => "Array<string>",
|
|
Type::TIMESTAMPTZ | Type::TIMESTAMP => "Date",
|
|
Type::TIMESTAMPTZ_ARRAY | Type::TIMESTAMP_ARRAY => "Array<Date>",
|
|
Type::UUID => "string",
|
|
Type::UUID_ARRAY => "Array<string>",
|
|
Type::JSON | Type::JSONB | Type::JSON_ARRAY | Type::JSONB_ARRAY => "unknown",
|
|
Type::OID => "number",
|
|
Type::OID_ARRAY => "Array<number>",
|
|
_ => "string",
|
|
},
|
|
None => "string",
|
|
};
|
|
|
|
data_type.to_string()
|
|
}
|
|
|
|
fn into_body_struct(language: Language, mapped_info: Vec<MappingInfo>) -> String {
|
|
let mut block = String::new();
|
|
match language {
|
|
Language::Typescript => {
|
|
block.push_str("{\r\n");
|
|
for field in mapped_info {
|
|
let typescript_type = postgres_to_typescript_type(field.data_type);
|
|
let mut key = field.column_name;
|
|
if field.is_nullable {
|
|
key.push('?');
|
|
}
|
|
let full_field = format!("\t\t{}: {},\r\n", key, typescript_type);
|
|
block.push_str(&full_field);
|
|
}
|
|
block.push_str("\t}");
|
|
}
|
|
}
|
|
block
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct MappingInfo {
|
|
data_type: Option<Type>,
|
|
is_nullable: bool,
|
|
column_name: String,
|
|
}
|
|
|
|
impl MappingInfo {
|
|
pub fn new(column_name: String, data_type: Option<Type>, is_nullable: bool) -> Self {
|
|
Self { column_name, data_type, is_nullable }
|
|
}
|
|
}
|
|
|
|
pub struct Mapper {
|
|
to_template: HashMap<String, HashMap<String, Vec<MappingInfo>>>,
|
|
language: Language,
|
|
}
|
|
|
|
impl Mapper {
|
|
pub fn new(
|
|
to_template: HashMap<String, HashMap<String, Vec<MappingInfo>>>,
|
|
language: Language,
|
|
) -> Self {
|
|
Self { to_template, language }
|
|
}
|
|
|
|
fn into_typescript_template(self) -> Vec<String> {
|
|
let mut struct_definitions = Vec::new();
|
|
for (_, mapping_info) in self.to_template {
|
|
let last_elem = mapping_info.len() - 1;
|
|
for (i, (_, mapped_info)) in mapping_info.into_iter().enumerate() {
|
|
let mut struct_body = into_body_struct(Language::Typescript, mapped_info);
|
|
let struct_body = if i != last_elem {
|
|
struct_body.push_str("\r\n");
|
|
struct_body
|
|
} else {
|
|
struct_body
|
|
};
|
|
struct_definitions.push(struct_body);
|
|
}
|
|
}
|
|
struct_definitions
|
|
}
|
|
|
|
pub fn get_template(self) -> String {
|
|
let struct_definition = match self.language {
|
|
Language::Typescript => self.into_typescript_template(),
|
|
};
|
|
|
|
let struct_definition = if struct_definition.is_empty() {
|
|
"any".to_string()
|
|
} else {
|
|
struct_definition.join("\t| ")
|
|
};
|
|
|
|
format!(
|
|
r#"
|
|
|
|
|
|
export async function main(
|
|
transaction_type: "insert" | "update" | "delete",
|
|
schema_name: string,
|
|
table_name: string,
|
|
row: {}
|
|
) {{
|
|
}}
|
|
"#,
|
|
struct_definition
|
|
)
|
|
}
|
|
}
|