@@ -120,13 +120,14 @@ function createtable!(db::DB, nm::AbstractString, ::Tables.Schema{names, types};
120
120
end
121
121
122
122
"""
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 )
125
125
126
126
Load a Tables.jl input `source` into an SQLite table that will be named `tablename` (will be auto-generated if not specified).
127
127
128
128
`temp=true` will create a temporary SQLite table that will be destroyed automatically when the database is closed
129
129
`ifnotexists=false` will throw an error if `tablename` already exists in `db`
130
+ `analyze=true` will execute `ANALYZE` at the end of the insert
130
131
"""
131
132
function load! end
132
133
143
144
144
145
checkdupnames (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" )
145
146
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 )
147
148
# check for case-insensitive duplicate column names (sqlite doesn't allow)
148
149
checkdupnames (sch. names)
149
150
# create table if needed
@@ -161,12 +162,12 @@ function load!(sch::Tables.Schema, rows, db::DB, nm::AbstractString, name, shoul
161
162
sqlite3_reset (stmt. handle)
162
163
end
163
164
end
164
- execute (db, " ANALYZE $nm " )
165
+ analyze && execute (db, " ANALYZE $nm " )
165
166
return name
166
167
end
167
168
168
169
# 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 )
170
171
state = iterate (rows)
171
172
state === nothing && return nm
172
173
row, st = state
@@ -191,6 +192,7 @@ function load!(::Nothing, rows, db::DB, nm::AbstractString, name, shouldcreate;
191
192
row, st = state
192
193
end
193
194
end
194
- execute (db, " ANALYZE $nm " )
195
+ analyze && execute (db, " ANALYZE $nm " )
196
+
195
197
return name
196
198
end
0 commit comments