Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Playground] show parameters for stored procedures/functions #1556

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface Routine {
name: string;
type: string;
definition: string;
parameters: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
<mat-expansion-panel-header>
<mat-panel-title> {{ routine.name }} </mat-panel-title>
</mat-expansion-panel-header>
<span> {{ routine.type }}</span>
<pre class="routine-definition">{{ routine.definition }}</pre>
<p class="header">
<b>Type: </b>
<span>{{ routine.type }}</span>
</p>
<br />

<span class="header"><b>Parameter:</b></span> <br />
<span
class="routine-definition"
*ngFor="let param of routine.parameters.split(', ')"
>
{{ param }} <br />
</span>
<br />

<p class="header"><b>Definition:</b></p>
<pre class="routine-definition overflow">{{ routine.definition }}</pre>
</mat-expansion-panel>
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ mat-expansion-panel {
.routine {
font-size: smaller;

span {
margin: 10px 15px 0;
.header {
margin: 0px 15px 0px;
font-size: smaller;
font-weight: bold;
}
.routine-definition {
margin: 0px 15px 10px;
font-size: smaller;
}
.overflow {
overflow-x: auto;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/fbs-core/web/src/i18n/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export const germanTranslation = {
"sql-playground.dbSchema": "DB Schema",
"sql-playground.tables": "Tabellen",
"sql-playground.views": "Views",
"sql-playground.storedProcedures": "Stored Procedures",
"sql-playground.storedProcedures": "Datenbankroutinen",
"sql-playground.triggers": "Triggers",
"sql-playground.db-control-panel.tab-db": "DB",
"sql-playground.db-control-panel.tab-templates": "Vorlagen",
Expand Down
2 changes: 1 addition & 1 deletion modules/fbs-core/web/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export const englishTranslation = {
"sql-playground.dbSchema": "DB Schema",
"sql-playground.tables": "Tables",
"sql-playground.views": "Views",
"sql-playground.storedProcedures": "Stored Procedures",
"sql-playground.storedProcedures": "Database routines",
"sql-playground.triggers": "Triggers",
"sql-playground.db-control-panel.tab-db": "DB",
"sql-playground.db-control-panel.tab-templates": "Templates",
Expand Down
6 changes: 6 additions & 0 deletions modules/fbs-core/web/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ app-db-scheme-table {
}
}

app-db-scheme-routines {
.mat-expansion-panel-body {
padding: 5px 0 10px 0 !important;
}
}


// Prism.js line numbers plugin
.line-numbers .line-numbers-rows {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,56 +119,68 @@
}

override def getDatabaseInformation(client: JDBCClient): Future[ResultSet] = {
val tables =
"""
|SELECT c.table_name as name,
|json_agg(json_build_object('name', column_name, 'isNullable', is_nullable::boolean, 'udtName', udt_name) ORDER BY ordinal_position) as json
|FROM information_schema.columns as c
|join information_schema.tables as t on c.table_name = t.table_name and c.table_schema = t.table_schema
|WHERE c.table_schema = 'public' and t.table_type != 'VIEW'
|group by c.table_name, t.table_type;
|""".stripMargin
val constrains =
"""
|select constrains.table_name as table,
|json_agg(json_build_object('columnName', constrains.column_name, 'name',
|constrains.constraint_name, 'type', constrains.constraint_type, 'checkClause', constrains.check_clause)) as json
|from (select tc.table_name, kcu.column_name, kcu.constraint_name, tc.constraint_type, null as check_clause
|from information_schema.KEY_COLUMN_USAGE as kcu
|JOIN information_schema.table_constraints as tc ON tc.constraint_name = kcu.constraint_name
|where tc.table_schema = 'public'
|UNION
|SELECT tc.table_name, SUBSTRING(cc.check_clause from '(?:^|(?:\.\s))(\w+)'), tc.constraint_name, tc.constraint_type, cc.check_clause
|FROM information_schema.table_constraints as tc
|JOIN information_schema.check_constraints as cc ON cc.constraint_name = tc.constraint_name
|AND constraint_type = 'CHECK'
|where tc.table_schema = 'public') as constrains group by constrains.table_name;
|""".stripMargin
val views =
"""
|SELECT table_name as table, view_definition as definition
|FROM information_schema.views
|WHERE table_schema = 'public';
|""".stripMargin

val routines =
"""
|SELECT routine_name as name, routine_type as type, routine_definition as definition
|FROM information_schema.routines
|WHERE routine_schema = 'public';
|""".stripMargin

val triggers =
"""
|SELECT trigger_name as name,
|event_object_table as objectTable,
|json_agg(event_manipulation) as json,
|action_statement as statement, action_orientation as orientation, action_timing as timing
|FROM information_schema.triggers
|WHERE trigger_schema = 'public' group by trigger_name, action_statement, action_orientation, action_timing, event_object_table;
|""".stripMargin

client.queryFuture(s"$tables $constrains $views $routines $triggers")
client.queryFuture(s"$getTablesDatabaseInformationQuery $getConstrainsDatabaseInformationQuery $getViewsDatabaseInformationQuery " +
s"$getRoutinesDatabaseInformationQuery $getTriggersDatabaseInformationQuery")

Check warning on line 123 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala#L122-L123

Added lines #L122 - L123 were not covered by tests
}

private def getTablesDatabaseInformationQuery = {
"""

Check warning on line 127 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala#L127

Added line #L127 was not covered by tests
|SELECT c.table_name as name,
|json_agg(json_build_object('name', column_name, 'isNullable', is_nullable::boolean, 'udtName', udt_name) ORDER BY ordinal_position) as json
|FROM information_schema.columns as c
|join information_schema.tables as t on c.table_name = t.table_name and c.table_schema = t.table_schema
|WHERE c.table_schema = 'public' and t.table_type != 'VIEW'
|group by c.table_name, t.table_type;
|""".stripMargin
}

private def getConstrainsDatabaseInformationQuery = {
"""

Check warning on line 138 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala#L138

Added line #L138 was not covered by tests
|select constrains.table_name as table,
|json_agg(json_build_object('columnName', constrains.column_name, 'name',
|constrains.constraint_name, 'type', constrains.constraint_type, 'checkClause', constrains.check_clause)) as json
|from (select tc.table_name, kcu.column_name, kcu.constraint_name, tc.constraint_type, null as check_clause
|from information_schema.KEY_COLUMN_USAGE as kcu
|JOIN information_schema.table_constraints as tc ON tc.constraint_name = kcu.constraint_name
|where tc.table_schema = 'public'
|UNION
|SELECT tc.table_name, SUBSTRING(cc.check_clause from '(?:^|(?:\.\s))(\w+)'), tc.constraint_name, tc.constraint_type, cc.check_clause
|FROM information_schema.table_constraints as tc
|JOIN information_schema.check_constraints as cc ON cc.constraint_name = tc.constraint_name
|AND constraint_type = 'CHECK'
|where tc.table_schema = 'public') as constrains group by constrains.table_name;
|""".stripMargin
}

private def getViewsDatabaseInformationQuery = {
"""

Check warning on line 156 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala#L156

Added line #L156 was not covered by tests
|SELECT table_name as table, view_definition as definition
|FROM information_schema.views
|WHERE table_schema = 'public';
|""".stripMargin
}

private def getRoutinesDatabaseInformationQuery = {
"""

Check warning on line 164 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala#L164

Added line #L164 was not covered by tests
|SELECT DISTINCT ON (oid)
|routine_name as name, routine_type as type,
|routine_definition as definition,
|pg_catalog.pg_get_function_identity_arguments(p.oid) AS parameters
|FROM information_schema.routines i
|JOIN pg_catalog.pg_proc p ON i.routine_name = p.proname
|WHERE routine_schema = 'public';
|""".stripMargin
}

private def getTriggersDatabaseInformationQuery = {
"""

Check warning on line 176 in modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala

View check run for this annotation

Codecov / codecov/patch

modules/fbs-runner/checker/src/main/scala/de/thm/ii/fbs/services/db/PsqlOperationsService.scala#L176

Added line #L176 was not covered by tests
|SELECT trigger_name as name,
|event_object_table as objectTable,
|json_agg(event_manipulation) as json,
|action_statement as statement, action_orientation as orientation, action_timing as timing
|FROM information_schema.triggers
|WHERE trigger_schema = 'public' group by trigger_name, action_statement, action_orientation, action_timing, event_object_table;
|""".stripMargin
}

override def queryFutureWithTimeout(client: JDBCClient, sql: String): Future[ResultSet] = {
Expand Down