Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consolidate append=true behavior of MySQL.load #224

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ end
Attempts to take a Tables.jl source `table` and load into the database represented by `conn` with table name `name`.

It first detects the `Tables.Schema` of the table source and generates a `CREATE TABLE` statement
with the appropriate column names and types. If no table name is provided, one will be autogenerated, like `odbcjl_xxxxx`.
with the appropriate column names and types. If no table name is provided, one will be autogenerated, like `mysql_xxxxx`.
The `CREATE TABLE` clause can be provided manually by passing the `createtableclause` keyword argument, which
would allow specifying a temporary table or `if not exists`.

Column definitions can also be enhanced by providing arguments to `columnsuffix` as a `Dict` of
column name (given as a `Symbol`) to a string of the enhancement that will come after name and type like
`[column name] [column type] enhancements`. This allows, for example, specifying the charset of a string column
Expand Down Expand Up @@ -82,12 +83,13 @@ function load(itr, conn::Connection, name::AbstractString="mysql_"*Random.randst
if quoteidentifiers
name = quoteid(name)
end
try
createtable(conn, name, sch; quoteidentifiers=quoteidentifiers, debug=debug, kw...)
catch e
@warn "error creating table" (e, catch_backtrace())
end
# create table as we are not appending
if !append
try
createtable(conn, name, sch; quoteidentifiers=quoteidentifiers, debug=debug, kw...)
catch e
@warn "error creating table" (e, catch_backtrace())
end
DBInterface.execute(conn, "DELETE FROM $name")
end
# start a transaction for inserting rows
Expand Down