Skip to content

Commit

Permalink
improve doc
Browse files Browse the repository at this point in the history
  • Loading branch information
loicknuchel committed Feb 10, 2024
1 parent 3dca5b0 commit 04a41fd
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions frontend/src/DataSources/DbMiner/DbQuery.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Models.SqlQuery exposing (SqlQuery, SqlQueryOrigin)

exploreTable : DatabaseKind -> TableId -> SqlQueryOrigin
exploreTable db table =
-- query made from table details sidebar, something like: `SELECT * FROM table;`
{ sql =
case db of
DatabaseKind.Couchbase ->
Expand All @@ -43,14 +44,15 @@ exploreTable db table =
QuerySQLServer.exploreTable table

DatabaseKind.Other ->
"exploreTable not implemented for database " ++ DatabaseKind.toString db
"DbQuery.exploreTable not implemented for database " ++ DatabaseKind.toString db
, origin = "exploreTable"
, db = db
}


exploreColumn : DatabaseKind -> TableId -> ColumnPath -> SqlQueryOrigin
exploreColumn db table column =
-- query made from column details sidebar, something like: `SELECT col, count(*) FROM table GROUP BY col ORDER BY count(*) DESC, col;`
{ sql =
case db of
DatabaseKind.Couchbase ->
Expand All @@ -75,15 +77,15 @@ exploreColumn db table column =
QuerySQLServer.exploreColumn table column

DatabaseKind.Other ->
"exploreColumn not implemented for database " ++ DatabaseKind.toString db
"DbQuery.exploreColumn not implemented for database " ++ DatabaseKind.toString db
, origin = "exploreColumn"
, db = db
}


filterTable : DatabaseKind -> TableQuery -> SqlQueryOrigin
filterTable db query =
-- select many rows from a table with a filter
-- query made from the visual editor, something like: `SELECT * FROM table WHERE ${filters};`
{ sql =
case db of
DatabaseKind.MySQL ->
Expand All @@ -93,15 +95,15 @@ filterTable db query =
QueryPostgreSQL.filterTable query.table query.filters

_ ->
"filterTable not implemented for database " ++ DatabaseKind.toString db
"DbQuery.filterTable not implemented for database " ++ DatabaseKind.toString db
, origin = "filterTable"
, db = db
}


findRow : DatabaseKind -> RowQuery -> SqlQueryOrigin
findRow db query =
-- select a single row from a table by primary key
-- query made from the table rows or the row details sidebar, something like: `SELECT * FROM table WHERE ${primaryKey} = ${value} LIMIT 1;`
{ sql =
case db of
DatabaseKind.MySQL ->
Expand All @@ -111,7 +113,7 @@ findRow db query =
QueryPostgreSQL.findRow query.table query.primaryKey

_ ->
"findRow not implemented for database " ++ DatabaseKind.toString db
"DbQuery.findRow not implemented for database " ++ DatabaseKind.toString db
, origin = "findRow"
, db = db
}
Expand All @@ -124,7 +126,14 @@ incomingRowsLimit =

incomingRows : DatabaseKind -> Dict TableId IncomingRowsQuery -> RowQuery -> SqlQueryOrigin
incomingRows db relations row =
-- fetch rows from each relation pointing to a specific row
-- query made from table rows to get incoming rows from every incoming relation for the specific row, something like:
-- ```
-- SELECT
-- ${rels.map(rel =>
-- `array(SELECT json('id', r.id, 'alt', r.name) FROM ${rel.table} r WHERE r.fk=t.pk LIMIT 20) as ${rel.table}`
-- ).join(', ')}
-- FROM table t WHERE ${primaryKey} = ${value} LIMIT 1;
-- ```
{ sql =
case db of
DatabaseKind.MySQL ->
Expand All @@ -134,15 +143,16 @@ incomingRows db relations row =
QueryPostgreSQL.incomingRows row relations incomingRowsLimit

_ ->
"incomingRows not implemented for database " ++ DatabaseKind.toString db
"DbQuery.incomingRows not implemented for database " ++ DatabaseKind.toString db
, origin = "incomingRows"
, db = db
}


addLimit : DatabaseKind -> SqlQueryOrigin -> SqlQueryOrigin
addLimit db query =
-- limit query results to 100 if no limit specified
-- allow to limit query results (to 100) if not already specified
-- used before sending any query from Azimutt to the Gateway
case db of
DatabaseKind.MySQL ->
{ sql = QueryMySQL.addLimit query.sql, origin = query.origin, db = query.db }
Expand All @@ -159,6 +169,7 @@ addLimit db query =

updateColumnType : DatabaseKind -> ColumnRefLike x -> ColumnType -> SqlQueryOrigin
updateColumnType db ref kind =
-- generate SQL to update column types in the db analyzer in order to make them consistent (fk pointing at a pk)
{ sql =
case db of
DatabaseKind.MySQL ->
Expand All @@ -168,7 +179,7 @@ updateColumnType db ref kind =
QueryPostgreSQL.updateColumnType { table = ref.table, column = ref.column } kind

_ ->
"updateColumnType not implemented for database " ++ DatabaseKind.toString db
"DbQuery.updateColumnType not implemented for database " ++ DatabaseKind.toString db
, origin = "updateColumnType"
, db = db
}

0 comments on commit 04a41fd

Please sign in to comment.