From 0ed8bef3a4a29975499035a7c552354a90226c65 Mon Sep 17 00:00:00 2001 From: nixo Date: Fri, 23 Oct 2020 15:29:19 +0200 Subject: [PATCH] add do-block way to create/open a database, given a schema --- src/InMemoryLoggedDB.jl | 1 + src/db_init.jl | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/db_init.jl diff --git a/src/InMemoryLoggedDB.jl b/src/InMemoryLoggedDB.jl index e9e309d..9cce8a7 100644 --- a/src/InMemoryLoggedDB.jl +++ b/src/InMemoryLoggedDB.jl @@ -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)) diff --git a/src/db_init.jl b/src/db_init.jl new file mode 100644 index 0000000..1ddef0e --- /dev/null +++ b/src/db_init.jl @@ -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