Skip to content

Commit

Permalink
adds copy_to for lite, duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
drizk1 committed Mar 27, 2024
1 parent a594678 commit 6baedb6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/TidierDB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using DuckDB

export start_query_meta, set_sql_mode, @arrange, @group_by, @filter, @select, @mutate, @summarize, @summarise,
@distinct, @left_join, @right_join, @inner_join, @count, @window_order, @window_frame, @show_query, @collect, @slice_max,
@slice_min, @slice_sample
@slice_min, @slice_sample, copy_to

include("docstrings.jl")
include("structs.jl")
Expand Down Expand Up @@ -184,7 +184,9 @@ function start_query_meta(db, table::Symbol)
return SQLQuery(from=table_name, metadata=metadata, db=db)
end


"""
$docstring_copy_to
"""
function copy_to(conn, df::DataFrame, name::String)
if current_sql_mode[] == :duckdb
DuckDB.register_data_frame(conn, df, name)
Expand Down
28 changes: 27 additions & 1 deletion src/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,35 @@ SELECT id, groups, value, percent AS new_name
SELECT *
FROM cte_1
"""

const docstring_copy_to =
"""
copy_to(conn, df, "name")
Allows user to copy a df to the database connection. Currently supports DuckDB, SQLite
# Arguments
-`conn`: the database connection
-`df`: dataframe to be copied
-`name`: name as string for the database to be used
# Examples
```jldoctest
julia> df = DataFrame(id = [string('A' + i ÷ 26, 'A' + i % 26) for i in 0:9],
groups = [i % 2 == 0 ? "aa" : "bb" for i in 1:10],
value = repeat(1:5, 2),
percent = 0.1:0.1:1.0);
julia> db = DB();
julia> copy_to(db, df, "test")
"test"
```
"""



const docstring_window_order =
"""
@window_order(sql_query, columns...)
@window_order(sql_query, columns...)
Specify the order of rows for window functions within a SQL query.
Expand Down

0 comments on commit 6baedb6

Please sign in to comment.