Skip to content

Commit

Permalink
support duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin authored and xitology committed Sep 7, 2024
1 parent 6de9a93 commit 16af87d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/dialects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ const postgresql_dialect =
limit_style = LIMIT_STYLE.POSTGRESQL,
variable_prefix = '$',
variable_style = VARIABLE_STYLE.NUMBERED)
const duckdb_dialect =
SQLDialect(name = :duckdb,
limit_style = LIMIT_STYLE.POSTGRESQL,
variable_prefix = '$',
variable_style = VARIABLE_STYLE.NUMBERED)
const redshift_dialect =
SQLDialect(name = :redshift,
concat_operator = Symbol("||"),
Expand Down Expand Up @@ -187,7 +192,8 @@ const standard_dialects = [
spark_dialect,
sqlite_dialect,
sqlserver_dialect,
default_dialect]
default_dialect,
duckdb_dialect]

function SQLDialect(name::Symbol; kws...)
for sd in standard_dialects
Expand All @@ -210,6 +216,7 @@ const known_connection_types = [
[:MySQL, :Connection] => :mysql,
[:LibPQ, :Connection] => :postgresql,
[:SQLite, :DB] => :sqlite,
[:DuckDB, :DB] => :duckdb,
]

function SQLDialect(@nospecialize ConnType::Type)
Expand Down
14 changes: 14 additions & 0 deletions src/reflect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ const postgresql_reflect_clause =
SELECT(:schema => (:n, :nspname),
:name => (:c, :relname),
:column => (:a, :attname))
# same as postgresql, just the default schema is "main" instead of "public":
const duckdb_reflect_clause =
FROM(:n => (:pg_catalog, :pg_namespace)) |>
JOIN(:c => (:pg_catalog, :pg_class), on = FUN("=", (:n, :oid), (:c, :relnamespace))) |>
JOIN(:a => (:pg_catalog, :pg_attribute), on = FUN("=", (:c, :oid), (:a, :attrelid))) |>
WHERE(FUN(:and, FUN("=", (:n, :nspname), FUN(:coalesce, VAR(:schema), "main")),
FUN(:in, (:c, :relkind), "r", "v"),
FUN(">", (:a, :attnum), 0),
FUN(:not, (:a, :attisdropped)))) |>
ORDER((:n, :nspname), (:c, :relname), (:a, :attnum)) |>
SELECT(:schema => (:n, :nspname),
:name => (:c, :relname),
:column => (:a, :attname))
const redshift_reflect_clause = postgresql_reflect_clause
const sqlite_reflect_clause =
FROM(:sm => :sqlite_master) |>
Expand All @@ -49,6 +62,7 @@ const sqlserver_reflect_clause =
const standard_reflect_clauses = [
:mysql => mysql_reflect_clause,
:postgresql => postgresql_reflect_clause,
:duckdb => duckdb_reflect_clause,
:redshift => redshift_reflect_clause,
:sqlite => sqlite_reflect_clause,
:sqlserver => sqlserver_reflect_clause]
Expand Down

0 comments on commit 16af87d

Please sign in to comment.