Skip to content

Instantly share code, notes, and snippets.

@mattn

mattn/dump.sql Secret

Last active April 29, 2023 11:08
Show Gist options
  • Save mattn/cd116cd17533888462fd0c6336575642 to your computer and use it in GitHub Desktop.
Save mattn/cd116cd17533888462fd0c6336575642 to your computer and use it in GitHub Desktop.
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE migration_state(
k integer not null primary key,
version integer not null
);
INSERT INTO migration_state VALUES(0,2);
CREATE TABLE data_version (
k integer primary key,
version integer not null
);
INSERT INTO data_version VALUES(0,1);
CREATE TABLE kv (
k blob primary key,
v blob not null,
v_encoding integer not null,
version integer not null
) without rowid;
INSERT INTO kv VALUES(X'02706174680002746f00026b657900',X'ff0f220c68656c6c6f2c20776f726c64',1,1);
CREATE TABLE queue (
ts integer not null,
id text not null,
data blob not null,
backoff_schedule text not null,
keys_if_undelivered blob not null,
primary key (ts, id)
);
CREATE TABLE queue_running(
deadline integer not null,
id text not null,
data blob not null,
backoff_schedule text not null,
keys_if_undelivered blob not null,
primary key (deadline, id)
);
COMMIT;
// ローカルとdeno deployの両方で動作する
const kv = await Deno.openKv("./tmp.sqlite");
// path/to/keyにデータを設定
await kv.set(["path", "to", "key"], "hello, world");
// path/to/keyのデータを取得
const res = await kv.get(["path", "to", "key"]);
// キーがpath/to始まりのデータを列挙する
for await (const data of kv.list({ prefix: ["path", "to"] })) {
console.log(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment