Skip to content

Commit ebedb79

Browse files
committed
Downlooad SQL as CSV workflow
1 parent a9d3444 commit ebedb79

File tree

6 files changed

+122
-3
lines changed

6 files changed

+122
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,4 @@ backend/files/etc/cache/*
381381
deployment.apps/*
382382
backend/files/etc/stripe-subscription-templates/templates.hl
383383
backend/files/etc/hyperlambda-training-material/*
384+
/backend/files/etc/tmp

backend/files/misc/common-startup-files/default.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,27 @@ Arguments:
674674
* database - Mandatory database to connect to and execute SQL within.
675675
* database-type - Optional argument being database type. Can be either 'mysql', 'pgsql', 'mssql' or 'sqlite'. Defaults to 'sqlite'.
676676

677+
### Export SQL
678+
679+
Connects to the [database] database, and executes the specified [sql], for then to allow the frontend to download it as a CSV file. Use this function if the user tells you to export some database table, and/or specific SQL query as a CSV file.
680+
681+
___
682+
FUNCTION_INVOCATION[/misc/workflows/workflows/database/export-sql.hl]:
683+
{
684+
"sql": "[STRING_VALUE]",
685+
"database": "[STRING_VALUE]",
686+
"database-type": "[STRING_VALUE]"
687+
}
688+
___
689+
690+
Arguments:
691+
692+
* sql - Mandatory argument being SQL to execute, unless specifically overridden the dialect should be SQLite.
693+
* database - Mandatory database to connect to and execute SQL within.
694+
* database-type - Optional argument being database type. Can be either 'mysql', 'pgsql', 'mssql' or 'sqlite'. Defaults to 'sqlite'.
695+
696+
This function will signal the frontend once done, allowing the user to download the resulting CSV file. Use this function if the user asks you to export a database table, or some specific SQL to a CSV file.
697+
677698
### List databases
678699

679700
Lists all SQLite databases in the system
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
/*
3+
* Executes the specified [sql] and exports it as a CSV file
4+
*
5+
* Connects to [database] database, and executes the specified [sql], and exports the file as a CSV vile.
6+
*/
7+
.arguments
8+
9+
// Injected by the framework to identify the session.
10+
_session:string
11+
12+
// Mandatory argument being SQL to execute, unless specifically overridden the dialect should be SQLite
13+
sql:string
14+
15+
// Mandatory database to connect to and execute SQL within.
16+
database:string
17+
18+
// Optional argument being database type. Can be either 'mysql', 'pgsql', 'mssql' or 'sqlite'. Defaults to 'sqlite'.
19+
database-type:string
20+
21+
// Ensuring user is root.
22+
auth.ticket.verify:root
23+
24+
// Applying defaults.
25+
validators.default:x:@.arguments
26+
database-type:sqlite
27+
28+
// Sanity checking invocation.
29+
validators.mandatory:x:@.arguments/*/sql
30+
validators.mandatory:x:@.arguments/*/_session
31+
validators.mandatory:x:@.arguments/*/database
32+
log.info:x:@.arguments/*/sql
33+
database:x:@.arguments/*/database
34+
35+
// Parametrizing connect
36+
insert-before:x:./*/data.connect/0
37+
get-nodes:x:@.arguments/*/database-type
38+
39+
// Connecting to database
40+
data.connect:x:@.arguments/*/database
41+
42+
// Parametrizing connect
43+
add:x:./*/data.select
44+
get-nodes:x:@.arguments/*/database-type
45+
46+
// Executing SQL.
47+
data.select:x:@.arguments/*/sql
48+
49+
// Converting to CSV.
50+
lambda2csv:x:@data.select/*
51+
52+
// Saving to temp folder.
53+
.path:/etc/tmp/
54+
if
55+
not
56+
io.folder.exists:x:@.path
57+
.lambda
58+
io.folder.create:x:@.path
59+
set-value:x:@.path
60+
strings.concat
61+
get-value:x:@.path
62+
.:sql-export-
63+
crypto.random
64+
min:25
65+
max:25
66+
.:.csv
67+
io.file.save:x:@.path
68+
get-value:x:@lambda2csv
69+
70+
auth.ticket.create
71+
username:service
72+
roles
73+
.:root
74+
75+
// Signaling frontend that file can be downloaded
76+
sockets.signal:x:@.arguments/*/_session
77+
role:root
78+
args
79+
type:download_file
80+
ticket:x:@auth.ticket.create
81+
filename:x:@.path
82+
.
83+
84+
// Returning result to caller.
85+
yield
86+
rows:x:@data.select/*

backend/files/misc/workflows/workflows/database/select-sql.hl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Executes the specified [sql] and returns the result
44
*
5-
* Connect to [database] database, and executes the specified [sql], and returns all rows resulting from the SQL to caller.
5+
* Connects to [database] database, and executes the specified [sql], and returns all rows resulting from the SQL to caller.
66
*/
77
.arguments
88

frontend/src/app/components/protected/dashboard/components/vibe-coding/vibe-coding.component.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,20 @@
206206
}
207207

208208
::ng-deep .download_file {
209-
display: inline-block;
209+
display: block;
210210
border: solid 1px rgba(0,0,0,.1);
211211
border-radius: 5px;
212212
padding: 5px 25px;
213213
text-decoration: none;
214+
margin-left: auto;
215+
margin-right: auto;
216+
width: 200px;
217+
text-align: center;
218+
margin-top: 25px;
219+
margin-bottom: 25px;
220+
}
221+
222+
::ng-deep .hljs_ignore {
223+
margin-top: 25px;
224+
margin-bottom: 25px;
214225
}

frontend/src/app/components/protected/dashboard/components/vibe-coding/vibe-coding.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export class VibeCodingComponent implements OnInit, OnDestroy {
380380

381381
// Verifying we should not ignore this guy.
382382
let ignore = false;
383-
let idxEl = el
383+
let idxEl = el;
384384
while (idxEl) {
385385
if (idxEl.classList.contains('hljs_ignore')) {
386386
ignore = true;

0 commit comments

Comments
 (0)