-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Database Visualization Support (#1582)
- Loading branch information
1 parent
2932819
commit b0e908e
Showing
35 changed files
with
392 additions
and
62 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
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,8 @@ | ||
from Standard.Base import all | ||
|
||
## PRIVATE | ||
recover_errors ~body = | ||
result = Panic.recover body | ||
result.catch err-> | ||
Json.from_pairs [["error", err.to_display_text]] . to_text | ||
|
39 changes: 39 additions & 0 deletions
39
distribution/std-lib/Standard/src/Visualization/Sql/Visualization.enso
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,39 @@ | ||
from Standard.Base import all | ||
|
||
import Standard.Visualization.Helpers | ||
|
||
## PRIVATE | ||
|
||
Prepares the query for visualization. | ||
|
||
For each interpolation it provides its value, its actual type name, its | ||
expected SQL type name and if it was possible to infer it, its expected Enso | ||
typename. | ||
|
||
Expected Enso types are inferred based on known SQL types and their mapping | ||
to Enso types. | ||
prepare_visualization x = Helpers.recover_errors <| | ||
prepared = x.to_sql.prepare | ||
code = prepared.first | ||
interpolations = prepared.second | ||
mapped = interpolations.map e-> | ||
value = e.first | ||
actual_type = Meta.get_qualified_type_name value | ||
expected_sql_type = e.second.name | ||
expected_enso_type = here.find_expected_enso_type_for_sql e.second | ||
Json.from_pairs [["value", value], ["actual_type", actual_type], ["expected_sql_type", expected_sql_type], ["expected_enso_type", expected_enso_type]] | ||
dialect = x.connection.dialect.name | ||
Json.from_pairs [["dialect", dialect], ["code", code], ["interpolations", mapped]] . to_text | ||
|
||
## PRIVATE | ||
|
||
Return an expected Enso type for an SQL type. | ||
|
||
Expected Enso types are only inferred for some known SQL types. For unknown | ||
types it will return `Nothing`. | ||
find_expected_enso_type_for_sql sql_type = | ||
if sql_type.is_definitely_integer then "Builtins.Main.Integer" else | ||
if sql_type.is_definitely_double then "Builtins.Main.Decimal" else | ||
if sql_type.is_definitely_text then "Builtins.Main.Text" else | ||
if sql_type.is_definitely_boolean then "Builtins.Main.Boolean" else | ||
Nothing |
Oops, something went wrong.