Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Jan 3, 2024
1 parent 76914d6 commit 8e75d36
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 9 deletions.
86 changes: 86 additions & 0 deletions backend/files/misc/workflows/actions/sql/sql-delete.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

/*
* Invokes the SQL CRUD Delete slot with the specified parameters.
*
* Provide [connection-string], [database-type], [database], and [table] to inform the action of
* what database/table you want to execute your SQL towards, and add [and] or [or] arguments
* to filter your records. Notice, you can only use one of [or] or [and], and not both.
*/
.arguments
database-type
type:enum
mandatory:bool:true
values
.:sqlite
.:mssql
.:mysql
.:pgsql
connection-string
type:string
mandatory:bool:true
database
type:string
mandatory:bool:true
table
type:string
mandatory:bool:true
and
type:key-value
mandatory:bool:false
or
type:key-value
mandatory:bool:false
.icon:cloud_download

// Sanity checking invocation.
validators.mandatory:x:@.arguments/*/table
validators.enum:x:@.arguments/*/database-type
.:sqlite
.:mssql
.:mysql
.:pgsql

// Applying defaults.
validators.default:x:@.arguments
connection-string:generic
database-type:sqlite
database:magic

// Ensuring user provided either [or] or [and] and not both.
if
and
exists:x:@.arguments/*/or/*
exists:x:@.arguments/*/and/*
.lambda

throw:Provide either [or] or [and] to sql-read action, and not both
public:bool:true
status:500

// Connection string to actually use as we connect.
.connection-string

// Caller supplied an explicit [connection-string] argument.
set-value:x:@.connection-string
strings.concat
.:[
get-value:x:@.arguments/*/connection-string
.:|
get-value:x:@.arguments/*/database
.:]

// Connecting to database.
data.connect:x:@.connection-string
database-type:x:@.arguments/*/database-type

// Adding [or] or [and] arguments.
add:x:@data.connect/*/data.delete/*/where
get-nodes:x:@.arguments/*/or
get-nodes:x:@.arguments/*/and

// Executing SQL.
data.delete:x:@.arguments/*/sql
database-type:x:@.arguments/*/database-type
table:x:@.arguments/*/table
where
return-nodes:x:@data.delete
21 changes: 13 additions & 8 deletions backend/files/misc/workflows/actions/sql/sql-read.hl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
*
* Provide [connection-string], [database-type], [database], and [table] to inform the action of
* what database/table you want to execute your SQL towards, and add [and] or [or] arguments
* to filter your returns, in addition to [limit] and [offset] to apply paging.
* to filter your returns, in addition to [limit] and [offset] to apply paging. Use [order]
* and [direction] to sort either ascending or descending. Notice, you can only use one of [or]
* or [and], and not both.
*/
.arguments
database-type
Expand All @@ -23,7 +25,7 @@
mandatory:bool:true
table
type:string
mandatory:true
mandatory:bool:true
and
type:key-value
mandatory:bool:false
Expand All @@ -32,16 +34,19 @@
mandatory:bool:false
limit
type:int
mandatory:false
mandatory:bool:false
offset
type:int
mandatory:false
mandatory:bool:false
order
type:string
mandatory:false
mandatory:bool:false
direction
type:string
mandatory:false
type:enum
mandatory:bool:false
values
.:asc
.:desc
.icon:cloud_download

// Sanity checking invocation.
Expand Down Expand Up @@ -85,7 +90,7 @@ set-value:x:@.connection-string
data.connect:x:@.connection-string
database-type:x:@.arguments/*/database-type

// Adding [limit] and [offset] arguments.
// Adding [limit], [offset], [order] and [direction] arguments.
add:x:./*/data.read
get-nodes:x:@.arguments/*/limit
get-nodes:x:@.arguments/*/offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,23 @@ export class FormlyAutocompleteComponent extends FieldType<FieldTypeConfig> impl
})).subscribe();
}
} else if (this.field.key === 'table') {
if (this.form.controls['database-type'] && this.form.controls['connection-string'] && this.form.controls['table']) {
if (this.form.controls['database-type'] && this.form.controls['connection-string'] && this.form.controls['database']) {
this.form.controls['database'].valueChanges.pipe(
debounceTime(400),
distinctUntilChanged(),
tap(() => {
this.getTables();
})).subscribe();
}
} else if (this.field.key === 'order') {
if (this.form.controls['database-type'] && this.form.controls['connection-string'] && this.form.controls['database'] && this.form.controls['table']) {
this.form.controls['table'].valueChanges.pipe(
debounceTime(400),
distinctUntilChanged(),
tap(() => {
this.getColumns();
})).subscribe();
}
}
}

Expand Down Expand Up @@ -205,6 +214,47 @@ export class FormlyAutocompleteComponent extends FieldType<FieldTypeConfig> impl
});
}

private getColumns() {

if (!this.model['database-type'] || this.model['database-type'] === '' ||
!this.model['connection-string'] || this.model['connection-string'] === '' ||
!this.model['database'] || this.model['database'] === '' ||
!this.model['table'] || this.model['table'] === '') {
return;
}

this.generalService.showLoading();
this.sqlService.getDatabaseMetaInfo(
<string>this.model['database-type'],
<string>this.model['connection-string']).subscribe({

next: (result: any) => {

this.generalService.hideLoading();
const db = result.databases.filter((x: any) => x.name === <string>this.model['database'])[0];
const table = db.tables.filter(x => x.name === <string>this.model['table'])[0];
const expOptions = (<any[]>this.field.props.options).filter(x => x.value.startsWith(':x:'));
this.field.props.options = [];
for (const idx of table.columns) {
this.field.props.options.push({
value: idx.name,
label: idx.name,
complete: true,
});
}
for (const idx of expOptions) {
this.field.props.options.push(idx);
}
this.formControl.setValue('');
},

error: () => {

this.generalService.hideLoading();
}
});
}

private _filter(value: string): any[] {

if (!value) {
Expand Down

0 comments on commit 8e75d36

Please sign in to comment.