@@ -120,13 +120,14 @@ function createtable!(db::DB, nm::AbstractString, ::Tables.Schema{names, types};
120120end
121121
122122"""
123- source |> SQLite.load!(db::SQLite.DB, tablename::String; temp::Bool=false, ifnotexists::Bool=false)
124- SQLite.load!(source, db, tablename; temp=false, ifnotexists=false)
123+ source |> SQLite.load!(db::SQLite.DB, tablename::String; temp::Bool=false, ifnotexists::Bool=false, analyze::Bool=false )
124+ SQLite.load!(source, db, tablename; temp=false, ifnotexists=false, analyze::Bool=false )
125125
126126Load a Tables.jl input `source` into an SQLite table that will be named `tablename` (will be auto-generated if not specified).
127127
128128`temp=true` will create a temporary SQLite table that will be destroyed automatically when the database is closed
129129`ifnotexists=false` will throw an error if `tablename` already exists in `db`
130+ `analyze=true` will execute `ANALYZE` at the end of the insert
130131"""
131132function load! end
132133
143144
144145checkdupnames (names) = length (unique (map (x-> lowercase (String (x)), names))) == length (names) || error (" duplicate case-insensitive column names detected; sqlite doesn't allow duplicate column names and treats them case insensitive" )
145146
146- function load! (sch:: Tables.Schema , rows, db:: DB , nm:: AbstractString , name, shouldcreate; temp:: Bool = false , ifnotexists:: Bool = false )
147+ function load! (sch:: Tables.Schema , rows, db:: DB , nm:: AbstractString , name, shouldcreate; temp:: Bool = false , ifnotexists:: Bool = false , analyze :: Bool = false )
147148 # check for case-insensitive duplicate column names (sqlite doesn't allow)
148149 checkdupnames (sch. names)
149150 # create table if needed
@@ -161,12 +162,12 @@ function load!(sch::Tables.Schema, rows, db::DB, nm::AbstractString, name, shoul
161162 sqlite3_reset (stmt. handle)
162163 end
163164 end
164- execute (db, " ANALYZE $nm " )
165+ analyze && execute (db, " ANALYZE $nm " )
165166 return name
166167end
167168
168169# unknown schema case
169- function load! (:: Nothing , rows, db:: DB , nm:: AbstractString , name, shouldcreate; temp:: Bool = false , ifnotexists:: Bool = false )
170+ function load! (:: Nothing , rows, db:: DB , nm:: AbstractString , name, shouldcreate; temp:: Bool = false , ifnotexists:: Bool = false , analyze :: Bool = false )
170171 state = iterate (rows)
171172 state === nothing && return nm
172173 row, st = state
@@ -191,6 +192,7 @@ function load!(::Nothing, rows, db::DB, nm::AbstractString, name, shouldcreate;
191192 row, st = state
192193 end
193194 end
194- execute (db, " ANALYZE $nm " )
195+ analyze && execute (db, " ANALYZE $nm " )
196+
195197 return name
196198end
0 commit comments