remove duplicated export
parent
bad6390430
commit
4f72af430d
|
@ -5,7 +5,6 @@ export Action, Transaction,
|
||||||
write, restore, replay,
|
write, restore, replay,
|
||||||
DataBase, DataBaseTable, Table,
|
DataBase, DataBaseTable, Table,
|
||||||
ArrayTable, MappedTable
|
ArrayTable, MappedTable
|
||||||
export Table
|
|
||||||
|
|
||||||
using MsgPack
|
using MsgPack
|
||||||
|
|
||||||
|
|
|
@ -41,17 +41,17 @@ struct DataBase
|
||||||
size
|
size
|
||||||
end
|
end
|
||||||
|
|
||||||
DataBaseTable(table::Table, path) =
|
DataBaseTable(table::Table, path; verbose = false) =
|
||||||
DataBaseTable(table, Memory(table, path))
|
DataBaseTable(table, Memory(table, path, verbose = verbose))
|
||||||
|
|
||||||
const defaultSchema = Table("schema", MappedTable,
|
const defaultSchema = Table("schema", MappedTable,
|
||||||
# Key, Value (File), Value (Memory)
|
# Key, Value (File), Value (Memory)
|
||||||
[Symbol, Table], UInt32)
|
[Symbol, Table], UInt32)
|
||||||
|
|
||||||
function DataBase(dir; S = UInt32)
|
function DataBase(dir; S = UInt32, verbose = false)
|
||||||
dir = ispath(dir) ? realpath(dir) : mkpath(dir)
|
dir = ispath(dir) ? realpath(dir) : mkpath(dir)
|
||||||
isfile(dir) && throw(ArgumentError("path ($dir) is a file"))
|
isfile(dir) && throw(ArgumentError("path ($dir) is a file"))
|
||||||
tables = DataBaseTable(defaultSchema, dir)
|
tables = DataBaseTable(defaultSchema, dir, verbose = verbose)
|
||||||
tbldata = Dict{Table,DataBaseTable}()
|
tbldata = Dict{Table,DataBaseTable}()
|
||||||
for (idx,tbl) in tables.memory.data
|
for (idx,tbl) in tables.memory.data
|
||||||
tbldata[tbl] = DataBaseTable(tbl, dir)
|
tbldata[tbl] = DataBaseTable(tbl, dir)
|
||||||
|
@ -85,8 +85,8 @@ function Base.getindex(db::DataBase, name::Symbol)
|
||||||
db.memory[db.schema.memory.data[name]]
|
db.memory[db.schema.memory.data[name]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.setindex!(db::DataBase, table::Table, name::Symbol)
|
function Base.setindex!(db::DataBase, table::Table, name::Symbol; verbose = false)
|
||||||
dbtable = DataBaseTable(table, Memory(table, db.path))
|
dbtable = DataBaseTable(table, Memory(table, db.path, verbose = verbose))
|
||||||
# File
|
# File
|
||||||
action = haskey(db.schema.memory.data, name) ? modify : create
|
action = haskey(db.schema.memory.data, name) ? modify : create
|
||||||
write(db.schema.memory.io, Action(action, (name,table)), S = db.size)
|
write(db.schema.memory.io, Action(action, (name,table)), S = db.size)
|
||||||
|
@ -207,7 +207,7 @@ function replay(actions::Vector{Action{T}}) where T
|
||||||
state
|
state
|
||||||
end
|
end
|
||||||
|
|
||||||
function Memory(table::Table, path)::Memory
|
function Memory(table::Table, path; verbose = false)::Memory
|
||||||
vname(version) = joinpath(path, string(table.name, version, DBExt))
|
vname(version) = joinpath(path, string(table.name, version, DBExt))
|
||||||
rx = Regex("$(table.name)([0-9]+)$(DBExt)")
|
rx = Regex("$(table.name)([0-9]+)$(DBExt)")
|
||||||
files = filter!(!isnothing, map(x -> match(rx, x), readdir(path)))
|
files = filter!(!isnothing, map(x -> match(rx, x), readdir(path)))
|
||||||
|
@ -215,7 +215,7 @@ function Memory(table::Table, path)::Memory
|
||||||
exists = length(matches) > 0
|
exists = length(matches) > 0
|
||||||
version = exists ? maximum(matches) : 0
|
version = exists ? maximum(matches) : 0
|
||||||
fname = vname(version)
|
fname = vname(version)
|
||||||
@info(exists ? "Loading table from $(fname)" :
|
verbose && @info(exists ? "Loading table from $(fname)" :
|
||||||
"Creating new table in $(fname)")
|
"Creating new table in $(fname)")
|
||||||
if table.Type == ArrayTable
|
if table.Type == ArrayTable
|
||||||
data = if exists
|
data = if exists
|
||||||
|
|
Loading…
Reference in New Issue