Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AdRiley committed Jul 29, 2024
1 parent 89d9002 commit d5491c1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,10 @@ type Redshift_Dialect
Base_Generator.truncate_table_delete_from_style self table_name

## PRIVATE
Generates SQL for limiting the number of rows using the `LIMIT` clause.
get_limit_part_sql : Integer -> SQL_Builder
get_limit_part_sql self limit =
SQL_Builder.code (" LIMIT " + limit.to_text)

## PRIVATE
Generates SQL for limiting the number of rows using the `TOP` clause.
get_top_part_sql : Integer -> SQL_Builder
get_top_part_sql self limit =
_ = [limit]
SQL_Builder.code ""
Generates SQL modifier for limiting the number of rows and its position in the query
get_limit_sql_modifier : Integer -> Any
get_limit_sql_modifier self limit =
[700, SQL_Builder.code (" LIMIT " + limit.to_text)]

## PRIVATE
Wraps and possibly escapes the identifier so that it can be used in a
Expand Down
13 changes: 3 additions & 10 deletions distribution/lib/Standard/Database/0.0.0-dev/src/Dialect.enso
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,9 @@ type Dialect
Unimplemented.throw "This is an interface only."

## PRIVATE
Generates SQL for limiting the number of rows using the `LIMIT` clause.
get_limit_part_sql : Integer -> SQL_Builder
get_limit_part_sql self limit =
_ = [limit]
Unimplemented.throw "This is an interface only."

## PRIVATE
Generates SQL for limiting the number of rows using the `TOP` clause.
get_top_part_sql : Integer -> SQL_Builder
get_top_part_sql self limit =
Generates SQL modifier for limiting the number of rows and its position in the query
get_limit_sql_modifier : Integer -> Any
get_limit_sql_modifier self limit =
_ = [limit]
Unimplemented.throw "This is an interface only."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,6 @@ generate_order dialect order_descriptor =
- ctx: A description of the SELECT clause.
generate_select_query_sql : Dialect -> Vector (Pair Text SQL_Expression) -> Context -> SQL_Builder
generate_select_query_sql dialect columns ctx =
top_part = case ctx.limit of
Nothing -> SQL_Builder.code ""
_ : Integer -> dialect.get_top_part_sql ctx.limit

gen_exprs exprs = exprs.map (generate_expression dialect)
gen_column pair = (generate_expression dialect pair.second) ++ alias dialect pair.first

Expand All @@ -444,23 +440,20 @@ generate_select_query_sql dialect columns ctx =
orders = ctx.orders.map (generate_order dialect)
order_part = (SQL_Builder.join ", " orders) . prefix_if_present " ORDER BY "

limit_part = case ctx.limit of
Nothing -> ""
_ : Integer -> dialect.get_limit_part_sql ctx.limit

extensions = ctx.extensions.map extension->
part = extension.run_generator (gen_exprs extension.expressions)
[extension.position, part]

parts = Vector.build builder->
builder.append [100, SQL_Builder.code "SELECT "]
builder.append [150, top_part]
builder.append [100, SQL_Builder.code "SELECT "]
builder.append [200, generated_columns]
builder.append [300, SQL_Builder.code " FROM " ++ from_part]
builder.append [400, where_part]
builder.append [500, group_part]
builder.append [600, order_part]
builder.append [700, limit_part]
case ctx.limit of
Nothing -> _
_ : Integer -> builder.append (dialect.get_limit_sql_modifier ctx.limit)
extensions.each builder.append

SQL_Builder.join "" <| parts.sort on=(.first) . map .second
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,10 @@ type Postgres_Dialect
Base_Generator.truncate_table_truncate_table_style self table_name

## PRIVATE
Generates SQL for limiting the number of rows using the `LIMIT` clause.
get_limit_part_sql : Integer -> SQL_Builder
get_limit_part_sql self limit =
SQL_Builder.code (" LIMIT " + limit.to_text)

## PRIVATE
Generates SQL for limiting the number of rows using the `TOP` clause.
get_top_part_sql : Integer -> SQL_Builder
get_top_part_sql self limit =
_ = [limit]
SQL_Builder.code ""
Generates SQL modifier for limiting the number of rows and its position in the query
get_limit_sql_modifier : Integer -> Any
get_limit_sql_modifier self limit =
[700, SQL_Builder.code (" LIMIT " + limit.to_text)]

## PRIVATE
Wraps and possibly escapes the identifier so that it can be used in a
Expand Down Expand Up @@ -193,7 +186,7 @@ type Postgres_Dialect
Specifies whether the Database supports CREATE TEMPORARY TABLE syntax.
suppports_temporary_table_syntax : Boolean
suppports_temporary_table_syntax self = True

## PRIVATE
There is a bug in Postgres type inference, where if we unify two
fixed-length char columns of length N and M, the result type is said to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,10 @@ type SQLite_Dialect
Base_Generator.truncate_table_delete_from_style self table_name

## PRIVATE
Generates SQL for limiting the number of rows using the `LIMIT` clause.
get_limit_part_sql : Integer -> SQL_Builder
get_limit_part_sql self limit =
SQL_Builder.code (" LIMIT " + limit.to_text)

## PRIVATE
Generates SQL for limiting the number of rows using the `TOP` clause.
get_top_part_sql : Integer -> SQL_Builder
get_top_part_sql self limit =
_ = [limit]
SQL_Builder.code ""
Generates SQL modifier for limiting the number of rows and its position in the query
get_limit_sql_modifier : Integer -> Any
get_limit_sql_modifier self limit =
[700, SQL_Builder.code (" LIMIT " + limit.to_text)]

## PRIVATE
Wraps and possibly escapes the identifier so that it can be used in a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,10 @@ type SQLSever_Dialect
Base_Generator.truncate_table_truncate_table_style self table_name

## PRIVATE
Generates SQL for limiting the number of rows using the `LIMIT` clause.
get_limit_part_sql : Integer -> SQL_Builder
get_limit_part_sql self limit =
_ = [limit]
SQL_Builder.code ""

## PRIVATE
Generates SQL for limiting the number of rows using the `TOP` clause.
get_top_part_sql : Integer -> SQL_Builder
get_top_part_sql self limit =
SQL_Builder.code (" TOP " + limit.to_text)
Generates SQL modifier for limiting the number of rows and its position in the query
get_limit_sql_modifier : Integer -> Any
get_limit_sql_modifier self limit =
[150, SQL_Builder.code (" TOP " + limit.to_text)]

## PRIVATE
Wraps and possibly escapes the identifier so that it can be used in a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,10 @@ type Snowflake_Dialect
Base_Generator.truncate_table_truncate_table_style self table_name

## PRIVATE
Generates SQL for limiting the number of rows using the `LIMIT` clause.
get_limit_part_sql : Integer -> SQL_Builder
get_limit_part_sql self limit =
SQL_Builder.code (" LIMIT " + limit.to_text)

## PRIVATE
Generates SQL for limiting the number of rows using the `TOP` clause.
get_top_part_sql : Integer -> SQL_Builder
get_top_part_sql self limit =
_ = [limit]
SQL_Builder.code ""
Generates SQL modifier for limiting the number of rows and its position in the query
get_limit_sql_modifier : Integer -> Any
get_limit_sql_modifier self limit =
[700, SQL_Builder.code (" LIMIT " + limit.to_text)]

## PRIVATE
Wraps and possibly escapes the identifier so that it can be used in a
Expand Down

0 comments on commit d5491c1

Please sign in to comment.