Closed mcgear closed 10 months ago
Thank you for the suggestion. Though, the idea is outside of the scope of this module. If you'd like to pursue having this functionality, I suggest opening an issue in the main runtime repository (https://github.com/denoland/deno).
@mcgear there is a function in the standard lib to ensure a directory exists... ensureDir
and if you need to determine the directory from the full path... dirname
import { ensureDir } from "https://deno.land/std@0.210.0/fs/ensure_dir.ts";
import { dirname } from "https://deno.land/std@0.210.0/path/dirname.ts";
const DB = './denoKv/deno.db';
await ensureDir(dirname(DB));
const denokv = await Deno.openKv(DB);
Great suggestion, @jollytoad!
My rust skills are garbage, otherwise i would just submit a pr... That said, the issue that I am seeing is that when opening a new Deno KV instance in a subdirectory, if the directory does not already exist, it fails to open:
I get the following error:
If the directory already exists for
./denoKv
then everything works fine.Would it be possible to update the code so that it creates any directories if they do not already exist? Before attempting to create the DB files.
The workaround is to create the
./denoKv
directory with a.gitkeep
file in it, but would be nice if it handles directory creation as well.