Direct inserting a DataFrame into SQLite without using SQL?

I wonder if there is any package that allows a DataFrame to be:

  1. created as a SQLite table
  2. inserted into an existing SQLite table
    withOUT using SQL???

something like:

  1. create(df, "fname.sqlite")
    and
  2. insert(df, "fname.sqlite")
    would be perfect! (df is a DataFrame and “fname.sqlite” is the file name of the SQLite table)

Thanks!

Yes, this is possible:

using DataFrames, SQLite

df = DataFrame(a = 1:10, b = rand(10))
db = SQLite.DB(":memory:")

df |> SQLite.load!(db, "mytable")

# check entries
DataFrame(DBInterface.execute(db, "select * from mytable;"))

# another load
df |> SQLite.load!(db, "mytable")

# check again
DataFrame(DBInterface.execute(db, "select * from mytable;"))

Instead of ":memory:" you can specify your database file.

For more information you can take a look at the SQLite.load! documentation.
https://juliadatabases.org/SQLite.jl/stable/#SQLite.load!.

5 Likes