-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL studio component and backend implementation
Plus the ability to handle (almost) all MySQL types without triggering errors ...
- Loading branch information
Thomas Hansen
committed
Sep 1, 2019
1 parent
060cfe0
commit 7c7ff3b
Showing
16 changed files
with
293 additions
and
30 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
<div class="mat-elevation-z4 sql no-codemirror-auto-height"> | ||
|
||
<ngx-codemirror | ||
[(ngModel)]="sqlText" | ||
[options]="getCodeMirrorOptions()"></ngx-codemirror> | ||
|
||
</div> | ||
|
||
<div class="right-aligned"> | ||
<button | ||
mat-button | ||
matTooltip="Evaluates your Hyperlambda" | ||
(click)="evaluate()">Evaluate</button> | ||
</div> | ||
|
||
<div *ngIf="result !== null && result.length > 0" class="mat-elevation-z4 result"> | ||
<table class="fill-width"> | ||
<tr> | ||
<th *ngFor="let idx of result[0] | dynamic"> | ||
{{idx.key}} | ||
</th> | ||
</tr> | ||
<tr *ngFor="let row of result"> | ||
<td *ngFor="let idx of row | dynamic"> | ||
{{idx.value}} | ||
</td> | ||
</tr> | ||
</table> | ||
</div> |
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,27 @@ | ||
|
||
.sql { | ||
margin:5rem 4rem .5rem 4rem; | ||
} | ||
|
||
.right-aligned { | ||
margin:0 4rem .5rem 4rem; | ||
text-align: right; | ||
} | ||
|
||
.result { | ||
margin:.5rem 4rem .5rem 4rem; | ||
padding: 3rem; | ||
table.fill-width { | ||
width: 100%; | ||
tr { | ||
th { | ||
text-align: left; | ||
} | ||
} | ||
} | ||
} | ||
|
||
::ng-deep .error-snackbar { | ||
background:rgb(255,100,100); | ||
color:rgb(0,0,0); | ||
} |
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,56 @@ | ||
|
||
import { Component, OnInit } from '@angular/core'; | ||
import { PipeTransform, Pipe } from '@angular/core'; | ||
import { MatSnackBar } from '@angular/material'; | ||
import { SqlService } from 'src/app/services/sql-service'; | ||
|
||
@Component({ | ||
selector: 'app-sql', | ||
templateUrl: './sql.component.html', | ||
styleUrls: ['./sql.component.scss'] | ||
}) | ||
export class SqlComponent implements OnInit { | ||
private result: any = null; | ||
private sqlText: string = `/* | ||
* Type your SQL in here | ||
*/ | ||
use some_database; | ||
select * from some_table;`; | ||
|
||
constructor( | ||
private sqlService: SqlService, | ||
private snackBar: MatSnackBar) { } | ||
|
||
ngOnInit() { } | ||
|
||
getCodeMirrorOptions() { | ||
return { | ||
lineNumbers: true, | ||
theme: 'material', | ||
height: '250px', | ||
mode: 'text/x-mysql', | ||
}; | ||
} | ||
|
||
evaluate() { | ||
this.sqlService.evaluate(this.sqlText).subscribe((res) => { | ||
this.result = res; | ||
this.showHttpSuccess('SQL executed successfully'); | ||
}, (error) => { | ||
this.showHttpError(error); | ||
}); | ||
} | ||
|
||
showHttpError(error: any) { | ||
this.snackBar.open(error.error.message, 'Close', { | ||
duration: 10000, | ||
panelClass: ['error-snackbar'], | ||
}); | ||
} | ||
|
||
showHttpSuccess(msg: string) { | ||
this.snackBar.open(msg, 'Close', { | ||
duration: 2000, | ||
}); | ||
} | ||
} |
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,14 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
@Pipe({ | ||
name: 'dynamic' | ||
}) | ||
export class DynamicPipe implements PipeTransform { | ||
transform(value: any, args: string[]) : any { | ||
let keys = []; | ||
for (let key in value) { | ||
keys.push({key: key, value: value[key]}); | ||
} | ||
return keys; | ||
} | ||
} |
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,20 @@ | ||
|
||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { environment } from 'src/environments/environment'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class SqlService { | ||
|
||
constructor(private httpClient: HttpClient) { } | ||
|
||
public evaluate(sql: string) { | ||
return this.httpClient.post<any[]>( | ||
environment.apiURL + | ||
'hl/system/db/evaluate', { | ||
sql, | ||
}); | ||
} | ||
} |
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
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
Oops, something went wrong.