add do-block way to create/open a database, given a schema

master
nixo 2020-10-23 15:29:19 +02:00
parent 3ae8fd2d12
commit 0ed8bef3a4
2 changed files with 15 additions and 0 deletions

View File

@ -10,6 +10,7 @@ using MsgPack
include("actions.jl")
include("structure.jl")
include("db_init.jl")
function Base.push!(stream::IOStream, object::T) where T
write(stream, Action(create, object))

14
src/db_init.jl Normal file
View File

@ -0,0 +1,14 @@
"DataBase(path) do db:DataBase
end
Load a database, or create it from a schema"
function DataBase(f, path::String)
db = if isdir(path)
DataBase(path, verbose = true);
else
let db = DataBase(path, verbose = true);
f(db)
db
end
end
end